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?

2 Answers 2

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
    Commented Dec 13, 2018 at 6:52
  • do we have to create field to store value? or it will create when its run first time? Commented Jan 6, 2020 at 10:39
  • Need to create a field in quote and order table then etc.xml in define copy field value Commented Jan 6, 2020 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 Commented Jun 11, 2017 at 8:34
  • It's working fine here. Did you clear cache?
    – Sohel Rana
    Commented Jun 11, 2017 at 8:43
  • yes.. but it's not working yet. Commented Jun 11, 2017 at 8:49
  • Can you post your event.xml? Something wrong here may be.
    – Sohel Rana
    Commented Jun 11, 2017 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> Commented Jun 11, 2017 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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