Magento2 Sales Order Grid – Unable to Save Data in Newly Added Column of Sales_Order_Grid Table

magento-2.0magento2sales-order

trying to save the my oven data in newly added column of sales_order_grid but unable to to do so.

However, I can save my custom the data in sales_order table where I have added one extra column.
I am adding the data in sales_order table by getting below observer event.

$obj = $observer->getEvent()->getOrder();
$obj->setMyName($value);

same data is not saving in sales_order_grid table having same column name..

is there there anyway or anything alternative to achieve this???

Best Answer

Suppose column name 'delivery_date, So that you need to add di.xml for save some value for custom column to grid

Vendor/Module/etc/di.xml


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="delivery_date" xsi:type="string">sales_order.delivery_date</item>
            </argument>
        </arguments>
    </virtualType>
</config>

Here is an example

Related Topic