1

I want to know which event is used for firing when an order successfully placed by the admin.

Right know i am using an event sales_order_save_commit_after. The problem her i am facing is that while i place an order using a card and the card was not valid or something happened at gateway which resulted in cancel of order. Even if the order is cancel my code still run which shouldn't happen.

So which is the best event for Admin orders in this type of cases.

2 Answers 2

2

You can create events.xml file here and you can use checkout_submit_all_after event there.

app/code/Vendor/Module/etc/adminhtml/events.xml

Content for this file is..

<?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="checkout_submit_all_after">
        <observer name="admin_order_place_after" instance="Vendor\Module\Observer\AdminOrderPlaceAfter" />
    </event>
</config>

Now you need to create one Observer file here

app/code/Vendor/Module/Observer/AdminOrderPlaceAfter.php

<?php
namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer;

class AdminOrderPlaceAfter implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(Observer $observer){
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/observer.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info('Backend order placed successfully.');
    }
}

This event will work when order successfully placed from Backend.

Hope this will help you!

5
  • Let me know if it helps. Thanks. Nov 27, 2019 at 12:06
  • Please explain what is the flow of checkout_submit_all_after
    – Avesh Naik
    Nov 27, 2019 at 13:12
  • checkout_submit_all_after event call once your order successfully placed and committed all changed in Database that is related to order. you can check this file vendor/magento/module-checkout/Model/Type/Onepage.php check saveOrder() function there in last this event is available. Nov 27, 2019 at 13:16
  • In last this event is called when you place any order. Nov 27, 2019 at 13:16
  • it helps to resolve this Nov 27, 2019 at 14:12
0

You have to add below file in your custom extension

app/code/Vendor/Extension/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="checkout_submit_all_after">
            <observer name="sales_order_save_after" instance="Vendor\Extension\Observer\OrderSaveObserver" />
        </event> 
</config>

app\code\Vendor\Extension\Observer\OrderSaveObserver.php

<?php
namespace Vendor\Extension\Observer;
use Magento\Framework\Event\ObserverInterface;
class OrderSaveObserver implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
        /*
            Write your code here
        */
    }
}

You have to access all data from $order object.

Hope This Will Help You !!!

1
  • Please explain what is the flow of checkout_submit_all_after
    – Avesh Naik
    Nov 27, 2019 at 13:12

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.