0

I have added custom column in sales_order_grid table and values are showing in backend but how to update that column's value if customer has edited it from frontend order view? Anyone please help!

installer code

$setup->getConnection()
    ->addColumn(
        $setup->getTable($ordergridTable),
        'custom_column',
        [
            'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
            'unsigned'  => true,
            'nullable'  => false,
            'default'   => '0',
            'comment' =>'Custom column'
        ]
    );

    $setup->getConnection()->addIndex(
    $setup->getTable($ordergridTable),
    $setup->getConnection()->getIndexName(
    $setup->getTable($ordergridTable),
    ['custom_column']
    ),
    ['custom_column']
    );

Below is code from my model where i am saving it in sales_order table:

public function setFav($order,$orderId,$favId)
{

    $order = $order->create();
    $order->load($orderId);
    if($favId==0){
       $order->setCustomColumn(1);
    }else{
       $order->setCustomColumn(0);
    }
    $order->save();
}

It is saving in sales_order table but need to save/update in sales_order_grid at same time. Thanks

  • Can you tell me how you can add that column and also share code to save value into this field. – Dhiren Vasoya May 3 '17 at 10:34
  • Please check updated post – Keith May 3 '17 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.