cancel
Showing results for 
Search instead for 
Did you mean: 

Product Quantity is not updating first time

Product Quantity is not updating first time

We have a plugin for Key deliveries which also updates the inventory stock item based on the keys availability. Now from Magento 2.3 on wards if we create new product with manual quantity (ie: 1000) the quantity we enter there is updating instead of the quantity of available keys. But by clicking the save button again it turns to the quantity based on the Key availability. Seems lke a bug as it was working good till Magento 2.x.

Below code is what I am using from observer file.

$stockItem = $this->stockRegistry->getStockItemBySku($sku);
$stockItem->setQty($availableKeys);
$stockItem->setIsInStock((bool) $availableKeys);
$this->stockRegistry->updateStockItemBySku($sku, $stockItem);

 

If I observe correctly it is happening after when Magento introduced 'Salable Quantity' feature.