我构建了一个监听sales_convert_quote_to_order事件的观察者.事件被触发,我只想为订单的属性添加值.该属性已设置 – 打印在日志中 – 但magento不保存订单.我做错了什么?
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>
$customer_lang = 'customer_language'; $installer->addAttribute('order',$customer_lang,array('type'=>'varchar'));
customer_language列存在于sales_flat_order表中.但它没有得到保存.
我正在使用Magento 1.4.1.1
您需要将属性添加到报价和销售模型中才能使其正常工作.
原文链接:https://www.f2er.com/php/134350.html由于Magento会将一个定义的< fieldset> *从引用复制到订单,因此您还需要相应地扩展覆盖类的config.xml:
<config> <!-- : --> <global> <fieldsets> <sales_convert_quote> <customer_language><to_order>*</to_order></customer_language> </sales_convert_quote> </fieldsets> </global> <!-- : --> </config>
*请参阅Mages_Sales的config.xml