[Issue] Prevent side effect on category objects store_id and url_key on save #29585
Labels
Component: CatalogUrlRewrite
Fixed in 2.4.x
The issue has been fixed in 2.4-develop branch
Issue: Confirmed
Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed
Issue: Format is valid
Gate 1 Passed. Automatic verification of issue format passed
Issue: Ready for Work
Gate 4. Acknowledged. Issue is added to backlog and ready for development
Priority: P2
A defect with this priority could have functionality issues which are not to expectations.
Progress: done
Reported on 2.4.0
Indicates original Magento version for the Issue report.
Reproduced on 2.4.x
The issue has been reproduced on latest 2.4-develop branch
Severity: S3
Affects non-critical data or functionality and does not force users to employ a workaround.
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)
Steps to reproduce (*)
Abbreviated test case
Expected result (*)
$category->getStoreId()
should return0
Actual result (*)
$category->getStoreId()
returns value of the last processed store id.Questions or comments
Contribution checklist (*)
The text was updated successfully, but these errors were encountered: