Skip to content

Commit d1359f2

Browse files
ENGCOM-8030: Prevent side effect on category objects store_id and url_key on save #28164
- Merge Pull Request #28164 from schmengler/magento2:url-rewrite-side-effect - Merged commits: 1. 7bd5e25 2. 8bcd2fa 3. 87c5c60 4. 31c5963 5. c051134 6. 6083a7c
2 parents 390505a + 6083a7c commit d1359f2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class CategoryUrlRewriteGenerator
5454
*/
5555
private $mergeDataProviderPrototype;
5656

57+
/**
58+
* @var CategoryRepositoryInterface
59+
*/
60+
private $categoryRepository;
61+
5762
/**
5863
* @var bool
5964
*/
@@ -124,10 +129,11 @@ protected function generateForGlobalScope(
124129
$mergeDataProvider = clone $this->mergeDataProviderPrototype;
125130
$categoryId = $category->getId();
126131
foreach ($category->getStoreIds() as $storeId) {
127-
$category->setStoreId($storeId);
128132
if (!$this->isGlobalScope($storeId)
129133
&& $this->isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls)
130134
) {
135+
$category = clone $category; // prevent undesired side effects on original object
136+
$category->setStoreId($storeId);
131137
$this->updateCategoryUrlForStore($storeId, $category);
132138
$mergeDataProvider->merge($this->generateForSpecificStoreView($storeId, $category, $rootCategoryId));
133139
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryUrlRewriteGeneratorTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public function testGenerationForGlobalScope()
158158
],
159159
$this->categoryUrlRewriteGenerator->generate($this->category, false, $categoryId)
160160
);
161+
$this->assertEquals(0, $this->category->getStoreId(), 'Store ID should not have been modified');
161162
}
162163

163164
/**

0 commit comments

Comments
 (0)