Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent side effect on category objects store_id and url_key on save #28164

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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