加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Observer不保存订单

发布时间:2020-12-13 18:02:44 所属栏目:PHP教程 来源:网络整理
导读:我构建了一个监听sales_convert_quote_to_order事件的观察者.事件被触发,我只想为订单的属性添加值.该属性已设置 – 打印在日志中 – 但magento不保存订单.我做错了什么? Observer.php public function addLangToOrder($observer){ Mage::log('catching con
我构建了一个监听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_language

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

customer_language列存在于sales_flat_order表中.但它没有得到保存.

我正在使用Magento 1.4.1.1

您需要将属性添加到报价和销售模型中才能使其正常工作.

由于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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读