magento2: Moving a category to a new parent does not generate 301 redirects for product URLs
Preconditions and environment
- Magento 2.4.6 and potentially all prior versions
Steps to reproduce
- Install any recent version of Magento (2.4.4 - 2.4.6)
- Enable the following settings under Catalog -> Catalog -> SEO
- Create two categories under the root category with one child category under the first one.
- Create a product and assign it to the child category.
- Enable all categories and products.
- Using the drag & drop feature of the category tree, move the child category to be underneath the second parent you created.
- Navigate to Marketing -> URL Rewrites, and observe that a 301 redirect was created for the original category URL, but not for the original product URL within the original parent category.
Expected result
A 301 redirect will be created for every category / product URL path within the original parent category pointing to the new category / product path under the new parent category. Frontend visitors will get redirected to the new product URL path if they try to access the original path.
Actual result
A 301 redirect was created from the old category path to the new one, but no redirects were created for product URLs. Frontend visitors receive a 404 if they try to access the original product URL path.
Additional information
The issue appears to lie in this observer Magento\CatalogUrlRewrite\Observer\CategoryProcessUrlRewriteMovingObserver
.
It calls this method $this->urlRewriteHandler->deleteCategoryRewritesForChildren($category)
, which results in the product level rewrites being deleted before this method is run $productUrlRewriteResult = $this->urlRewriteHandler->generateProductUrlRewrites($category)
, which looks for those rewrites for the purpose of creating 301 redirects.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 5
- Comments: 26 (1 by maintainers)
Commits related to this issue
- magento/magento2#37039: Not generating 301 redirects for product - fixed issue with generating 301 redirects for product after moving a category to a new parent — committed to Yaroslav1301/magento2-contribution by Yaroslav1301 a year ago
- magento/magento2#37039: Changed variable name — committed to Yaroslav1301/magento2-contribution by Yaroslav1301 a year ago
- magento/magento2#37039: Covered changes with Unit Test — committed to Yaroslav1301/magento2-contribution by Yaroslav1301 a year ago
Hi @hiddenmike. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel. ⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.