-
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
Fixed URL Rewrite addition/removal on product website add/remove #26999
Fixed URL Rewrite addition/removal on product website add/remove #26999
Conversation
Hi @gwharton. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
Moved scope of ProductToWebsiteChangeObserver to base instead of adminhtml as this functionality has been moved to a consumer. With the observer set to adminhtml, this observer was not being called properly on changing the websites for a particular product in the consumer. Corrected ProductProcessUrlRewriteSavingObserver to correctly add and remove rewrite URLs when products are added and removed from websites using the Product Edit Admin Page. Corrected ProductToWebsiteChangeObserver to correctly add and remove rewrite URLs when products are added and removed using the Products Grid Mass Action function. Extended unit tests to cover both Observers. Fixed MFTF test for Product URL Rewrite generation.
@magento run Database Compare |
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.
Hi @gwharton,
Thank you so much for the fix! From first view your fix looks good, but url rewrites quite complex thing and usually there are no issues with single unit, but issues appears when few components works together. For such cases unit tests much less effective than integration tests, as there you’re having real objects, real db, etc and you could do some queries to db and compare with what you expect.
Could you review my comments and cover your changes with integration tests?
app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php
Outdated
Show resolved
Hide resolved
app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php
Outdated
Show resolved
Hide resolved
.../Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php
Outdated
Show resolved
Hide resolved
app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php
Outdated
Show resolved
Hide resolved
app/code/Magento/CatalogUrlRewrite/Observer/ProductToWebsiteChangeObserver.php
Outdated
Show resolved
Hide resolved
.../Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php
Outdated
Show resolved
Hide resolved
I have added a new function to the class Magento/UrlRewrite/Model/Storage/DbStorage.php. Previously this class only provided the ability to remove a single url rewrite at a time, which lead to lengthy and nested foreach loops, with many many database transactions to process for a single operation where multiple url rewrites needed removing. I added a new function which allows you to remove multiple url rewrite's based on arrays of entity_ids and websites_ids, allowing you to remove multiple items from multiple websites in a single operation. Question, Would it be worth adding this new deleteEntitiesFromStores function to the UrlPersistInterface so it can sit alongside the existing deleteByData function already in that interface, and provided by DbStorage. It could be useful elsewhere. |
app/code/Magento/CatalogUrlRewrite/Plugin/ProductProcessUrlRewriteRemovingPlugin.php
Outdated
Show resolved
Hide resolved
Apologies for the large number of additions of |
Let me know if you want me to cleanup commit history and squash. |
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.
Looks like this is the last iteration :)
Let's squash all changes once everything will be ready
app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php
Outdated
Show resolved
Hide resolved
app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php
Outdated
Show resolved
Hide resolved
app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php
Outdated
Show resolved
Hide resolved
app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php
Outdated
Show resolved
Hide resolved
Processed review comments.
@magento run all tests |
Failed functional, static tests not related to the changes in this PR |
The integration test that used to fail now passes. I guess this is what you get by running the tests against the PR merged with 2.4-develop as opposed to running against the forked repo as if someone manages to commit something bad to 2.4-develop, everyones tests fail. |
@engcom-Echo thank you so much! |
Hi @ihor-sviziev, thank you for the review. |
Failed functional, static tests not related to the changes in this PR |
Hi @gwharton, thank you for your contribution! |
@gwharton
Thus we had to revert changes. We need to find a more appreciative solution or make refact of current. |
Understood. We did do some work on optimising it, but obviously not enough. |
Related Pull Requests
magento/inventory#2887
Description (*)
Moved scope of ProductToWebsiteChangeObserver to base instead of adminhtml
as this functionality has been moved to a consumer. With the observer set
to adminhtml, this observer was not being called properly on changing
the websites for a particular product in the consumer.
Corrected ProductProcessUrlRewriteSavingObserver to correctly add and remove
rewrite URLs when products are added and removed from websites using the
Product Edit Admin Page.
Corrceted ProductToWebsiteChangeObserver to correctly add and remove
rewrite URLs when products are added and removed using the Products
Grid Mass Action function.
Extended unit tests to cover both Observers.
Fixed Issues (if relevant)
This also fixes the issue with URL rewrites not being generated correctly using the mass action remove/add from website.
Manual testing scenarios (*)
Contribution checklist (*)