1

I have use event checkout_submit_all_after and sales_order table field test_field.

class SalesOrderPlaceAfter implements ObserverInterface
    {
        public function execute(\Magento\Framework\Event\Observer $observer)
        {
            $order = $observer->getEvent()->getOrder();
            $order->setTestField(12);
            $order->save();   
        }
    }

TestField in not save value.how does it save?

1

Finally Find answer Use sales_model_service_quote_submit_before event..

namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class SalesOrderPlaceAfter implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        try {
            $order = $observer->getEvent()->getOrder();
            $order->setTestField(10);
        } catch (\Exception $e) {
            error_log($e->getMessage());
        }
    }
}
3
  • But i need to update value in sales_order_grid table
    – Sourav
    Dec 13 '18 at 6:52
  • do we have to create field to store value? or it will create when its run first time? Jan 6 '20 at 10:39
  • Need to create a field in quote and order table then etc.xml in define copy field value Jan 6 '20 at 12:51
0

Try following way


namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class SalesOrderPlaceAfter implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        try {
            $order = $observer->getEvent()->getOrder();
            $order->setTestField(177);
            $order->save();
        } catch (\Exception $e) {
            error_log($e->getMessage());
        }
    }
}

Clear cache.

[Update]

Vendor/Modue/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="custom_checkout_submit_all_after" instance="Vendor\Modue\Observer\SalesOrderPlaceAfter" />
    </event>
</config>
16
  • I have already check with it..but not working..any another way? @ sohel Jun 11 '17 at 8:34
  • It's working fine here. Did you clear cache?
    – Sohel Rana
    Jun 11 '17 at 8:43
  • yes.. but it's not working yet. Jun 11 '17 at 8:49
  • Can you post your event.xml? Something wrong here may be.
    – Sohel Rana
    Jun 11 '17 at 9:01
  • <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="checkout_submit_all_after"> <observer name="btn_checkout_submit_all_after" instance="Test\Demo\Observer\SalesOrderPlaceAfter"/> </event> </config> Jun 11 '17 at 9:02

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.