The observer does not keep order

I created an observer that listens for the sales_convert_quote_to_order event. The event fires and I just want to add a value to the order attribute. The attribute is set - as printed in the journal, but magento does not preserve order. What am I doing wrong?

Observer.php

 public function addLangToOrder($observer){ Mage::log('catching convert_quote_to_order_after'); $order = $observer->getEvent()->getOrder(); $order->setCustomerLanguage(Mage::app()->getStore()->getCode()); $order->save(); Mage::log($order->getCustomerLanguage()); } 

config.xml

 <events> <sales_convert_quote_to_order> <observers> <accustomer> <type>singleton</type> <class>Ac_Customer_Model_Observer</class> <method>addLangToOrder</method> </accustomer> </observers> </sales_convert_quote_to_order> </events> 

I added customer_language attribute through setting script

 $customer_lang = 'customer_language'; $installer->addAttribute('order', $customer_lang, array('type'=>'varchar')); 

The customer_language column is present in my sales_flat_order table. But he is not saved.

I am using Magento 1.4.1.1

+7
source share
2 answers

You need to add your attribute to both - quote and sales model - to make this work.

Since Magento will copy the specific <fieldset> * from quote to order , you also need to extend the config.xml your overriding class:

 <config> <!-- : --> <global> <fieldsets> <sales_convert_quote> <customer_language><to_order>*</to_order></customer_language> </sales_convert_quote> </fieldsets> </global> <!-- : --> </config> 

* see config.xml of Mages_Sales

+6
source

Is there a transaction that happened before that? my experience is that trying to save the model while the transaction is still ongoing does not work. I had to move the observer to another event after the transaction, for example, "sales_model_service_quote_submit_after".

+5
source

All Articles