inventory
inventory copied to clipboard
Stock status and saleable qty is not update when updating a product with qty 0
Preconditions (*)
- Magento Inventory 1.2.3(most recent versions seem to contain the same logic as well)
- No Backorders enabled
Steps to reproduce (*)
- Update a product with qty = 0 and stock_status 'out of stock'
Expected result (*)
- Stock status should switch to 'in stock' and saleable qty should be equal to qty
Actual result (*)
- Stock status is not updated and saleable qty stays 0
Additional Information
I debugged the whole process and found following:
Order of execution
- \Magento\Inventory\Model\SourceItem\Command\SourceItemsSave::execute
- \Magento\InventoryCatalog\Plugin\InventoryApi\SetDataToLegacyCatalogInventoryAtSourceItemsSavePlugin::afterExecute
- \Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory::execute
- \Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory::updateSourceItems
- \Magento\InventoryCatalog\Model\SourceItemsSaveSynchronization\SetDataToLegacyCatalogInventory::getStockStatuses (here the problem starts)
- \Magento\InventorySales\Model\AreProductsSalable::execute
- \Magento\InventoryIndexer\Model\IsProductSalable::execute
- \Magento\InventoryIndexer\Model\ResourceModel\GetStockItemDataCache::execute
- \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)
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
- Join Magento Community Engineering Slack and ask your questions in #github channel.