Skip to content

Commit

Permalink
ENGCOM-8030: Prevent side effect on category objects store_id and url…
Browse files Browse the repository at this point in the history
…_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
  • Loading branch information
magento-engcom-team committed Sep 22, 2020
2 parents 390505a + 6083a7c commit d1359f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class CategoryUrlRewriteGenerator
*/
private $mergeDataProviderPrototype;

/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @var bool
*/
Expand Down Expand Up @@ -124,10 +129,11 @@ protected function generateForGlobalScope(
$mergeDataProvider = clone $this->mergeDataProviderPrototype;
$categoryId = $category->getId();
foreach ($category->getStoreIds() as $storeId) {
$category->setStoreId($storeId);
if (!$this->isGlobalScope($storeId)
&& $this->isOverrideUrlsForStore($storeId, $categoryId, $overrideStoreUrls)
) {
$category = clone $category; // prevent undesired side effects on original object
$category->setStoreId($storeId);
$this->updateCategoryUrlForStore($storeId, $category);
$mergeDataProvider->merge($this->generateForSpecificStoreView($storeId, $category, $rootCategoryId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public function testGenerationForGlobalScope()
],
$this->categoryUrlRewriteGenerator->generate($this->category, false, $categoryId)
);
$this->assertEquals(0, $this->category->getStoreId(), 'Store ID should not have been modified');
}

/**
Expand Down

0 comments on commit d1359f2

Please sign in to comment.