-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions and environment
- Magento version: 2.4.6-p3
Steps to reproduce
- Create a category in the Admin
URL Key is now auto-generated, system/auto-generated URL Rewrite is created (redirect_type = 0) - Change category URL Key
System/auto-generated URL Rewrite is updated to a 301 from old to new (redirect_type = 301)
A new system/auto-generated URL Rewrite is added (redirect_type = 0) from new tot internal route - Enable canonical URLs
bin/magento config:set catalog/seo/category_canonical_tag 1
- View the category in the frontend
State in the database with example data:
Expected result
Canonical URL === New category URL Key
Actual result
Canonical URL === Old category URL Key
Additional information
In \Magento\Catalog\Model\Category.php::getUrl()
URL rewrites are loaded for the category by ID and store. This returns the first result, which is the 301 redirect from the old to the new category URL. The request_path
of this rewrite is used to form the return value of Category.php:getUrl()
, which contains the old URL.
The fix is that only the system/auto-generated URL rewrite is loaded. Therefor the array param provided to \Magento\UrlRewrite\Model\UrlFinderInterface::findOneByData()
in vendor/magento/module-catalog/Model/Category.php:613
should be extended with UrlRewrite::REDIRECT_TYPE => 0,
. The same addition is already in place for \Magento\Catalog\Model\Product\Url::getProductUrl()
, but missing for categories.
Release note
Note that I've only yet encountered this issue in the category canonicals, but since the issue resides in Category.php:getUrl()
, there are probably other area's where this bug causes an issue.
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”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status