Skip to content

Commit 8088a14

Browse files
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #14252: [Forwardport] Add integration tests for product urls rewrite generation (by @rostyslav-hymon) - #14250: [Forwardport] Fix JS address converter function from mutating its argument (by @mastiuhin-olexandr) - #13220: Solve problem saving empty swatches in admin (by @enriquei4) Fixed GitHub Issues: - #5863: URL Rewrite issues occur very often /catalog/product/view/id/711/s/product-name/category/16/ (reported by @kayintveen) has been fixed in #14252 by @rostyslav-hymon in 2.3-develop branch Related commits: 1. 03e0a0b 2. 1322d8b - #8227: After upgrade to 2.1.3 url rewrite problem multi store (reported by @philipvandebriel) has been fixed in #14252 by @rostyslav-hymon in 2.3-develop branch Related commits: 1. 03e0a0b 2. 1322d8b - #8957: Permanent Redirect for old URL missing via API (reported by @MarcoGrecoBitbull) has been fixed in #14252 by @rostyslav-hymon in 2.3-develop branch Related commits: 1. 03e0a0b 2. 1322d8b - #10073: Magento don't create product redirect if URL key on store view level was changed. (reported by @sergei-sss) has been fixed in #14252 by @rostyslav-hymon in 2.3-develop branch Related commits: 1. 03e0a0b 2. 1322d8b - #13240: Permanent 301 redirect is not generated when product url changes on storeview scope (reported by @koenner01) has been fixed in #14252 by @rostyslav-hymon in 2.3-develop branch Related commits: 1. 03e0a0b 2. 1322d8b - #13216: `quoteAddressToFormAddressData` mutates the argument (reported by @vaaralav) has been fixed in #14250 by @mastiuhin-olexandr in 2.3-develop branch Related commits: 1. c71e7ac - #13117: Swatch Attribute is not getting save while deleting a swatch row with empty admin scope text (reported by @mak0605) has been fixed in #13220 by @enriquei4 in 2.3-develop branch Related commits: 1. 15477af 2. 2eeb633 3. 3bab714 4. ae01fba 5. a9abfa8 6. 980522a 7. d42b6be
2 parents c21680f + dce6a04 commit 8088a14

File tree

6 files changed

+336
-8
lines changed

6 files changed

+336
-8
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public function execute()
113113
$options
114114
);
115115
$valueOptions = (isset($options['value']) && is_array($options['value'])) ? $options['value'] : [];
116+
foreach (array_keys($valueOptions) as $key) {
117+
if (!empty($options['delete'][$key])) {
118+
unset($valueOptions[$key]);
119+
}
120+
}
116121
$this->checkEmptyOption($response, $valueOptions);
117122
}
118123

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ public function provideUniqueData()
249249
]
250250
], false
251251
],
252+
'empty and deleted' => [
253+
[
254+
'value' => [
255+
"option_0" => [1, 0],
256+
"option_1" => [2, 0],
257+
"option_2" => ["", ""],
258+
],
259+
'delete' => [
260+
"option_0" => "",
261+
"option_1" => "",
262+
"option_2" => "1",
263+
]
264+
], false
265+
],
252266
];
253267
}
254268

@@ -321,7 +335,34 @@ public function provideEmptyOption()
321335
(object) [
322336
'error' => false,
323337
]
324-
]
338+
],
339+
'empty admin scope options and deleted' => [
340+
[
341+
'value' => [
342+
"option_0" => [''],
343+
],
344+
'delete' => [
345+
'option_0' => '1',
346+
],
347+
],
348+
(object) [
349+
'error' => false,
350+
],
351+
],
352+
'empty admin scope options and not deleted' => [
353+
[
354+
'value' => [
355+
"option_0" => [''],
356+
],
357+
'delete' => [
358+
'option_0' => '0',
359+
],
360+
],
361+
(object) [
362+
'error' => true,
363+
'message' => 'The value of Admin scope can\'t be empty.',
364+
],
365+
],
325366
];
326367
}
327368
}

app/code/Magento/Checkout/view/frontend/web/js/model/address-converter.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ define([
7272
output = {},
7373
streetObject;
7474

75+
$.each(addrs, function (key) {
76+
if (addrs.hasOwnProperty(key) && !$.isFunction(addrs[key])) {
77+
output[self.toUnderscore(key)] = addrs[key];
78+
}
79+
});
80+
7581
if ($.isArray(addrs.street)) {
7682
streetObject = {};
7783
addrs.street.forEach(function (value, index) {
7884
streetObject[index] = value;
7985
});
80-
addrs.street = streetObject;
86+
output.street = streetObject;
8187
}
8288

83-
$.each(addrs, function (key) {
84-
if (addrs.hasOwnProperty(key) && !$.isFunction(addrs[key])) {
85-
output[self.toUnderscore(key)] = addrs[key];
86-
}
87-
});
88-
8989
return output;
9090
},
9191

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogUrlRewrite\Observer;
7+
8+
use Magento\Store\Model\StoreManagerInterface;
9+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
10+
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
11+
12+
/**
13+
* @magentoAppArea adminhtml
14+
*/
15+
class ProductProcessUrlRewriteSavingObserverTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/** @var \Magento\Framework\ObjectManagerInterface */
18+
protected $objectManager;
19+
20+
protected function setUp()
21+
{
22+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
23+
}
24+
25+
/**
26+
* @param array $filter
27+
* @return array
28+
*/
29+
private function getActualResults(array $filter)
30+
{
31+
/** @var \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder */
32+
$urlFinder = $this->objectManager->get(\Magento\UrlRewrite\Model\UrlFinderInterface::class);
33+
$actualResults = [];
34+
foreach ($urlFinder->findAllByData($filter) as $url) {
35+
$actualResults[] = [
36+
'request_path' => $url->getRequestPath(),
37+
'target_path' => $url->getTargetPath(),
38+
'is_auto_generated' => (int)$url->getIsAutogenerated(),
39+
'redirect_type' => $url->getRedirectType(),
40+
'store_id' => $url->getStoreId()
41+
];
42+
}
43+
return $actualResults;
44+
}
45+
46+
/**
47+
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_rewrite_multistore.php
48+
* @magentoAppIsolation enabled
49+
*/
50+
public function testUrlKeyHasChangedInGlobalContext()
51+
{
52+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository*/
53+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
54+
/** @var \Magento\Catalog\Model\Product $product*/
55+
$product = $productRepository->get('product1');
56+
57+
/** @var StoreManagerInterface $storeManager */
58+
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
59+
$storeManager->setCurrentStore(0);
60+
61+
$testStore = $storeManager->getStore('test');
62+
$productFilter = [
63+
UrlRewrite::ENTITY_TYPE => 'product',
64+
];
65+
66+
$expected = [
67+
[
68+
'request_path' => "product-1.html",
69+
'target_path' => "catalog/product/view/id/" . $product->getId(),
70+
'is_auto_generated' => 1,
71+
'redirect_type' => 0,
72+
'store_id' => 1,
73+
],
74+
[
75+
'request_path' => "product-1.html",
76+
'target_path' => "catalog/product/view/id/" . $product->getId(),
77+
'is_auto_generated' => 1,
78+
'redirect_type' => 0,
79+
'store_id' => $testStore->getId(),
80+
],
81+
];
82+
$actual = $this->getActualResults($productFilter);
83+
foreach ($expected as $row) {
84+
$this->assertContains($row, $actual);
85+
}
86+
87+
$product->setData('save_rewrites_history', true);
88+
$product->setUrlKey('new-url');
89+
$product->save();
90+
91+
$expected = [
92+
[
93+
'request_path' => "new-url.html",
94+
'target_path' => "catalog/product/view/id/" . $product->getId(),
95+
'is_auto_generated' => 1,
96+
'redirect_type' => 0,
97+
'store_id' => 1,
98+
],
99+
[
100+
'request_path' => "new-url.html",
101+
'target_path' => "catalog/product/view/id/" . $product->getId(),
102+
'is_auto_generated' => 1,
103+
'redirect_type' => 0,
104+
'store_id' => $testStore->getId(),
105+
],
106+
[
107+
'request_path' => "product-1.html",
108+
'target_path' => "new-url.html",
109+
'is_auto_generated' => 0,
110+
'redirect_type' => 301,
111+
'store_id' => 1,
112+
],
113+
[
114+
'request_path' => "product-1.html",
115+
'target_path' => "new-url.html",
116+
'is_auto_generated' => 0,
117+
'redirect_type' => 301,
118+
'store_id' => $testStore->getId(),
119+
],
120+
];
121+
122+
$actual = $this->getActualResults($productFilter);
123+
foreach ($expected as $row) {
124+
$this->assertContains($row, $actual);
125+
}
126+
}
127+
128+
/**
129+
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_rewrite_multistore.php
130+
* @magentoAppIsolation enabled
131+
*/
132+
public function testUrlKeyHasChangedInStoreviewContextWithPermanentRedirection()
133+
{
134+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository*/
135+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
136+
/** @var \Magento\Catalog\Model\Product $product*/
137+
$product = $productRepository->get('product1');
138+
139+
/** @var StoreManagerInterface $storeManager */
140+
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
141+
$storeManager->setCurrentStore(1);
142+
143+
$testStore = $storeManager->getStore('test');
144+
145+
$productFilter = [
146+
UrlRewrite::ENTITY_TYPE => 'product',
147+
];
148+
149+
$product->setData('save_rewrites_history', true);
150+
$product->setUrlKey('new-url');
151+
$product->save();
152+
153+
$expected = [
154+
[
155+
'request_path' => "new-url.html",
156+
'target_path' => "catalog/product/view/id/" . $product->getId(),
157+
'is_auto_generated' => 1,
158+
'redirect_type' => 0,
159+
'store_id' => 1,
160+
],
161+
[
162+
'request_path' => "product-1.html",
163+
'target_path' => "catalog/product/view/id/" . $product->getId(),
164+
'is_auto_generated' => 1,
165+
'redirect_type' => 0,
166+
'store_id' => $testStore->getId(),
167+
],
168+
[
169+
'request_path' => "product-1.html",
170+
'target_path' => "new-url.html",
171+
'is_auto_generated' => 0,
172+
'redirect_type' => 301,
173+
'store_id' => 1,
174+
],
175+
];
176+
177+
$actual = $this->getActualResults($productFilter);
178+
foreach ($expected as $row) {
179+
$this->assertContains($row, $actual);
180+
}
181+
}
182+
183+
/**
184+
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_rewrite_multistore.php
185+
* @magentoAppIsolation enabled
186+
*/
187+
public function testUrlKeyHasChangedInStoreviewContextWithoutPermanentRedirection()
188+
{
189+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository*/
190+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
191+
/** @var \Magento\Catalog\Model\Product $product*/
192+
$product = $productRepository->get('product1');
193+
194+
/** @var StoreManagerInterface $storeManager */
195+
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
196+
$storeManager->setCurrentStore(1);
197+
198+
$testStore = $storeManager->getStore('test');
199+
200+
$productFilter = [
201+
UrlRewrite::ENTITY_TYPE => 'product',
202+
];
203+
204+
$product->setData('save_rewrites_history', false);
205+
$product->setUrlKey('new-url');
206+
$product->save();
207+
208+
$expected = [
209+
[
210+
'request_path' => "new-url.html",
211+
'target_path' => "catalog/product/view/id/" . $product->getId(),
212+
'is_auto_generated' => 1,
213+
'redirect_type' => 0,
214+
'store_id' => 1,
215+
],
216+
[
217+
'request_path' => "product-1.html",
218+
'target_path' => "catalog/product/view/id/" . $product->getId(),
219+
'is_auto_generated' => 1,
220+
'redirect_type' => 0,
221+
'store_id' => $testStore->getId(),
222+
],
223+
];
224+
225+
$actual = $this->getActualResults($productFilter);
226+
foreach ($expected as $row) {
227+
$this->assertContains($row, $actual);
228+
}
229+
}
230+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Catalog\Api\ProductRepositoryInterface;
8+
use Magento\Catalog\Setup\CategorySetup;
9+
use Magento\Store\Model\StoreManagerInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
\Magento\TestFramework\Helper\Bootstrap::getInstance()
13+
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
14+
15+
require __DIR__ . '/../../Store/_files/store.php';
16+
17+
/** @var $installer CategorySetup */
18+
$objectManager = Bootstrap::getObjectManager();
19+
$installer = $objectManager->create(CategorySetup::class);
20+
$storeManager = $objectManager->get(StoreManagerInterface::class);
21+
$storeManager->setCurrentStore(0);
22+
23+
/** @var $product \Magento\Catalog\Model\Product */
24+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
25+
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
26+
->setAttributeSetId($installer->getAttributeSetId('catalog_product', 'Default'))
27+
->setStoreId(0)
28+
->setWebsiteIds([1])
29+
->setName('Product1')
30+
->setSku('product1')
31+
->setPrice(10)
32+
->setWeight(18)
33+
->setStockData(['use_config_manage_stock' => 0])
34+
->setUrlKey('product-1')
35+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
36+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
37+
38+
/** @var ProductRepositoryInterface $productRepository */
39+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
40+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Helper\Bootstrap;
8+
9+
$objectManager = Bootstrap::getObjectManager();
10+
11+
require __DIR__ . '/../../Store/_files/store_rollback.php';
12+
require __DIR__ . '/../../Store/_files/second_store_rollback.php';

0 commit comments

Comments
 (0)