Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
codebase-md opened this issue Nov 11, 2022 · 1 comment

Comments

@codebase-md
Copy link

codebase-md commented Nov 11, 2022

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
Copy link

m2-assistant bot commented Nov 11, 2022

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Backlog
  
Ready for Grooming
Development

No branches or pull requests

1 participant