0

Hi i have made a custom column in sales_flat_order table named final_shipping_amount. When i am loading order its showing my custom column in it. I am trying to add value in my custom column but its not adding value in it here is my code.

$final_shipping = "1.33"
$orderIid = $this->getRequest()->getParam('id');
$orderDataShip = Mage::getModel('sales/order')->load($orderIid);
$orderDataShip->setFinalShippingAmount($final_shipping);
$orderDataShip->save();

Its not saving value in it. i have also tried this way but also its not saving

$final_shipping = "1.33"
$orderIid = $this->getRequest()->getParam('id');
$orderDataShip = Mage::getModel('sales/order')->load($orderIid);
$orderDataShip->setData('final_shipping_amount' , $final_shipping);
$orderDataShip->save();

but its not working.

OBAID
  • 1,299
  • 2
  • 21
  • 43

2 Answers2

0

In your module's config.xml file user this event

<sales_order_place_before>
            <observers>
                <Yournamespace_YourModuleName_model_observer>
                    <type>singleton</type>
                    <class>Yournamespace_YourModuleName_Model_Observer</class>
                    <method>example</method>
                </Yournamespace_YourModuleName_model_observer>
            </observers>
</sales_order_place_before>

And in your Observer file

public function example($observer) {
        $final_shipping = "1.33";
        $event = $observer->getEvent();
        $order = $event->getOrder();


        $items = $order->getQuote()->getAllItems(); 
        //Mage::log($items->debug());

        $orderdata = Mage::getModel('sales/order')->load($order->getEntityId());
        $mn = $orderdata->setData('final_shipping_amount', $final_shipping );
        $orderdata->save();

    }

May be it can help you.

Klaus Mikaelson
  • 572
  • 6
  • 17
0

Adding an attribute to magento isn't as simple as that.

Firstly when you save the order entity, magento will save this into the EAV structure not the flat order table.

You need to tell magento you've added a new attribute first, there's a load of info on how to do this for example:

http://stackoverflow.com/questions/12936470/adding-a-new-attribute-to-order-in-magento

Once you've done that magento will be aware of the attribute you've added and should save correctly.

Andrew
  • 12,617
  • 1
  • 34
  • 48