magento / inventory

Magento Inventory Project (a.k.a MSI)
Open Software License 3.0
339 stars 248 forks source link

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

Open codebase-md opened 2 years ago

codebase-md commented 2 years ago

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)

m2-assistant[bot] commented 2 years ago

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


kulwinders433 commented 2 months ago

Can you please assign this ticket to me I will work on it? Thanks @magento I am working on this