1

I have got an issue of "Stock Item with id "x" does not exist" because of this some product have didn't display price and options in product detail page.

Have any solution?

1 Answer 1

1

Basically I am not getting your questions. But primarily, it looks like you need stock details.

So, for that, you can follow the below approach

/** @var \Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory **/
        $criteria = $stockStatusCriteriaFactory->create();
        $criteria->setProductsFilter($productId);
        /** @var \Magento\CatalogInventory\Api\Data\StockStatusRepositoryInterface $stockStatusRepository **/
        $result = $stockStatusRepository->getList($criteria);
        $stockStatus = current($result->getItems());
        $stockStatus->getProductId();                 // product id
        $stockStatus->getQty();   // quantity of specified product
        $stockStatus->getStockStatus();     // Could be 
// Magento\CatalogInventory\Model\Stock\Status::STATUS_OUT_OF_STOCK = 0;
// or
// Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK = 1;

Credits: https://github.com/magento/magento2/issues/7057#issuecomment-256052729

1
  • Thank you for sharing this, this allows you to get and set stock status for non simple products as well - other methods you can't without an error about how qty records can't be found
    – John
    Commented Sep 7, 2022 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.