Description
This issue is automatically created based on existing pull request: #28164: Prevent side effect on category objects store_id and url_key on save
Preconditions (*)
Magento 2.4-develop
Category URL rewrites are saved by an "after save" observer for categories. But if saved for global scope, the URL rewrite generator itself modifies the passed category object for each assigned store to generate URL rewrites for all stores. Afterwards, url_key, url_path and store_id have the values of the last processed store id. This has side effects on later observers or other code that works on the category object after saving it.
Since the default store (0) is always the first item of $category->getStoreIds()
I chose to clone the category object only for the other stores, so that url_key and url_path for the global scope are still set to the original object.
Related Pull Requests
Fixed Issues (if relevant)
- magento/magento2#<issue_number>: Issue title
Steps to reproduce (*)
Abbreviated test case
$category->setStoreId(0);
$category->setUrlKey('url-key-for-global-scope');
$categoryResource->save($category);
Expected result (*)
$category->getStoreId()
should return 0
Actual result (*)
$category->getStoreId()
returns value of the last processed store id.
Questions or comments
Contribution checklist (*)
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- All new or changed code is covered with unit/integration tests (if applicable)
- All automated tests passed successfully (all builds are green)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status