inventory
inventory copied to clipboard
Category count for category pages is wrong when show out of stock is enabled 2.4.5
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 (*)
- cataloginventory/options/show_out_of_stock is enabled
- Magento 2.4.5
- php 8.1
- latest version of magento/module-inventory:1.2.3
Steps to reproduce (*)
- I have a total of 29 products in the category for example
- i click a filter that should show only 9 products as a result.
- In the total num i get to see 33 instead of 9, while i do only see 9 products.
Expected result (*)
- total number of products count is 9
Actual result (*)
- total number of products count is 33
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?
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
- Join Magento Community Engineering Slack and ask your questions in #github channel.
Might be also related to my testing today: https://github.com/magento/magento2/issues/36055
Ah, I just disabled that Plugin.
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.
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
Amasty's QA has also reproduced this issue on 2.4.5-p1 via MFTF for Improved Layered Navigation.
For now, the best solutions:
- Disable the plugin.
- Disable MSI extensions.
Suggested fix $items = $subject->getCollection()->getItems();
is not working: