inventory icon indicating copy to clipboard operation
inventory copied to clipboard

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

Open leonhelmus opened this issue 2 years ago • 6 comments

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?

leonhelmus avatar Aug 15 '22 10:08 leonhelmus

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


m2-assistant[bot] avatar Aug 15 '22 10:08 m2-assistant[bot]

Might be also related to my testing today: https://github.com/magento/magento2/issues/36055

pmonosolo avatar Aug 30 '22 20:08 pmonosolo

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.

pmonosolo avatar Sep 02 '22 22:09 pmonosolo

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

sebastian-ehrling avatar Sep 05 '22 12:09 sebastian-ehrling

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

LeonidTomashevskyAmasty avatar Oct 03 '22 10:10 LeonidTomashevskyAmasty

For now, the best solutions:

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

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

LeonidTomashevskyAmasty avatar Oct 03 '22 15:10 LeonidTomashevskyAmasty