1

I have to save value in custom_attribute(current_seller_id) in "sales_order" table. using event below code But now i want to save same value in custom_attribute(current_seller_id) of "sale_order_grid" table. am new in magento guide me which observer or anything used for copy data from sales_order table to sales_order_grid.


  public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getData('order');
        $quote = $observer->getData('quote');

       // $cartdata=$this->cart->getQuote()->getItemsCollection();
        $quoteItems = $quote->getItems();
        foreach ($quoteItems as $quoteItem){
            if ($quoteItem->getCurrentSellerId() != ""){
                $items[]=$quoteItem->getCurrentSellerId();
            }
        }
        $seller_ids=implode(',',$items);
        $order->setCurrentSellerId($seller_ids);
        return $this;
    }

1 Answer 1

4

Try following way will copy data automatically when saving sales_order table:

VendorName\ModuleName\etc\di.xml


<?xml version="1.0"?>

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

More details check this free module

1
  • Then accept answer, it will help others .
    – Sohel Rana
    Commented Feb 19, 2019 at 18:40

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.