cancel
Showing results for 
Search instead for 
Did you mean: 

sales_order_save_after observer isn't run after placing order by rest api ?

sales_order_save_after observer isn't run after placing order by rest api ?

an observer sales_order_save_after to send SMS after placing an order has been working from luma front end but when I placing an order by rest API call the observer didn't run !

any help ?

 

4 REPLIES 4

Re: sales_order_save_after observer isn't run after placing order by rest api ?

@emanmohameda68 

Please use the below plugin:

checkout_submit_all_after
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: sales_order_save_after observer isn't run after placing order by rest api ?

@Sanjay Jethva  any help in 

How can I use plugin checkout_submit_all_after 

I'm new in Magento 2 

Re: sales_order_save_after observer isn't run after placing order by rest api ?

 

@emanmohameda68 

The below blog can be helpful to you:

https://meetanshi.com/blog/create-new-observer-on-trigger-of-magento-2-event-catalog_product_save_be...

 

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: sales_order_save_after observer isn't run after placing order by rest api ?

If the Observer is not been triggered, Make Sure that you are Declaring the Observer in Appropriate Scope.

In Magento Make your observer as specific as it needs to be. Declare your observer in the appropriate area :

global<module-dir>/etc/events.xmlObserver will be executed in all areas: adminhtml, crontab, frontend, graphql, webapi_rest, webapi_soap.
adminhtml<module-dir>/etc/adminhtml/events.xmlObserver will be executed in the adminhtml area only.
crontab<module-dir>/etc/crontab/events.xmlObserver will be executed in the crontab area only.
frontend<module-dir>/etc/frontend/events.xmlObserver will be executed in the frontend area only.
graphql<module-dir>/etc/graphql/events.xmlObserver will be executed in the graphql area only.
webapi_rest<module-dir>/etc/webapi_rest/events.xmlObserver will be executed in the webapi_rest area only.
webapi_soap<module-dir>/etc/webapi_soap/events.xmlObserver will be executed in the webapi_soap area only.


You can Use the Observer :
sales_model_service_quote_submit_success event.
<magento-root>/app/code/Vendor/ModuleName/etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_model_service_quote_submit_success">
        <observer name="vendor_modulename_order_save_quote" instance="Vendor\ModuleName\Observer\Order\SaveQuote" />
    </event>
</config>

<magento-root>/app/code/Vendor/ModuleName/Observer/Order/SaveQuote.php

<?php
namespace Vendor\ModuleName\Observer\Order;

use Magento\Framework\Event\ObserverInterface;

class SaveQuote implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        try {
            $quote = $observer->getEvent()->getData('quote');
            // Your Code
        } catch (\Exception $e) {
            // Silence
        }
    }
}

Problem Solved !!
Click on 'Kudos' & Accept as Solution to encourage to write more answers !