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" />

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) {
               $this->stockRegistry->updateStockItemBySku($item->getSku(), $stockItem);



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.

  • Your code is not working for me. Order is not placing. – Kowsigan Atsayam Feb 13 '20 at 10:30
  • Please check your logs file and share the error message with me, – Ashvini Marwal Feb 13 '20 at 14:53

Use the following event global scope. Ex. VendorName/ModuleName/etc/events.xml


For Paypal payment method, use the following:

  • my mentioned event is working but as the explained issue is in salable qunitiy and product quntity value issue – Ashvini Marwal Nov 29 '19 at 9:48
  • Don't use sales_order_place_after event, this event will call every time when order will save. Ex. $order->save(). If you want something after the order place then use the above event that I answer. – Sohel Rana Nov 29 '19 at 10:15
  • Using your event getting the same issue.example SKU with qty 100 and 100 salable qty.i ordered 1 qty and stock effected as qty 99 and 98 saleable qty. I think my code is updating qty instead of salable qty.any idea? – Ashvini Marwal Nov 29 '19 at 11:03
  • you got any solution? – Kowsigan Atsayam Feb 12 '20 at 15:01
  • I am also facing same issue. Did you got any solution? Please share it here. – Kowsigan Atsayam Feb 19 '20 at 11:06

Just go to Catalog -> inventory on the store configuration in the back end.

In the stock options, select No to Decrease Stock When Order is Placed. Then you will get what you needed.

  • I used a module from github.com/bharat2762/magento2-admin-low-stock-notification to send a notification mail to the admin when any product stock quantity below 20,10,5. Also, I need additional customization to send a notification mail for out of stock product to the admin. If you have any idea can you please share your thoughts – Divya Sekar Sep 8 '20 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.