Add a product into the cart – message “There are no source items with the in-stock status
A Bug story : I have faced an issue on my customer website that a few products can not be added into a cart. An error message I got is ” There are no source items with the in-stock status”. I tried to deeply debug ( see the steps below ) and realized this SQL return empty result.
A strange thing, everything in the backend shows that the product has qty of 2 and in-stock status. Then I go to MySQLAdmin to find a record relate to the product SKU from table “inventory_source_item”. It shows me a record with qty = 0 and status = 0.
I’m sure we have done reindex a thousand times. I tried to save the product again from the backend. And then, what amazing !!!, it works and qty and stock status are updated correctly on table “inventory_source_item” for the product.
I think the problem happened because we did migrate data from Magento 1 to Magento 2.
Here is quick fixing for this issue for every product without saving each product on the backend.
NOTE !!! In-case: You have only stock source: “default “
- Backup table inventory_source_item
- Truncate table inventory_source_item
Debug:
Magento\InventorySales\Model\IsProductSalableForRequestedQtyCondition\\IsAnySourceItemInStockCondition
public function execute(string $sku, int $stockId, float $requestedQty): ProductSalableResultInterface
{
$errors = [];
if (!$this->isAnySourceInStockCondition->execute($sku, $stockId)) {
$data = [
'code' => 'is_any_source_item_in_stock-no_source_items_in_stock',
'message' => __('There are no source items with the in stock status')
];
$errors[] = $this->productSalabilityErrorFactory->create($data);
}
return $this->productSalableResultFactory->create(['errors' => $errors]);
}