Skip to content

Commit b542481

Browse files
author
Olga Kopylova
committed
Merge remote-tracking branch 'mainline/develop' into PR_Branch
2 parents 42feff7 + 31a7fe0 commit b542481

File tree

211 files changed

+3058
-1183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+3058
-1183
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Console\Command;
7+
8+
use Magento\Framework\DB\Adapter\AdapterInterface;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class ProductAttributesCleanUp extends \Symfony\Component\Console\Command\Command
13+
{
14+
/**
15+
* @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface
16+
*/
17+
protected $productAttributeRepository;
18+
19+
/**
20+
* @var \Magento\Framework\Api\SearchCriteriaBuilder
21+
*/
22+
protected $searchCriteriaBuilder;
23+
24+
/**
25+
* @var \Magento\Catalog\Model\ResourceModel\Attribute
26+
*/
27+
protected $attributeResource;
28+
29+
/**
30+
* @var \Magento\Framework\App\State
31+
*/
32+
protected $appState;
33+
34+
/**
35+
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository
36+
* @param \Magento\Catalog\Model\ResourceModel\Attribute $attributeResource
37+
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
38+
* @param \Magento\Framework\App\State $appState
39+
*/
40+
public function __construct(
41+
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository,
42+
\Magento\Catalog\Model\ResourceModel\Attribute $attributeResource,
43+
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
44+
\Magento\Framework\App\State $appState
45+
) {
46+
$this->productAttributeRepository = $productAttributeRepository;
47+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
48+
$this->attributeResource = $attributeResource;
49+
$this->appState = $appState;
50+
parent::__construct();
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
protected function configure()
57+
{
58+
$this->setName('catalog:product:attributes:cleanup');
59+
$this->setDescription('Removes unused product attributes.');
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
protected function execute(InputInterface $input, OutputInterface $output)
66+
{
67+
$output->setDecorated(true);
68+
$this->appState->setAreaCode('catalog');
69+
$connection = $this->attributeResource->getConnection();
70+
$attributeTables = $this->getAttributeTables();
71+
72+
$progress = new \Symfony\Component\Console\Helper\ProgressBar($output, count($attributeTables));
73+
$progress->setFormat('<comment>%message%</comment> %current%/%max% [%bar%] %percent:3s%% %elapsed%');
74+
75+
$this->attributeResource->beginTransaction();
76+
try {
77+
// Find and remove unused attributes
78+
foreach ($attributeTables as $attributeTable) {
79+
$progress->setMessage($attributeTable . ' ');
80+
$affectedIds = $this->getAffectedAttributeIds($connection, $attributeTable);
81+
if (count($affectedIds) > 0) {
82+
$connection->delete($attributeTable, ['value_id in (?)' => $affectedIds]);
83+
}
84+
$progress->advance();
85+
}
86+
$this->attributeResource->commit();
87+
88+
$output->writeln("");
89+
$output->writeln("<info>Unused product attributes successfully cleaned up:</info>");
90+
$output->writeln("<comment> " . implode("\n ", $attributeTables) . "</comment>");
91+
} catch (\Exception $exception) {
92+
$this->attributeResource->rollBack();
93+
94+
$output->writeln("");
95+
$output->writeln("<error>{$exception->getMessage()}</error>");
96+
}
97+
}
98+
99+
/**
100+
* @return array
101+
* @throws \Magento\Framework\Exception\LocalizedException
102+
*/
103+
private function getAttributeTables()
104+
{
105+
$searchResult = $this->productAttributeRepository->getList($this->searchCriteriaBuilder->create());
106+
$attributeTables = [];
107+
108+
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $productAttribute */
109+
foreach ($searchResult->getItems() as $productAttribute) {
110+
$attributeTable = $productAttribute->getBackend()->getTable();
111+
if (!in_array($attributeTable, $attributeTables)
112+
&& $attributeTable != $this->attributeResource->getTable('catalog_product_entity')
113+
) {
114+
$attributeTables[] = $attributeTable;
115+
}
116+
}
117+
return $attributeTables;
118+
}
119+
120+
/**
121+
* @param AdapterInterface $connection
122+
* @param string $attributeTableName
123+
* @return array
124+
* @throws \Zend_Db_Statement_Exception
125+
*/
126+
private function getAffectedAttributeIds(AdapterInterface $connection, $attributeTableName)
127+
{
128+
$select = $connection->select()->reset();
129+
$select->from(['e' => $this->attributeResource->getTable('catalog_product_entity')], 'ei.value_id');
130+
$select->join(['ei' => $attributeTableName], 'ei.entity_id = e.entity_id AND ei.store_id != 0', '');
131+
$select->join(['s' => $this->attributeResource->getTable('store')], 's.store_id = ei.store_id', '');
132+
$select->join(['sg' => $this->attributeResource->getTable('store_group')], 'sg.group_id = s.group_id', '');
133+
$select->joinLeft(
134+
['pw' => $this->attributeResource->getTable('catalog_product_website')],
135+
'pw.website_id = sg.website_id AND pw.product_id = e.entity_id',
136+
''
137+
);
138+
$select->where('pw.product_id is null');
139+
return $connection->fetchCol($select);
140+
}
141+
}

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,12 @@ protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $p
574574
{
575575
$transport = new \StdClass();
576576
$transport->options = [];
577+
$options = null;
577578
if ($product->getHasOptions()) {
578-
foreach ($product->getOptions() as $option) {
579+
$options = $product->getOptions();
580+
}
581+
if ($options !== null) {
582+
foreach ($options as $option) {
579583
/* @var $option \Magento\Catalog\Model\Product\Option */
580584
$group = $option->groupFactory($option->getType())
581585
->setOption($option)

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@
493493
<arguments>
494494
<argument name="commands" xsi:type="array">
495495
<item name="imagesResizeCommand" xsi:type="object">Magento\Catalog\Console\Command\ImagesResizeCommand</item>
496+
<item name="productAttributesCleanUp" xsi:type="object">Magento\Catalog\Console\Command\ProductAttributesCleanUp</item>
496497
</argument>
497498
</arguments>
498499
</type>

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
107107
$query
108108
);
109109
} elseif ($filter->getField() === 'category_ids') {
110-
return 'category_ids_index.category_id = ' . $filter->getValue();
110+
return 'category_ids_index.category_id = ' . (int) $filter->getValue();
111111
} elseif ($attribute->isStatic()) {
112112
$alias = $this->tableMapper->getMappingAlias($filter);
113113
$resultQuery = str_replace(
@@ -194,10 +194,10 @@ private function processTermSelect(FilterInterface $filter, $isNegation)
194194
$value = sprintf(
195195
'%s IN (%s)',
196196
($isNegation ? 'NOT' : ''),
197-
implode(',', $filter->getValue())
197+
implode(',', array_map([$this->connection, 'quote'], $filter->getValue()))
198198
);
199199
} else {
200-
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
200+
$value = ($isNegation ? '!' : '') . '= ' . $this->connection->quote($filter->getValue());
201201
}
202202
$resultQuery = sprintf(
203203
'%1$s.value %2$s',

app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function setUp()
104104
->getMock();
105105
$this->connection = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface')
106106
->disableOriginalConstructor()
107-
->setMethods(['select', 'getIfNullSql'])
107+
->setMethods(['select', 'getIfNullSql', 'quote'])
108108
->getMockForAbstractClass();
109109
$this->select = $this->getMockBuilder('\Magento\Framework\DB\Select')
110110
->disableOriginalConstructor()
@@ -170,9 +170,25 @@ public function testProcessPrice()
170170
$this->assertSame($expectedResult, $this->removeWhitespaces($actualResult));
171171
}
172172

173-
public function testProcessCategoryIds()
173+
/**
174+
* @return array
175+
*/
176+
public function processCategoryIdsDataProvider()
177+
{
178+
return [
179+
['5', 'category_ids_index.category_id = 5'],
180+
[3, 'category_ids_index.category_id = 3'],
181+
["' and 1 = 0", 'category_ids_index.category_id = 0'],
182+
];
183+
}
184+
185+
/**
186+
* @param string|int $categoryId
187+
* @param string $expectedResult
188+
* @dataProvider processCategoryIdsDataProvider
189+
*/
190+
public function testProcessCategoryIds($categoryId, $expectedResult)
174191
{
175-
$expectedResult = 'category_ids_index.category_id = FilterValue';
176192
$isNegation = false;
177193
$query = 'SELECT category_ids FROM catalog_product_entity';
178194

@@ -182,7 +198,7 @@ public function testProcessCategoryIds()
182198

183199
$this->filter->expects($this->once())
184200
->method('getValue')
185-
->will($this->returnValue('FilterValue'));
201+
->will($this->returnValue($categoryId));
186202

187203
$this->config->expects($this->exactly(1))
188204
->method('getAttribute')
@@ -249,6 +265,7 @@ public function testProcessTermFilter($frontendInput, $fieldValue, $isNegation,
249265
->method('getValue')
250266
->willReturn($fieldValue);
251267

268+
$this->connection->expects($this->atLeastOnce())->method('quote')->willReturnArgument(0);
252269
$actualResult = $this->target->process($this->filter, $isNegation, 'This filter is not depends on used query');
253270
$this->assertSame($expected, $this->removeWhitespaces($actualResult));
254271
}

app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function processPaymentConfiguration(array &$configuration, array $eleme
147147
'customEntry' => 'billingAddress' . $paymentCode . '.region',
148148
],
149149
'validation' => [
150-
'validate-select' => true,
150+
'required-entry' => true,
151151
],
152152
'filterBy' => [
153153
'target' => '${ $.provider }:${ $.parentScope }.country_id',

app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
<item name="customEntry" xsi:type="string">shippingAddress.region</item>
198198
</item>
199199
<item name="validation" xsi:type="array">
200-
<item name="validate-select" xsi:type="string">true</item>
200+
<item name="required-entry" xsi:type="boolean">true</item>
201201
</item>
202202
<!-- Value of region_id field is filtered by the value of county_id attribute -->
203203
<item name="filterBy" xsi:type="array">

app/code/Magento/Checkout/view/frontend/web/js/view/payment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ define(
5353
stepNavigator.registerStep(
5454
'payment',
5555
null,
56-
'Review & Payments',
56+
$t('Review & Payments'),
5757
this.isVisible,
5858
_.bind(this.navigate, this),
5959
20

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ define(
8383
stepNavigator.registerStep(
8484
'shipping',
8585
'',
86-
'Shipping',
86+
$t('Shipping'),
8787
this.visible, _.bind(this.navigate, this),
8888
10
8989
);

app/code/Magento/Checkout/view/frontend/web/template/cart/totals/grand-total.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-->
77
<tr class="grand totals">
88
<th class="mark" colspan="1" scope="row">
9-
<strong data-bind="text: title"></strong>
9+
<strong data-bind="i18n: title"></strong>
1010
</th>
1111
<td class="amount" data-th="Order Total">
1212
<strong><span class="price" data-bind="text: getValue()"></span></strong>

app/code/Magento/Checkout/view/frontend/web/template/cart/totals/subtotal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<tr class="totals sub">
8-
<th class="mark" colspan="1" scope="row" data-bind="text: title"></th>
8+
<th class="mark" colspan="1" scope="row" data-bind="i18n: title"></th>
99
<td class="amount" data-th="Subtotal">
1010
<span class="price" data-bind="text: getValue()"></span>
1111
</td>

app/code/Magento/Checkout/view/frontend/web/template/payment.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<li id="payment" role="presentation" class="checkout-payment-method" data-bind="fadeVisible: isVisible">
8-
<div class="step-title" data-bind="text: title" data-role="title"></div>
8+
<div class="step-title" data-bind="i18n: title" data-role="title"></div>
99
<div id="checkout-step-payment"
1010
class="step-content"
1111
data-role="content"

app/code/Magento/Checkout/view/frontend/web/template/summary/shipping.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- ko if: quoteIsVirtual == 0 -->
88
<tr class="totals shipping excl">
99
<th class="mark" scope="row">
10-
<span class="label" data-bind="text: title"></span>
10+
<span class="label" data-bind="i18n: title"></span>
1111
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
1212
</th>
1313
<td class="amount">

app/code/Magento/Config/Model/Config/Structure/Element/Group/Proxy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\Config\Model\Config\Structure\Element\Group;
77

8-
class Proxy extends \Magento\Config\Model\Config\Structure\Element\Group
8+
class Proxy extends \Magento\Config\Model\Config\Structure\Element\Group implements
9+
\Magento\Framework\ObjectManager\NoninterceptableInterface
910
{
1011
/**
1112
* Object manager

app/code/Magento/Config/Model/Config/Structure/Search/Proxy.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
namespace Magento\Config\Model\Config\Structure\Search;
77

8-
class Proxy implements \Magento\Config\Model\Config\Structure\SearchInterface
8+
class Proxy implements
9+
\Magento\Config\Model\Config\Structure\SearchInterface,
10+
\Magento\Framework\ObjectManager\NoninterceptableInterface
911
{
1012
/**
1113
* Object manager

app/code/Magento/Deploy/Model/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected function compile(
161161
DirectoryList::DI,
162162
]
163163
);
164-
$cmd = $this->functionCallPath . 'setup:di:compile-multi-tenant';
164+
$cmd = $this->functionCallPath . 'setup:di:compile';
165165

166166
/**
167167
* exec command is necessary for now to isolate the autoloaders in the compiler from the memory state

app/code/Magento/GiftMessage/Model/GiftMessageConfigProvider.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public function getConfig()
105105
$configuration['isOrderLevelGiftOptionsEnabled'] = (bool)$this->isQuoteVirtual() ? false : true;
106106
$configuration['giftMessage']['orderLevel'] = $orderMessages === null ? true : $orderMessages->getData();
107107
}
108-
if ($itemLevelGiftMessageConfiguration) {
109-
$itemMessages = $this->getItemLevelGiftMessages();
110-
$configuration['isItemLevelGiftOptionsEnabled'] = true;
111-
$configuration['giftMessage']['itemLevel'] = $itemMessages === null ? true : $itemMessages;
112-
}
108+
109+
$itemMessages = $this->getItemLevelGiftMessages();
110+
$configuration['isItemLevelGiftOptionsEnabled'] = $itemLevelGiftMessageConfiguration;
111+
$configuration['giftMessage']['itemLevel'] = $itemMessages === null ? true : $itemMessages;
112+
113113
$configuration['priceFormat'] = $this->localeFormat->getPriceFormat(
114114
null,
115115
$this->checkoutSession->getQuote()->getQuoteCurrencyCode()
@@ -166,22 +166,27 @@ protected function getOrderLevelGiftMessages()
166166
}
167167

168168
/**
169-
* Load already specified item level gift messages.
169+
* Load already specified item level gift messages and related configuration.
170170
*
171171
* @return \Magento\GiftMessage\Api\Data\MessageInterface[]|null
172172
*/
173173
protected function getItemLevelGiftMessages()
174174
{
175-
$itemMessages = [];
176-
$cartId = $this->checkoutSession->getQuoteId();
177-
$items = $this->checkoutSession->getQuote()->getAllVisibleItems();
178-
foreach ($items as $item) {
175+
$itemLevelConfig = [];
176+
$quote = $this->checkoutSession->getQuote();
177+
foreach ($quote->getAllVisibleItems() as $item) {
179178
$itemId = $item->getId();
180-
$message = $this->itemRepository->get($cartId, $itemId);
179+
$itemLevelConfig[$itemId] = [];
180+
$isMessageAvailable = $item->getProduct()->getGiftMessageAvailable();
181+
// use gift message product setting if it is available
182+
if ($isMessageAvailable !== null) {
183+
$itemLevelConfig[$itemId]['is_available'] = (bool)$isMessageAvailable;
184+
}
185+
$message = $this->itemRepository->get($quote->getId(), $itemId);
181186
if ($message) {
182-
$itemMessages[$itemId] = $message->getData();
187+
$itemLevelConfig[$itemId]['message'] = $message->getData();
183188
}
184189
}
185-
return count($itemMessages) === 0 ? null : $itemMessages;
190+
return count($itemLevelConfig) === 0 ? null : $itemLevelConfig;
186191
}
187192
}

0 commit comments

Comments
 (0)