inventory icon indicating copy to clipboard operation
inventory copied to clipboard

Stock status and saleable qty is not update when updating a product with qty 0

Open codebase-md opened this issue 2 years ago • 2 comments

Preconditions (*)

  1. Magento Inventory 1.2.3(most recent versions seem to contain the same logic as well)
  2. No Backorders enabled

Steps to reproduce (*)

  1. Update a product with qty = 0 and stock_status 'out of stock'

Expected result (*)

  1. Stock status should switch to 'in stock' and saleable qty should be equal to qty

Actual result (*)

  1. Stock status is not updated and saleable qty stays 0

Additional Information

I debugged the whole process and found following:

Order of execution

  1. \Magento\Inventory\Model\SourceItem\Command\SourceItemsSave::execute
  2. \Magento\InventoryCatalog\Plugin\InventoryApi\SetDataToLegacyCatalogInventoryAtSourceItemsSavePlugin::afterExecute
  3. \Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory::execute
  4. \Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory::updateSourceItems
  5. \Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory::getStockStatuses (here the problem starts)
  6. \Magento\InventorySales\Model\AreProductsSalable::execute
  7. \Magento\InventoryIndexer\Model\IsProductSalable::execute
  8. \Magento\InventoryIndexer\Model\ResourceModel\GetStockItemDataCache::execute
  9. \Magento\InventoryIndexer\Model\ResourceModel\GetStockItemData::execute

In step 4 (\Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory::updateSourceItems) the stock status is fetched from the exact same table that this function tries to update(cataloginventory_stock_status) if the stock id is equal to the default stock id. Hence the old value is reused when executing the status update on line 205(\Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory)

codebase-md avatar Nov 11 '22 13:11 codebase-md

Hi @codebase-md. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Nov 11 '22 13:11 m2-assistant[bot]