I have create a custom field(zipcode) in sales_order and sales_order_grid, after that i try to save to database while click placeorder the order in frontend,so try to use checkout_submit_all_after
event, But its not save my custom field value.
what i did:
vendor/module/etc/frontend/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\Module\Observer\SalesOrderPlaceAfter"
/>
</event>
</config>
Then create a Observer to to save Custom Field Value.
vendor/module/Observer/SalesOrderPlaceAfter.php:
use Magento\Framework\Event\ObserverInterface;
class SalesOrderPlaceAfter implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
try {
$order = $observer->getEvent()->getOrder();
$order->setZipcode("604503");
$order->save();
} catch (\Exception $e) {
error_log($e->getMessage());
}
}
}
But its have save My custom Field value, Suggest me How to fix this.
events.xml
tovendor\module\etc\events.xml
.