Skip to content

Commit 49b7941

Browse files
author
Oleksandr Iegorov
committed
Merge branch '2.3-develop' of github.com:magento/magento2ce into MAGETWO-71537-2
2 parents d376f1c + fb7c593 commit 49b7941

File tree

73 files changed

+1648
-399
lines changed

Some content is hidden

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

73 files changed

+1648
-399
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,33 +202,36 @@ public function getUrl($routePath = null, $routeParams = null)
202202
}
203203

204204
$cacheSecretKey = false;
205-
if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) {
205+
if (isset($routeParams['_cache_secret_key'])) {
206206
unset($routeParams['_cache_secret_key']);
207207
$cacheSecretKey = true;
208208
}
209209
$result = parent::getUrl($routePath, $routeParams);
210210
if (!$this->useSecretKey()) {
211211
return $result;
212212
}
213+
214+
$this->getRouteParamsResolver()->unsetData('route_params');
213215
$this->_setRoutePath($routePath);
216+
$extraParams = $this->getRouteParamsResolver()->getRouteParams();
214217
$routeName = $this->_getRouteName('*');
215218
$controllerName = $this->_getControllerName(self::DEFAULT_CONTROLLER_NAME);
216219
$actionName = $this->_getActionName(self::DEFAULT_ACTION_NAME);
217-
if ($cacheSecretKey) {
218-
$secret = [self::SECRET_KEY_PARAM_NAME => "\${$routeName}/{$controllerName}/{$actionName}\$"];
219-
} else {
220-
$secret = [
221-
self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($routeName, $controllerName, $actionName),
222-
];
223-
}
224-
if (is_array($routeParams)) {
225-
$routeParams = array_merge($secret, $routeParams);
226-
} else {
227-
$routeParams = $secret;
220+
221+
if (!isset($routeParams[self::SECRET_KEY_PARAM_NAME])) {
222+
if (!is_array($routeParams)) {
223+
$routeParams = [];
224+
}
225+
$secretKey = $cacheSecretKey
226+
? "\${$routeName}/{$controllerName}/{$actionName}\$"
227+
: $this->getSecretKey($routeName, $controllerName, $actionName);
228+
$routeParams[self::SECRET_KEY_PARAM_NAME] = $secretKey;
228229
}
229-
if (is_array($this->_getRouteParams())) {
230-
$routeParams = array_merge($this->_getRouteParams(), $routeParams);
230+
231+
if (!empty($extraParams)) {
232+
$routeParams = array_merge($extraParams, $routeParams);
231233
}
234+
232235
return parent::getUrl("{$routeName}/{$controllerName}/{$actionName}", $routeParams);
233236
}
234237

app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public function testGetCustomAttributes()
468468
);
469469

470470
//Change the attribute value, should reflect in getCustomAttribute
471-
$this->category->setData($customAttributeCode, $newCustomAttributeValue);
471+
$this->category->setCustomAttribute($customAttributeCode, $newCustomAttributeValue);
472472
$this->assertEquals(1, count($this->category->getCustomAttributes()));
473473
$this->assertNotNull($this->category->getCustomAttribute($customAttributeCode));
474474
$this->assertEquals(

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ public function testGetCustomAttributes()
13051305
);
13061306

13071307
//Change the attribute value, should reflect in getCustomAttribute
1308-
$this->model->setData($customAttributeCode, $newCustomAttributeValue);
1308+
$this->model->setCustomAttribute($customAttributeCode, $newCustomAttributeValue);
13091309
$this->assertEquals(1, count($this->model->getCustomAttributes()));
13101310
$this->assertNotNull($this->model->getCustomAttribute($customAttributeCode));
13111311
$this->assertEquals(

app/code/Magento/Catalog/view/frontend/templates/product/view/form.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $_product->getId() ?>" />
2323
<input type="hidden" name="selected_configurable_option" value="" />
2424
<input type="hidden" name="related_product" id="related-products-field" value="" />
25+
<input type="hidden" name="item" value="<?= /* @noEscape */ $block->getRequest()->getParam('id') ?>" />
2526
<?= $block->getBlockHtml('formkey') ?>
2627
<?= $block->getChildHtml('form_top') ?>
2728
<?php if (!$block->hasOptions()):?>

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ protected function _saveProducts()
17031703
$storeId = !empty($rowData[self::COL_STORE])
17041704
? $this->getStoreIdByCode($rowData[self::COL_STORE])
17051705
: Store::DEFAULT_STORE_ID;
1706-
if (isset($rowData['_media_is_disabled'])) {
1706+
if (isset($rowData['_media_is_disabled']) && strlen(trim($rowData['_media_is_disabled']))) {
17071707
$disabledImages = array_flip(
17081708
explode($this->getMultipleValueSeparator(), $rowData['_media_is_disabled'])
17091709
);

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
503503
if ($attrParams['is_static']) {
504504
continue;
505505
}
506-
if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
506+
if (isset($rowData[$attrCode]) && strlen(trim($rowData[$attrCode]))) {
507507
if (in_array($attrParams['type'], ['select', 'boolean'])) {
508508
$resultAttrs[$attrCode] = $attrParams['options'][strtolower($rowData[$attrCode])];
509509
} elseif ('multiselect' == $attrParams['type']) {

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public function getCacheKeyInfo()
167167
intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)),
168168
$this->getProductsPerPage(),
169169
$conditions,
170-
$this->json->serialize($this->getRequest()->getParams())
170+
$this->json->serialize($this->getRequest()->getParams()),
171+
$this->getTemplate(),
172+
$this->getTitle()
171173
];
172174
}
173175

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ protected function setUp()
8787
{
8888
$this->collectionFactory =
8989
$this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class)
90-
->setMethods(['create'])
91-
->disableOriginalConstructor()->getMock();
90+
->setMethods(['create'])
91+
->disableOriginalConstructor()->getMock();
9292
$this->visibility = $this->getMockBuilder(\Magento\Catalog\Model\Product\Visibility::class)
9393
->setMethods(['getVisibleInCatalogIds'])
9494
->disableOriginalConstructor()
@@ -144,6 +144,8 @@ public function testGetCacheKeyInfo()
144144
$this->productsList->setData('conditions', 'some_serialized_conditions');
145145

146146
$this->productsList->setData('page_var_name', 'page_number');
147+
$this->productsList->setTemplate('test_template');
148+
$this->productsList->setData('title', 'test_title');
147149
$this->request->expects($this->once())->method('getParam')->with('page_number')->willReturn(1);
148150

149151
$this->request->expects($this->once())->method('getParams')->willReturn('request_params');
@@ -166,7 +168,9 @@ public function testGetCacheKeyInfo()
166168
1,
167169
5,
168170
'some_serialized_conditions',
169-
json_encode('request_params')
171+
json_encode('request_params'),
172+
'test_template',
173+
'test_title'
170174
];
171175
$this->assertEquals($cacheKey, $this->productsList->getCacheKeyInfo());
172176
}
@@ -251,9 +255,10 @@ public function testGetPagerHtml()
251255
* Test public `createCollection` method and protected `getPageSize` method via `createCollection`
252256
*
253257
* @param bool $pagerEnable
254-
* @param int $productsCount
255-
* @param int $productsPerPage
256-
* @param int $expectedPageSize
258+
* @param int $productsCount
259+
* @param int $productsPerPage
260+
* @param int $expectedPageSize
261+
*
257262
* @dataProvider createCollectionDataProvider
258263
*/
259264
public function testCreateCollection($pagerEnable, $productsCount, $productsPerPage, $expectedPageSize)
@@ -382,6 +387,7 @@ public function testGetIdentities()
382387

383388
/**
384389
* @param $collection
390+
*
385391
* @return \PHPUnit_Framework_MockObject_MockObject
386392
*/
387393
private function getConditionsForCollection($collection)

app/code/Magento/Checkout/view/frontend/web/js/view/configure/product-customer-data.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ require([
77

88
var selectors = {
99
qtySelector: '#product_addtocart_form [name="qty"]',
10-
productIdSelector: '#product_addtocart_form [name="product"]'
10+
productIdSelector: '#product_addtocart_form [name="product"]',
11+
itemIdSelector: '#product_addtocart_form [name="item"]'
1112
},
1213
cartData = customerData.get('cart'),
1314
productId = $(selectors.productIdSelector).val(),
15+
itemId = $(selectors.itemIdSelector).val(),
1416
productQty,
1517
productQtyInput,
1618

@@ -40,8 +42,10 @@ require([
4042
return;
4143
}
4244
product = data.items.find(function (item) {
43-
return item['product_id'] === productId ||
44-
item['item_id'] === productId;
45+
if (item['item_id'] === itemId) {
46+
return item['product_id'] === productId ||
47+
item['item_id'] === productId;
48+
}
4549
});
4650

4751
if (!product) {

app/code/Magento/ConfigurableProduct/Model/Product/SaveHandler.php

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1111
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable as ResourceModelConfigurable;
1212
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
13+
use Magento\ConfigurableProduct\Api\Data\OptionInterface;
14+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute;
1315

1416
/**
1517
* Class SaveHandler
@@ -76,35 +78,66 @@ public function execute($entity, $arguments = [])
7678
}
7779

7880
/**
79-
* Save attributes for configurable product
81+
* Save only newly created attributes for configurable product.
8082
*
8183
* @param ProductInterface $product
8284
* @param array $attributes
8385
* @return array
8486
*/
85-
private function saveConfigurableProductAttributes(ProductInterface $product, array $attributes)
87+
private function saveConfigurableProductAttributes(ProductInterface $product, array $attributes): array
8688
{
8789
$ids = [];
90+
$existingAttributeIds = [];
91+
foreach ($this->optionRepository->getList($product->getSku()) as $option) {
92+
$existingAttributeIds[$option->getAttributeId()] = $option;
93+
}
8894
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $attribute */
8995
foreach ($attributes as $attribute) {
90-
$attribute->setId(null);
91-
$ids[] = $this->optionRepository->save($product->getSku(), $attribute);
96+
if (!in_array($attribute->getAttributeId(), array_keys($existingAttributeIds))
97+
|| $this->isOptionChanged($existingAttributeIds[$attribute->getAttributeId()], $attribute)
98+
) {
99+
$attribute->setId(null);
100+
$ids[] = $this->optionRepository->save($product->getSku(), $attribute);
101+
}
92102
}
93103

94104
return $ids;
95105
}
96106

97107
/**
98-
* Remove product attributes
108+
* Remove product attributes which no longer used.
99109
*
100110
* @param ProductInterface $product
101111
* @return void
102112
*/
103-
private function deleteConfigurableProductAttributes(ProductInterface $product)
113+
private function deleteConfigurableProductAttributes(ProductInterface $product): void
114+
{
115+
$newAttributeIds = [];
116+
foreach ($product->getExtensionAttributes()->getConfigurableProductOptions() as $option) {
117+
$newAttributeIds[$option->getAttributeId()] = $option;
118+
}
119+
foreach ($this->optionRepository->getList($product->getSku()) as $option) {
120+
if (!in_array($option->getAttributeId(), array_keys($newAttributeIds))
121+
|| $this->isOptionChanged($option, $newAttributeIds[$option->getAttributeId()])
122+
) {
123+
$this->optionRepository->deleteById($product->getSku(), $option->getId());
124+
}
125+
}
126+
}
127+
128+
/**
129+
* Check if existing option is changed.
130+
*
131+
* @param OptionInterface $option
132+
* @param Attribute $attribute
133+
* @return bool
134+
*/
135+
private function isOptionChanged(OptionInterface $option, Attribute $attribute): bool
104136
{
105-
$list = $this->optionRepository->getList($product->getSku());
106-
foreach ($list as $item) {
107-
$this->optionRepository->deleteById($product->getSku(), $item->getId());
137+
if ($option->getLabel() == $attribute->getLabel() && $option->getPosition() == $attribute->getPosition()) {
138+
return false;
108139
}
140+
141+
return true;
109142
}
110143
}

0 commit comments

Comments
 (0)