magento / inventory

Magento Inventory Project (a.k.a MSI)
Open Software License 3.0
336 stars 247 forks source link

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

Open leonhelmus opened 2 years ago

leonhelmus commented 2 years ago

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

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[bot] commented 2 years ago

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 commented 2 years ago

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

pmonosolo commented 2 years ago

Ah, I just disabled that Plugin.

image

They need to rewrite that to check for:

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 commented 2 years ago

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 commented 1 year ago

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

LeonidTomashevskyAmasty commented 1 year ago

For now, the best solutions:

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

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