A product showed “In Stock” on the product page despite actually being out of stock. Customers placed orders for a product that could not be fulfilled. The error only appeared when creating a shipment. The problem affected configurable products with MSI. Fix time: 4 hours.
Symptoms
- Configurable product shows “In Stock” with qty = 0 in admin panel
- Customers can add to cart and place an order
- Error when creating shipment: “Not enough qty available”
- In
cataloginventory_stock_item: qty = 0, is_in_stock = 1 - In
inventory_source_item: quantity = 0, status = 1
Cause
A product import was updating the old cataloginventory_stock_item table but not the MSI tables (inventory_source_item). After migrating to MSI, the old stock API is just an alias – the real data is in inventory_* tables.
Solution
<?php
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
class StockUpdater
{
public function __construct(
private SourceItemsSaveInterface $sourceItemsSave,
private SourceItemInterfaceFactory $sourceItemFactory,
) {}
public function update(array $items): void
{
$sourceItems = [];
foreach ($items as $item) {
$sourceItem = $this->sourceItemFactory->create();
$sourceItem->setSku($item['sku']);
$sourceItem->setSourceCode($item['source'] ?? 'default');
$sourceItem->setQuantity($item['qty']);
$sourceItem->setStatus($item['qty'] > 0 ? 1 : 0);
$sourceItems[] = $sourceItem;
}
$this->sourceItemsSave->execute($sourceItems);
}
}
bin/magento indexer:reindex cataloginventory_stock inventory bin/magento inventory:reservation:list-inconsistencies bin/magento inventory:reservation:create-compensations
Takeaways
After enabling MSI all stock operations must use the InventoryApi – not the old cataloginventory. The old interface works as a wrapper but only for the default source. Custom importers and ERP integrations require updating to the new MSI API.
