Magento – main.CRITICAL: The stock item with the “37520” ID wasn’t found. Verify the ID and try again. System.log – M2 2.3.3

magento2

We get a lot of this type of notice in our system.log, but can't see what is causing this critical notice.

Framework: Magento M2 2.3.3

Have anyone seen this before ?

[2019-11-14 14:00:08] main.CRITICAL: The stock item with the "37520" ID wasn't found. Verify the ID and try again. [] []
[2019-11-14 14:00:13] main.CRITICAL: The stock item with the "39393" ID wasn't found. Verify the ID and try again. [] []
[2019-11-14 14:00:14] main.CRITICAL: The stock item with the "5610" ID wasn't found. Verify the ID and try again. [] []
[2019-11-14 14:00:19] main.CRITICAL: The stock item with the "10691" ID wasn't found. Verify the ID and try again. [] []
[2019-11-14 14:00:20] main.CRITICAL: The stock item with the "20589" ID wasn't found. Verify the ID and try again. [] []
[2019-11-14 14:00:22] main.CRITICAL: The stock item with the "47337" ID wasn't found. Verify the ID and try again. [] []
[2019-11-14 14:00:30] main.CRITICAL: The stock item with the "13366" ID wasn't found. Verify the ID and try again. [] []

Hi, check my response. Mark question as answered, if it works for you.

Best Answer

I had the same problem. Following the solution by @hitesh-kashyap, I was able to modify the the following code.

Problem: When the BuildProductRequest function is called in the ProductFeed class it creates a StockItemRepository object. If the product is a new product an exception is thrown because the newly created product does not have a record on the cataloginventory_stock_item table yet.

Solution: Add a try catch section to Facebook/BusinessExtension/Model/Feed/ProductFeed.php

  1. Replace
$stock = $this->_fbeHelper->createObject(StockItemRepository::class)->get($product->getId());

With

   $productQty = 0;
   $productIsInStock = 0;

   try {
           $stock = $product->getExtensionAttributes()->getStockItem();
           if($stock){
                   $productQty = $stock->getQty();
                   $productIsInStock = $stock->getIsInStock();
           }
   } catch (Exception $e) {}
  1. Replace
       self::ATTR_AVAILABILITY => $this->buildProductAttr(self::ATTR_AVAILABILITY, $stock->getIsInStock() ? 'in stock' : 'out of stock'),

with

       self::ATTR_AVAILABILITY => $this->buildProductAttr(self::ATTR_AVAILABILITY, $productIsInStock ? 'in stock' : 'out of stock'),
  1. Replace
       'inventory' => $stock->getIsInStock(),

With

       'inventory' => $productQty,

Finally, save the file.

Limitations, at the time you create a product the stock information will be 0 and out of stock. You will need to save the product a second time to update the stock information on Facebook.

Tested on Magento 2.3

Related Topic