-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
BUG - Prevent Magento from Creating incorrect URLs for category/products when Store View has modified URL keys #28676
BUG - Prevent Magento from Creating incorrect URLs for category/products when Store View has modified URL keys #28676
Conversation
Hi @BarnyShergold. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. |
Hi @BarnyShergold. Thank you for your request. I'm working on Magento 2.4-develop instance for you |
@magento run all tests |
@magento run all tests |
@magento run all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review the comments
@@ -21,6 +21,9 @@ | |||
|
|||
/** | |||
* Class ProductScopeRewriteGenerator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the original code but I've removed it anyway.
@@ -252,9 +254,14 @@ private function getCategoryWithOverriddenUrlKey($storeId, Category $category) | |||
Category::ENTITY | |||
); | |||
|
|||
if (!$isUrlKeyOverridden) { | |||
// Category should be loaded per appropriate store at all times. This is because whilst the URL key on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use PHP Doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// category in focus might be unchanged, parent category URL keys might be. If the category store ID | ||
// and passed store ID are the same then return current category as it is correct but may have changed in memory | ||
|
||
if (!$isUrlKeyOverridden && $storeId == $category->getStoreId()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use '==='
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -69,6 +70,9 @@ class ProductScopeRewriteGeneratorTest extends TestCase | |||
/** @var ScopeConfigInterface|MockObject */ | |||
private $configMock; | |||
|
|||
/** @var CategoryRepositoryInterface|MockObject */ | |||
private $categoryRepository; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suffix with 'Mock'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@magento run all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️ Great work, thank you!
Hi @lbajsarowicz, thank you for the review. |
@magento run all tests |
@magento run Functional Tests CE, Functional Tests B2B |
@engcom-Echo - Any idea why these seemingly unrelated tests keep failing? |
@BarnyShergold there is a migration to new chrome driver. |
@engcom-Echo @swnsma - All tests finally passed! They take such a long time.... maybe more hamsters are needed? |
@engcom-Echo - So what's left to be done before merging? Out of interest how long before that happens? |
…ategory/products when Store View has modified URL keys #28676
Hi @BarnyShergold, thank you for your contribution! |
Description (*)
If a Store View has a category tree where url_keys have been modified - eg different language - then if there is a category that has does not have a modified key (eg its the same in different languages) BUT has parents that DO, then the original code would use the DEFAULT Store View of the Category for creating URLS.
When scripts to regenerate URLs are used (as described in 28633) then they will end up creating incorrect URLs.
There is also a CORE issue. If an Admin changes the URL key of a category then Magento rebuilds all the URLs for the underlying categories and all the category/product URLs. However, if this is done where a category falls into the description above, then Magento sets the URL for that catalog/product combination for the store view it is done on but does it for ALL store views.
EG Given that the Default is English and there is a 3-level category :
Men > Collections > Premium
(men) (collections) (premium)
A product in Premium would have the url key : men/collections/premium/
Now there are two other Store Views : Italian & German
They have the names of the Men & Collections categories translated but not Premium as that is a brand.
So in the Italian Store the category should be -
(uomo) (collezioni) (premium)
German -
(herren) (kollektionen) (premium)
IF an Admin went into the Italian store view and decided to change the URL key of 'uomo' to 'uomo-italiano' then Magento would rebuild all the keys for the view. If then you checked the url_redirect table for all the URLs for a single product for the "Premium" category then you would expect to see -
men/collections/premium/
herren/kollektionen/premium/
uomo/collezioni/premium/
BUT the bug causes all storeviews to be set to the Italian URL -
uomo/collezioni/premium/
uomo/collezioni/premium/
uomo/collezioni/premium/
Categories where URL keys have been modified are okay.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)