magento/magento2#39863: Magento Catalog Product list widget returns incorrect count#40421
Conversation
…count - fixed catalog product widget displaying more products than configured
|
Hi @MaximLogic. 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 psirt@adobe.com. |
|
@magento run all tests |
|
@magento run all tests |
…count - reverted copyright change - added null safety to prevent 0 page bug
|
@magento run all tests |
engcom-Hotel
left a comment
There was a problem hiding this comment.
Thank you @MaximLogic for making the changes.
Please have a look into the static test failures as well.
…count - fixed Code Sniffer warnings
if you were talking about those warnings, they are not related to PR, but fixed that |
|
@magento run all tests |
engcom-Hotel
left a comment
There was a problem hiding this comment.
Thank you @MaximLogic for making the changes. Approving this PR for further processing.
|
Hi @MaximLogic, Thanks for the collaboration & contribution! ✔️ QA PassedPreconditions:
Steps to reproduce
Before: ✖️
After: ✔️
Builds are failed. Hence, moving this PR to Extended Testing. Thanks |
|
@magento run all tests |
|
@magento run all tests |
1 similar comment
|
@magento run all tests |
|
@magento run Integration Tests, Unit Tests |
2cf3742
into
magento:2.4-develop









Description (*)
According to issue #39863, the catalog product widget with pagination enabled was displaying more products than configured when the total products count is not a multiple of products per page. For example, when configuring the widget with
products_per_page = 5andproducts_count = 9, the widget displayed 10 products total (5 on page 1, 5 on page 2) instead of the expected 9 products (5 on page 1, 4 on page 2). Additionally, the pager showed incorrect text "Items 6 to 10 of 9 total" on the second page.The problem occurring, because in
ProductsList::getBaseCollection(), the collection limit was set usingsetPageSize()andsetCurPage()methods without considering theproducts_count(total limit) constraint. This caused the SQL query to fetch full page size worth of products regardless of the total limit.Solution:
I replaced automatic pagination with manual SQL LIMIT calculation in
getBaseCollection(), and added logic to calculate the correct limit:min(pageSize, max(0, totalLimit - offset)). This ensures that on the last page, only the remaining products within the total limit are fetched. Also, updated unit tests to reflect the new behavior and added test cases for edge scenariosFixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)