Skip to content

magento/magento2#39863: Magento Catalog Product list widget returns incorrect count#40421

Merged
magento-devops-reposync-svc merged 8 commits intomagento:2.4-developfrom
MaximLogic:fix-for-issue-39863
Mar 5, 2026
Merged

magento/magento2#39863: Magento Catalog Product list widget returns incorrect count#40421
magento-devops-reposync-svc merged 8 commits intomagento:2.4-developfrom
MaximLogic:fix-for-issue-39863

Conversation

@MaximLogic
Copy link
Copy Markdown
Contributor

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 = 5 and products_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 using setPageSize() and setCurPage() methods without considering the products_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 scenarios

Fixed Issues (if relevant)

  1. Fixes Magento Catalog Product list widget returns incorrect count #39863

Manual testing scenarios (*)

  1. Login to Magento Admin
  2. Navigate to Content → Pages
  3. Select any existing page or create a new page
  4. Click "Edit with Page Builder" (if you use Text Editor, skip this and next step)
  5. Drag and drop a Row element, then drag HTML Code inside it
  6. Click "Insert Widget" button
  7. Select "Catalog Products List" widget type
  8. Configure the widget:
    • Set "Number of Products per Page" = 5
    • Set "Number of Products to Display" = 9
    • Add any condition to filter products (e.g., category)
    • Save the widget configuration
  9. Save the page and view it on the frontend
  10. Verify page 1 displays exactly 5 products
  11. Click the pagination to go to page 2
  12. Expected result: Page 2 displays exactly 4 products (not 5)
  13. Expected result: Pager shows "Items 6 to 9 of 9 total"
  14. Expected result: Total of 9 products displayed across both pages

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

…count

- fixed catalog product widget displaying more products than configured
@m2-assistant
Copy link
Copy Markdown

m2-assistant Bot commented Jan 9, 2026

Hi @MaximLogic. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ 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
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@ct-prd-pr-scan
Copy link
Copy Markdown

ct-prd-pr-scan Bot commented Jan 9, 2026

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.

@MaximLogic
Copy link
Copy Markdown
Contributor Author

@magento run all tests

@engcom-Hotel
Copy link
Copy Markdown
Contributor

@magento run all tests

Comment thread app/code/Magento/CatalogWidget/Block/Product/ProductsList.php Outdated
Comment thread app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php Outdated
Comment thread app/code/Magento/CatalogWidget/Block/Product/ProductsList.php Outdated
Comment thread app/code/Magento/CatalogWidget/Block/Product/ProductsList.php
MaximLogic and others added 2 commits February 12, 2026 10:36
@MaximLogic
Copy link
Copy Markdown
Contributor Author

@magento run all tests

Copy link
Copy Markdown
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

Thank you @MaximLogic for making the changes.

Please have a look into the static test failures as well.

@MaximLogic
Copy link
Copy Markdown
Contributor Author

Thank you @MaximLogic for making the changes.

Please have a look into the static test failures as well.

Screenshot 2026-02-13 at 14 30 09

if you were talking about those warnings, they are not related to PR, but fixed that

@MaximLogic
Copy link
Copy Markdown
Contributor Author

@magento run all tests

@engcom-Hotel engcom-Hotel moved this from Changes Requested to Review in Progress in Community Dashboard Feb 18, 2026
Copy link
Copy Markdown
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

Thank you @MaximLogic for making the changes. Approving this PR for further processing.

@engcom-Bravo
Copy link
Copy Markdown
Contributor

Hi @MaximLogic,

Thanks for the collaboration & contribution!

✔️ QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop

Steps to reproduce

  • Login to Magento Admin

  • Navigate to Content → Pages

  • Select any existing page or create a new page

  • Click "Edit with Page Builder" (if you use Text Editor, skip this and next step)

  • Drag and drop a Row element, then drag HTML Code inside it

  • Click "Insert Widget" button

  • Select "Catalog Products List" widget type

  • Configure the widget:

  • Set "Number of Products per Page" = 5

  • Set "Number of Products to Display" = 9

  • Add any condition to filter products (e.g., category)

  • Save the widget configuration

  • Save the page and view it on the frontend

  • Verify page 1 displays exactly 5 products

  • Click the pagination to go to page 2

Before: ✖️ 

Screenshot 2026-02-19 at 3 14 18 pm

After: ✔️

Screenshot 2026-02-19 at 4 06 41 pm

Builds are failed. Hence, moving this PR to Extended Testing.

Thanks

@engcom-Bravo engcom-Bravo moved this to Extended testing (optional) in Community Dashboard Feb 19, 2026
@engcom-Dash engcom-Dash self-assigned this Feb 19, 2026
@engcom-Dash
Copy link
Copy Markdown
Contributor

@magento run all tests

@engcom-Dash
Copy link
Copy Markdown
Contributor

@magento run all tests

1 similar comment
@engcom-Dash
Copy link
Copy Markdown
Contributor

@magento run all tests

@engcom-Dash
Copy link
Copy Markdown
Contributor

@magento run Integration Tests, Unit Tests

@engcom-Dash
Copy link
Copy Markdown
Contributor

Few Functional B2B, CE and EE failures are not consistent in recent 2 builds. They are neither part of this PR nor failing because of the PR changes, seems to be flaky. The consistent failures are known issues and have open JIRAs.

CE
Build 1
https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40421/f6e596bbdd5fa3bb677ef190b580bae6/Functional/allure-report-ce/index.html#categories
image

Build 2
https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40421/5634d80ecf2abaaa8a1746ce59e3dd4e/Functional/allure-report-ce/index.html#categories
image

EE
Build 1
https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40421/bce0802c8f718a73e38196850edf2cfc/Functional/allure-report-ee/index.html#categories
image

Build 2
https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40421/fc4e3784761783a9d884d0a6327f6b81/Functional/allure-report-ee/index.html#categories
image

B2B
Build 1
https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40421/c65dbdb19682b925063a0a2f45303dd2/Functional/allure-report-b2b/index.html#categories/bdbf199525818fae7a8651db9eafe741
image

Build 2
https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/40421/5de9b35df9a4561ca13053454c40874d/Functional/allure-report-b2b/index.html#categories
image

Integration test and Unit Tests
The failure is occurring across all PRs and is not related to this specific PR.

Known Issue
AssertSuccessMessageAppearsAfterAddingProductToCartThatContainsOutOfStockProductTest ACQE-9359
PurchaseOrderEnableDisableE2ETest ACQE-9362
AdminDisplayingCartAndCatalogPriceRulesGridsTest ACQE-9406
StorefrontArabicLocaleDobVisibleAndSaveTest ACQE-9419

Hence, Moving this PR Merge In Progress.

@engcom-Dash engcom-Dash moved this from Extended testing (optional) to Merge in Progress in Community Dashboard Feb 23, 2026
@magento-devops-reposync-svc magento-devops-reposync-svc merged commit 2cf3742 into magento:2.4-develop Mar 5, 2026
7 of 12 checks passed
@ct-prd-projects-boards-automation ct-prd-projects-boards-automation Bot moved this from Merge in Progress to Recently Merged in Community Dashboard Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P3 May be fixed according to the position in the backlog. Progress: deployment queue Project: Community Picked PRs upvoted by the community

Projects

Status: Recently Merged

Development

Successfully merging this pull request may close these issues.

Magento Catalog Product list widget returns incorrect count

6 participants