0

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???

  • Do you call the save() method when trying to save ? – Raphael at Digital Pianism Apr 25 '16 at 12:16
  • yes, I did but no luck.. as I told you its saving in sales_order table but in sales_order_grid table its not, where column name is same in the both table.. Am i taking wrong event ($observer->getEvent()->getOrder()) ??? – Mohammad Mujassam Apr 25 '16 at 12:40
4

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

  • Thanks a lot @Sohel Rana, I spend so much time to achieve this, you saved my time, thanks again.. However, I used different event (sales_order_place_after) – Mohammad Mujassam Apr 27 '16 at 12:03
  • I have found you must run bin/magento setup:di:compile afterwards, then it starts to populate the grid column from the source table on insert/update. – Omer Sabic Nov 24 '17 at 10:38
  • Sir how can custom value save in custom_column in sales_order_grid table without populate from sales_order to sales_order_grid like your answer because my values are not in sales_order table ? i am using observer sales_model_service_quote_submit_before and now want to save value using model or have service contract for sales_order_grid ? – HaFiz Umer Oct 2 at 8:04

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.