Skip to content
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

Conversation

BarnyShergold
Copy link

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)

  1. Fixes URL Regeneration Fails on Store-Level URL Keys - Products #28633

Manual testing scenarios (*)

  1. Set up categories as above
  2. Change top level url key of a store view
  3. Check URLs of a category without a changed key for all store views - problem above shows.
  4. Apply fix
  5. Go to top level category in every store view and change key and revert
  6. Once all stores have been forced to update - check URLs for the category in 3 and all URLs for all stores will be correct.

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)

@m2-assistant
Copy link

m2-assistant bot commented Jun 10, 2020

Hi @BarnyShergold. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

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.

@magento-engcom-team magento-engcom-team added Component: CatalogUrlRewrite Release Line: 2.4 Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner labels Jun 10, 2020
@BarnyShergold
Copy link
Author

@magento give me 2.4-develop instance
@magento run all tests

@magento-engcom-team
Copy link
Contributor

Hi @BarnyShergold. Thank you for your request. I'm working on Magento 2.4-develop instance for you

@BarnyShergold
Copy link
Author

@magento run all tests

@BarnyShergold
Copy link
Author

@magento run all tests

@BarnyShergold
Copy link
Author

@magento run all tests

@BarnyShergold BarnyShergold requested a review from YevSent June 22, 2020 21:21
@BarnyShergold BarnyShergold self-assigned this Jun 22, 2020
Copy link
Contributor

@lbajsarowicz lbajsarowicz left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

Copy link
Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use PHP Doc

Copy link
Author

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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use '==='

Copy link
Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suffix with 'Mock'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@BarnyShergold
Copy link
Author

@magento run all tests

Copy link
Contributor

@lbajsarowicz lbajsarowicz left a 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!

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-8274 has been created to process this Pull Request

@engcom-Echo
Copy link
Contributor

@magento run all tests

@engcom-Echo
Copy link
Contributor

@magento run Functional Tests CE, Functional Tests B2B

@BarnyShergold
Copy link
Author

@engcom-Echo - Any idea why these seemingly unrelated tests keep failing?

@swnsma
Copy link
Contributor

swnsma commented Sep 29, 2020

@BarnyShergold there is a migration to new chrome driver.
So tests are unstable until migration finished.

@BarnyShergold
Copy link
Author

@engcom-Echo @swnsma - All tests finally passed! They take such a long time.... maybe more hamsters are needed?

@BarnyShergold
Copy link
Author

@engcom-Echo - So what's left to be done before merging? Out of interest how long before that happens?

magento-engcom-team pushed a commit that referenced this pull request Sep 30, 2020
…ategory/products when Store View has modified URL keys #28676
@magento-engcom-team magento-engcom-team merged commit abddda7 into magento:2.4-develop Sep 30, 2020
@m2-assistant
Copy link

m2-assistant bot commented Sep 30, 2020

Hi @BarnyShergold, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: test coverage Component: CatalogUrlRewrite Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner Priority: P3 May be fixed according to the position in the backlog. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Risk: low Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

URL Regeneration Fails on Store-Level URL Keys - Products
8 participants