Magento – Magento 1.9 : sales_flat_order and sales_flat_order_grid tables are not updating

magento-1.9sales-ordersales-order-grid

I used many update methods for update values in sales_flat_order and sales_flat_order_grid tables, but no method didn't work.

I don't know why the update is not done.

Method 1:-

$coreResource = Mage::getSingleton('core/resource');
$write = $coreResource->getConnection('core_write');
        $_field_flat_order =array();
        $_field_flat_order['grand_total']          = $order_gt;
        $_field_flat_order['base_grand_total']     = $order_gt;
        $_field_flat_order['discount_amount']      = $order_discount;
        $_field_flat_order['base_discount_amount'] = $order_discount;
        $_field_flat_order['discount_description'] = "1%";
        $write->update($coreResource->getTableName('sales_flat_order'),$_field_flat_order,array('entity_id = ?' => $order_id,));

Method 2:-

$order_data=Mage::getModel('sales/order')->loadByIncrementId($increment_id);
        $order_data->setGrandTotal($order_gt);
        $order_data->setBaseGrandTotal($order_gt);
        $order_data->setBaseDiscountAmount($order_discount);
        $order_data->setDiscountAmount($order_discount);
        $order_data->setDiscountDescription("1%");
        $order_data->save();

Method 3 :-

$sql_order = "UPDATE sales_flat_order SET grand_total='".$order_gt."',base_grand_total='".$order_gt."',discount_amount='".$order_discount."',base_discount_amount='".$order_discount."',discount_description='1%' WHERE entity_id ='".$order_id."'";
$write->query($sql_order);

No method didn't work, but all other tables are updating perfectly.

Anyone know the reason.?

Best Answer

Try:

<?php $write = Mage::getSingleton('core/resource')->getConnection('core_write'); ?>

And:

<?php
$write->query("UPDATE sales_flat_order SET grand_total = '$order_gt', base_grand_total = '$order_gt', discount_amount = '$order_discount', base_discount_amount = '$order_discount', discount_description ='1%' WHERE entity_id = '$order_id'");
?>
Related Topic