Magento2: Random products show out of stock until manual reindex

Created on 10 Jun 2018  路  18Comments  路  Source: magento/magento2

I have setup a new Magento store and have been adding products. I have recently noticed that some products are not showing up as out of stock on the front end despite being properly added in the admin panel (i.e. correct inventory, categories etc). Opening and saving these products a few times in the backend fixes this issue. Another way to fix this issue is manually running the reindex command from the SSH. All this time, the crons are properly running and according to the admin panel, the reindex is happening every minute.

Preconditions

  1. Nginx, PHP-FPM, MariaDB, CentOS 7
  2. Magento 2.2.4

Steps to reproduce

  1. Add some products.
  2. Some of the them will show up as out of stock.
  3. Reindex manually and they will show up as in stock.

Expected result

  1. Products should show up in stock without manual reindex.

Actual result

  1. Products only show up in stock after manual reindex.

I have seem two similar issues on StackExchange as well and none of them have gotten a proper answer:
https://magento.stackexchange.com/questions/150656/new-products-not-showing-until-manually-reindexing-although-cron-is-running
https://magento.stackexchange.com/questions/1177/products-seemingly-randomly-disappearing-until-reindex

Indexer Fixed in 2.3.x Clear Description Format is valid

Most helpful comment

Still an in issue in 2.3.3, this issue alone has at this point cost my client tens of thousands of dollars.
Update on save DOES NOT work.
Writing your own indexer to control the stock indexer that fixes all of it DOES NOT work.
Magento2 is bugridden garbage, it takes 4x as long to achieve anything in it than our last store and bugs are constant and hard to fix.

Attempting to rip out the indexer itself at this point. Never will I suggest m2 to anyone, it's been 3 years of hell.

All 18 comments

We have a problem in our shop which might be the same issue. Once in a while products seem to disappear from the cataloginventory_stock_status table.
I have set up monitoring to check whether all enabled products have a corresponding entry in that index table. This is usually the case, but sometimes I get alerts that a number of products have disappeared from that table. And it doesn't seem to be temporary. The products only reappear in that table after a manual reindex.

So far I haven't been able to find out what circumstances will trigger this disappearing of products, although I have an unconfirmed suspicion that it has something to do with large number of products being reindex via the mview scheduled indexer.

Hi @AF4Q I cannot reproduce by your scenarious steps in clean magento , can you provide more information ?

I resolved the problem, you need to set settings for indexer on save action System->Index manager chose checkbox stock -> set to -> update on save. In my case that work

@AF4Q seems like duplicate to this -> https://github.com/magento/magento2/issues/15939

@engcom-backlog-nazar While changing the index to "UPDATE ON SAVE" may work around the issue, Magento actually recommends using the "UPDATE BY SCHEDULE" option for production environments. Here's a quote from a Magento Support ticket where I asked for Magento's official stance on this:

When in production we always recommend UPDATE BY SCHEDULED, when in development then UPDATE ON SAVE. UPDATE BY SCHEDULE uses the crontab to run magento cron jobs which causes the indexers to run more efficiently while the store is open. So, always UPDATE BY SCHEDULE when in production but remember that means the cron tab needs to be set to run the Magento cron jobs.

@AF4Q Is your "Stock" index set to "UPDATE ON SAVE" or "UPDATE BY SCHEDULE" when you're experiencing this?

HI @AF4Q I checked this, the indexer oh state "UPDATE BY SCHEDULE" must be update partial and product may be changed. thank you for you report We've acknowledged the issue and added to our backlog.

My indexer is set to UPDATE BY SCHEDULE and in the admin panel it shows that all indexes are valid. But still this issue persists. Upon running a manual index by SSH fixes the issue.

code/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php : _updateIndex
$this->deleteOldRecords($entityIds) should be before $this->_updateIndexTable($data) where update by bunch and select "while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {"

The magento developers forget about bunch update by 1000 thus it's insert update to table and after it clean the data in the cataloginventory_stock_status

Closing this issue 鈥斅燼 fix for this has been applied and is available in v2.2.5

The fix for this can be located in https://github.com/magento/magento2/issues/12205

Actually.. sorry, re-opening..

@engcom-backlog-nazar 鈥斅爄s this something we could backport to affected versions?

@matthew-muscat Close this is as duplicate to https://github.com/magento/magento2/issues/15939

Hi, I am running Magento v2.2.5 but i am still experiencing the exact same issue that the product doesn't appear under the category until manual re-index is run.

Whereas it appears straight away in the search (we are using klevu).

Can anyone pass a reference form the Magento docs that refer this issue being included. I can't find it in any of the Magento release notes.

code/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php : _updateIndex
$this->deleteOldRecords($entityIds) should be before $this->_updateIndexTable($data) where update by bunch and select "while ($row = $query->fetch(\PDO::FETCH_ASSOC)) {"

The magento developers forget about bunch update by 1000 thus it's insert update to table and after it clean the data in the cataloginventory_stock_status

I need help on this! Magento 2.3.1 here. After SKU 1000 skus magento updates the stock only for the next skus ignoring the first 1000. On 1160 sku i have salable quantity stock only for the last 160.

Still an in issue in 2.3.3, this issue alone has at this point cost my client tens of thousands of dollars.
Update on save DOES NOT work.
Writing your own indexer to control the stock indexer that fixes all of it DOES NOT work.
Magento2 is bugridden garbage, it takes 4x as long to achieve anything in it than our last store and bugs are constant and hard to fix.

Attempting to rip out the indexer itself at this point. Never will I suggest m2 to anyone, it's been 3 years of hell.

As @Clud7 explained, this problem occurs when at least 1000 products of the same type are being reindex.
This problem will not be visible unless you have enough products. Here is an easy way to reproduce:

  • Set cataloginventory_stock index to mode scheduled
  • Simulate products getting changed:
    INSERT INTO cataloginventory_stock_cl(entity_id) SELECT a.entity_id FROM catalog_product_entity a INNER JOIN cataloginventory_stock_status b ON a.entity_id=b.product_id AND b.website_id=0 WHERE a.type_id='simple'
  • Run cron:run and wait until index turns green index:status

Now go to Gear->Bags for example and see no products. Stock index contains only around 1000 products instead of 2000.

The problem is here, when 1000 products are processed they are updated and at the end of the loop all products are deleted.

Let's reopen this one based on the last comments and on https://github.com/magento/magento2/issues/12205#issuecomment-524744517, maybe somebody from Magento can try to reproduce this.

Would it be enough to forward port https://github.com/magento/magento2/commit/20d7afbe75fed9b8f45e3231848aae40b1c06a3a to 2.3-develop?

@domeglic: thanks for listing those steps to reproduce, that was really helpful!

I was able to reproduce this problem and forward ported 20d7afb in this new PR to 2.3-develop.
This seems to fix the problem!

Hi @AF4Q. Thank you for your report.
The issue has been fixed in magento/magento2#25306 by @hostep in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.5 release.

Was this page helpful?
0 / 5 - 0 ratings