Skip to content
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

Category count for category pages is wrong when show out of stock is enabled 2.4.5 #3360

Open
leonhelmus opened this issue Aug 15, 2022 · 6 comments

Comments

@leonhelmus
Copy link

leonhelmus commented Aug 15, 2022

After upgrading to php 8.1 + M2.4.5 i get the following issue:

  • Product count of category pages is wrong it shows the total of all products while i do have a filter enabled.

Preconditions (*)

  1. cataloginventory/options/show_out_of_stock is enabled
  2. Magento 2.4.5
  3. php 8.1
  4. latest version of magento/module-inventory:1.2.3

Steps to reproduce (*)

  1. I have a total of 29 products in the category for example
  2. i click a filter that should show only 9 products as a result.
  3. In the total num i get to see 33 instead of 9, while i do only see 9 products.

Expected result (*)

  1. total number of products count is 9

Actual result (*)

  1. total number of products count is 33
    image

This patch that i created resolved the issue for me:

diff --git a/Plugin/Catalog/Block/ProductList/UpdateToolbarCount.php b/Plugin/Catalog/Block/ProductList/UpdateToolbarCount.php
--- a/Plugin/Catalog/Block/ProductList/UpdateToolbarCount.php
+++ b/Plugin/Catalog/Block/ProductList/UpdateToolbarCount.php
@@ -104,7 +104,7 @@
                 $defaultScopeId = $this->storeManager->getWebsite()->getCode();
                 $stock_id = (int) $this->stockRegistry->getStock($defaultScopeId)->getStockId();
                 $skus = [];
-                $items = $category->getProductCollection()->getItems();
+                $items = $subject->getCollection()->getItems();
                 array_walk(
                     $items,
                     function ($item) use (&$skus) {

The reason why i think it's going wrong is that this plugin does not take into account that filters are used on a category page. What do you think magento?

@m2-assistant
Copy link

m2-assistant bot commented Aug 15, 2022

Hi @leonhelmus. Thank you for your report.
To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


@pmonosolo
Copy link

Might be also related to my testing today: magento/magento2#36055

@pmonosolo
Copy link

Ah, I just disabled that Plugin.

image

They need to rewrite that to check for:

  • If page is Catalog Search Page
  • If there are filters applied.

Currently it just checks the Category page, so on Search Page it uses "Default Category" and outputs the whole catalog.

When you filter by attributes, it does not decrease the number because the only lookup that is done is for Category. It does not check if filters were applied to the category.

@sebastian-ehrling
Copy link

Disable the plugin only works with enabled MSI. I've removed all MSI Modules from my projects.
So the fix doesn't work for me

@LeonidTomashevskyAmasty
Copy link
Contributor

LeonidTomashevskyAmasty commented Oct 3, 2022

Amasty's QA has also reproduced this issue on 2.4.5-p1 via MFTF for Improved Layered Navigation.

@LeonidTomashevskyAmasty
Copy link
Contributor

For now, the best solutions:

  1. Disable the plugin.
  2. Disable MSI extensions.

Suggested fix $items = $subject->getCollection()->getItems(); is not working:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Backlog
  
Ready for Grooming
Development

No branches or pull requests

4 participants