magento / magento/inventory

Not indexing In-stock products

Open
#3,351 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Progress: ready for grooming
Dominant language
PHP
Stars
357
Forks
262
PR merge metrics
No merged PRs in 30d

Description

MSI plugin class prevents indexing in-stock products in special scenarios. When indexing Magento indexes products in a batch of 500 (default). On each batch, it goes to loop until it finds 0 products. Let's say there are 50,000 SKUs and the system is indexing
when on the 10th batch, it finds 460 products, and the MSI plugin checks if these consist of any out-of-stock products and returns only in-stock arrays. If none is found it then returns an empty array. Now, when Magento receives 0 products it thinks it reached the end of products and then stops indexing after that batch. Meaning there could be more products that are in stock that needs to be indexed.

In Magento this line https://github.com/magento/magento2/blob/28c1f28a2552de69158b40d1eaf84e45430c16f9/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php#L382 it loops through catalog_entity_table in a batch of 500 (default).

When MSI returns 0 products of that batch (https://github.com/magento/inventory/blob/e05d62abd8ce5aa043d40ad9739a3ea198b9e8f1/InventoryCatalogSearch/Plugin/CatalogSearch/Model/Indexer/ChildProductFilterByInventoryStockPlugin.php#L62), Magento thinks there are no more products to index and stops indexing rest of the products.

Preconditions (*)
  1. Magento Version: 2.4.3-p1
Steps to reproduce (*)
  1. Have SKUs more than 20,000 or
  2. Configure the indexing batch to less than 100 when having less SKUs https://developer.adobe.com/commerce/php/development/components/indexing/optimization/
Expected result (*)
  1. Should index all in-stock products when Display Out of Stock Products is set to No in config
Actual result (*)
  1. Doesn't index all in-stock products

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Magento_CatalogSearch/Model/Indexer/Full.php around line 382 and the InventoryCatalogSearch ChildProductFilterByInventoryStockPlugin around line 62. Reproduce with many SKUs or a small indexing batch while Display Out of Stock Products is disabled, then verify that indexing processes all in-stock products rather than stopping early.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.