I need to decrease purchased item saleable quantity with custom value (x* ordered_qty) after place order in Magento 2.Right now I'm using the following observer and class to update the quantity of purchased items.
Event Xml
<event name="sales_order_place_after">
<observer name="Update_customstock" instance="Company\MyMoudle\Observer\UpdateStock" />
</event>
Observer Class
class UpdateStock implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$orderData = $observer->getEvent()->getOrder();
$orderItems = $orderData->getAllVisibleItems();
foreach($orderItems as $item) {
if($flag_variable) {
$stockItem->setIsInStock(true);
$stockItem->setQty($new_qty);
$this->stockRegistry->updateStockItemBySku($item->getSku(), $stockItem);
}
}
}
}
Issue
But it's deceasing salable quantity double of my sent value and quantity also updating as sent value.
What I need
I need if the order is placed then only the decrease the salable quantity and once the shipment is created then decrease the quantity.
Please suggest any solution with a plugin or observer.