5

I added a new attribute on order entity :

$salesSetup->addAttribute(Order::ENTITY, "shipping_date", [
    'type'     => "date",
    'label'    => "Shipping date",
    'input'    => "text",
    'user_defined' => true,
    'required' => false,
    'visible' => true
  ]);

and display it on the sales order grid

view/adminhtml/uicomponent/sales_order_grid.xml

:

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_columns">
    <column name="shipping_date">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Shipping Date</item>
            </item>
        </argument>
    </column>
</columns>

And when I'm saving a new order I would like to populate the sales_order_grid so I added this code in

etc/adminhtml/di.xml:

<virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid">
    <arguments>
        <argument name="columns" xsi:type="array">
            <item name="shipping_date" xsi:type="string">sales_order.shipping_date</item>
        </argument>
    </arguments>
</virtualType>

The issue is when I'm saving the order it creates a blank line in sales_order_grid table with only the shipping date filled, all other fields are NULL, where is my mistake ?

2
  • I followed this way, but all the value are updating to the sales_order_grid table except the custom column value. is there any other code is missing?
    – senthil
    Commented Oct 10, 2018 at 10:40
  • Also when i add the above virtualtype my page will be blank
    – senthil
    Commented Oct 10, 2018 at 10:56

1 Answer 1

2

I think it's because you forget to add the type on your virtualType in di.xml
Update your virtualType like this :

<virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
    <arguments>
        <argument name="columns" xsi:type="array">
            <item name="shipping_date" xsi:type="string">sales_order.shipping_date</item>
        </argument>
    </arguments>
</virtualType>
1
  • how to insert custom value on sales_order_grid during this insertion? Commented Jan 14, 2022 at 14:54

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.