PHP / Magento Dev Blog

  • Home

Magento 2 product shows “In Stock” with qty=0 – MSI and legacy stock inconsistency

by Henryk Tews / Wednesday, 02 September 2026 / Published in Magento / Adobe Commerce

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.

About Henryk Tews

What you can read next

Xdebug – configuration, PHPStorm, debugging Magento plugins
Strategy pattern in PHP – and how Magento 2 uses it in pricing

© 2026 Created by

TOP
Zarządzaj zgodą
Aby zapewnić jak najlepsze wrażenia, korzystamy z technologii, takich jak pliki cookie, do przechowywania i/lub uzyskiwania dostępu do informacji o urządzeniu. Zgoda na te technologie pozwoli nam przetwarzać dane, takie jak zachowanie podczas przeglądania lub unikalne identyfikatory na tej stronie. Brak wyrażenia zgody lub wycofanie zgody może niekorzystnie wpłynąć na niektóre cechy i funkcje.
Funkcjonalne Always active
Przechowywanie lub dostęp do danych technicznych jest ściśle konieczny do uzasadnionego celu umożliwienia korzystania z konkretnej usługi wyraźnie żądanej przez subskrybenta lub użytkownika, lub wyłącznie w celu przeprowadzenia transmisji komunikatu przez sieć łączności elektronicznej.
Preferencje
Przechowywanie lub dostęp techniczny jest niezbędny do uzasadnionego celu przechowywania preferencji, o które nie prosi subskrybent lub użytkownik.
Statystyka
Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do celów statystycznych. Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do anonimowych celów statystycznych. Bez wezwania do sądu, dobrowolnego podporządkowania się dostawcy usług internetowych lub dodatkowych zapisów od strony trzeciej, informacje przechowywane lub pobierane wyłącznie w tym celu zwykle nie mogą być wykorzystywane do identyfikacji użytkownika.
Marketing
Przechowywanie lub dostęp techniczny jest wymagany do tworzenia profili użytkowników w celu wysyłania reklam lub śledzenia użytkownika na stronie internetowej lub na kilku stronach internetowych w podobnych celach marketingowych.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Zobacz preferencje
  • {title}
  • {title}
  • {title}