Magento 2 post data inside observer after checkout_submit_all_after event not working

Trying to get the custom sales attribute post value inside observer called on checkout_submit_all_after event but unable to get that.

The name of the input field is custom_abc Below is the piece of code.

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="abc_customorderfields_sales_order_save_after" instance="Abc\CustomOrderFields\Observer\SalesOrderPlaceAfter" /> </event> </config>`

Observer

namespace Abc\CustomOrderFields\Observer; /** * Class SalesOrderPlaceAfter */ class SalesOrderPlaceAfter implements \Magento\Framework\Event\ObserverInterface { protected $_request; protected $_logger; protected $_historyFactory; protected $_orderFactory; public function __construct( \Magento\Framework\App\RequestInterface $request, \Psr\Log\LoggerInterface $logger, \Magento\Sales\Model\Order\Status\HistoryFactory $historyFactory, \Magento\Sales\Model\OrderFactory $orderFactory ) { $this->_request = $request; $this->_logger = $logger; $this->_historyFactory = $historyFactory; $this->_orderFactory = $orderFactory; } public function execute(\Magento\Framework\Event\Observer $observer) { try { $order = $observer->getEvent()->getOrder(); if ($order) { $postValue = $this->_request->getPost('custom_abc'); $order->setCustomAbc($postValue)->save(); } return $this; } catch (\Exception $e) { error_log($e->getMessage()); } } }

please help me out. Thanks in advance!!

Read Entire Article