-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Category product count does not include products assigned to the category itself #40295
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
base: 2.4-develop
Are you sure you want to change the base?
Category product count does not include products assigned to the category itself #40295
Conversation
|
Hi @mimou78. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email [email protected]. |
1 similar comment
|
The security team has been informed about this pull request due to the presence of risky security keywords. For security vulnerability reports, please visit Adobe's vulnerability disclosure program on HackerOne or email [email protected]. |
…lf-reference-40263
…lf-reference-40263
…lf-reference-40263
app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php
Outdated
Show resolved
Hide resolved
app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Category/CollectionTest.php
Outdated
Show resolved
Hide resolved
|
@magento run all tests |
app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Category/CollectionTest.php
Show resolved
Hide resolved
swnsma
left a comment
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.
Thank you for your changes!
Could you have a look at my small note about unit tests?
|
@magento run Static Tests Unit Tests |
|
Failed to run the builds. Please try to re-run them later. |
|
@magento run Static Tests |
|
@magento run Unit Tests |
app/code/Magento/Catalog/Test/Fixture/CategoryTreeWithProducts.php
Outdated
Show resolved
Hide resolved
swnsma
left a comment
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 @mimou78,
Thank you very much for your great effort!
Could you please have a look at my comment regarding the newly created fixture?
I'm afraid my position is that it might be a bit excessive, and if we can achieve the same testing goals while introducing less code, that would be a more appropriate approach.
Hello, thanks for the feedback! No worries at all — I’m completely open to alternatives. |
|
@magento run Integration Tests |
|
@magento run all tests |
|
@magento run Functional Tests CE |
swnsma
left a comment
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 @mimou78,
Could you check my reply?
I beleive we can replace the constant \Magento\Catalog\Model\ResourceModel\Category\Collection::BULK_PROCESSING_LIMIT with new constructor param in order to make the implementation more convinient for testing.
Hi, Sounds good, I’ll take care of it. If we go in that direction, the change should probably be reflected in the changelog, since it wouldn’t be only a bugfix anymore but also an improvement. It may also require a short piece of documentation to explain the purpose of the new parameter and how to configure it. |
|
Hi @mimou78, |
|
Hi @swnsma, From my understanding, this looks like a bug in the current implementation. If we decide to fix it in this issue, we would also need to remove the dependency on catalogProductVisibility, though I'm not entirely sure about the correct approach to remove that dependency. I’ve addressed your last request, so feel free to review and give me your thoughts on how we should proceed regarding this visibility logic. |
Summary
This pull request fixes an issue where the product count displayed in the Admin Category Grid
incorrectly shows 0 products for categories that do not have any descendants.
The current logic only counts products assigned to descendant categories and does not
include products directly assigned to the category itself.
Problem
When building the temporary table of category → descendant relationships, the SQL
logic only inserts rows for descendants, not for the category itself.
As a result:
Related Issue
Fixes #40263
What This Fix Does
This change ensures that each category always includes a self-reference entry in
the temporary category/descendant table.
As a result:
Technical Changes
(category_id = X, descendant_id = X)for everyprocessed category ID.
and the category itself.
Testing Instructions
Backward Compatibility
Risks
Low. This affects only the temporary table generation used for counting, not
the category model or product relations.