1

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

2 Answers 2

0

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'");
?>
5
  • This is also not working @Marcel,I think there is a connection problem. But thank you. Feb 15, 2018 at 9:19
  • Connection problem to Database? In which file you placed the Code? Have you tried the Update... direct in the database (with changed variables in orginal values) to test the query?
    – Marcel
    Feb 15, 2018 at 10:50
  • I am using update query in observer(sales_order_invoice_save_after) file. Feb 15, 2018 at 11:25
  • If execute query directly in phpmyadmin,update is working. Feb 15, 2018 at 11:26
  • Maybe this could help you: magento.stackexchange.com/questions/60288/…
    – Marcel
    Feb 16, 2018 at 13:26
0

Having in mind that "While creating invoice to particular order, We can't update sales order tables for that particular order.", you can update that order getting it from the observer Example:

config.xml ...

<events>
 <sales_order_invoice_save_after>
  <observers>
   <unique_identifier>
     <type>singleton</type>
     <class>Module_SalesOrder_Model_Observer</class>
     <method>updateDeliveryDate</method>
   </unique_identifier>
  </observers>
 </sales_order_invoice_save_after>
</events>

...

Observer

class Module_SalesOrder_Model_Observer
{
   public function updateDeliveryDate(Varien_Event_Observer $observer) {
      $_event             = $observer->getEvent();
      $_invoice           = $_event->getInvoice();
      $_order             = $_invoice->getOrder();

      $_order->setDeliveryAt('2018-03-26 00:00:00');
      $_order->save();
   }
}

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.