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
Duplicate product collection items when loading category positions in the default store #33145
Comments
Hi @leoquijano. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. Please, add a comment to assign the issue:
🕙 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, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
I've also been investigating this issue and can confirm it exists in Magento 2.4.1-p1 too. |
Hi @engcom-Bravo. Thank you for working on this issue.
|
✅ Confirmed by @engcom-Bravo Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself. |
Any update on this ? |
Hi @leoquijano |
Preconditions (*)
Steps to reproduce (*)
It's important that that widget is processed in the default store (
Store::DEFAULT_STORE_ID
), so the_applyZeroStoreProductLimitations
call is used in the following code.In
\Magento\Catalog\Model\ResourceModel\Product\Collection
:Expected result (*)
The products list is rendered in the admin.
Actual result (*)
The products list rendering fails with the following error message:
(where <ID> is a product ID)
The issue can be tracked down to the
_applyZeroStoreProductLimitations
call mentioned above:The JOIN with the catalog_category_product generates a SQL query like this:
(Where <LIST OF CATEGORY IDS> includes the parent category and its children)
Now, this query is supposed to return 1 row per product. But the join with
catalog_category_product
can return multiple entries per product, if the product has different positions in different categories. It can even be reproduced by running the simplified query above with the appropriate category IDs. Even though the query has aDISTINCT
clause, the fact that a product can have different positions will make it return duplicate entries.This, in turn, will cause an exception when adding the product to the collection, in
\Magento\Framework\Data\Collection::addItem
.A workaround can be implemented by replacing the JOIN above with the following via a patch:
This JOIN will return one entry per product and will pick only one position for each one.
Note that I grouped the products by the minimum position they have in any of the categories they're in. A more sophisticated solution might prefer a specific category (perhaps the one used for the filtering) over the other ones.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
I marked this as an S1 because it affects any admin area where filtered product lists are being used. This is an issue that will show up after the catalog has been used for a while (products might have different positions due to the normal catalog administration), and will break the admin rendering of the content areas that include those products.
The text was updated successfully, but these errors were encountered: