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 ?
Please use the below plugin:
checkout_submit_all_after
The below blog can be helpful to you:
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.xml | Observer will be executed in all areas: adminhtml, crontab, frontend, graphql, webapi_rest, webapi_soap. |
adminhtml | <module-dir>/etc/adminhtml/events.xml | Observer will be executed in the adminhtml area only. |
crontab | <module-dir>/etc/crontab/events.xml | Observer will be executed in the crontab area only. |
frontend | <module-dir>/etc/frontend/events.xml | Observer will be executed in the frontend area only. |
graphql | <module-dir>/etc/graphql/events.xml | Observer will be executed in the graphql area only. |
webapi_rest | <module-dir>/etc/webapi_rest/events.xml | Observer will be executed in the webapi_rest area only. |
webapi_soap | <module-dir>/etc/webapi_soap/events.xml | Observer 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 !