Reputation: 169
I created an attribute for order and quote using installer script. Those can be seen in the entity_attribute table. In the checkout i want to set value and save it with the order. I created an event and observer function. But value wont saving. Any help please.
config.xml
<sales_order_save_after>
<observers>
<clickandcollect_save_location_orderattributes>
<type>model</type>
<class>Balance_Clickandcollect_Model_Observer</class>
<method>saveLocationOrderattributes</method>
</clickandcollect_save_location_orderattributes>
</observers>
</sales_order_save_after>
Observer.php
public function saveLocationOrderattributes($observer){
$event = $observer->getEvent();
$order = $event->getOrder();
//$quote = $event->getQuote();
$order->setLocation('1');
}
Can anyone please help me to solve this. I cannot understand where did i make mistake.
Thank you
Upvotes: 0
Views: 2646
Reputation: 61
Your order->save() goes back to sales_order_save_after and makes an infinite loop. Try this, I added a registry key so it won't save the attribute and order after your order->save() call
public function saveLocationOrderattributes($observer){
if(!Mage::registry('afterOrderSave'))
{
Mage::register('afterOrderSave');
$event = $observer->getEvent();
$order = $event->getOrder();
$order->setLocation('1');
$order->save();
}
}
Upvotes: 1
Reputation: 11853
i think you are missing save method
you must have to change your observer code as below
public function saveLocationOrderattributes($observer){
$event = $observer->getEvent();
$order = $event->getOrder();
//$quote = $event->getQuote();
//or load the order
$order_id = $order->getId();
$order = Mage::getModel('sales/order')->load($order_id);
$order->setLocation('1');
$order->save();
}
so it will save your order updated value.
hope this will help you
Upvotes: 1