Magento - 无法使用Observer保存第二个自定义属性

时间:2015-09-24 15:48:50

标签: php magento attributes

我正在开发一个自定义扩展,我必须在创建新订单时保存两个自定义属性。我有两个自定义输入,您可以在其中放置数据。

当我使用第一个输入提交数据时没有问题,数据被保存,之后我可以打印管理订单查看页面。

这是我的配置文件:

<?xml version="1.0"?>
<config>
    <modules>
        <VivasIndustries_Vshippingone>
            <version>1.1</version>
        </VivasIndustries_Vshippingone>
    </modules>

    <global> 
         <fieldsets>
            <sales_convert_quote>                           
                <my_custom_input_field_one><to_order>*</to_order></my_custom_input_field_one>
                <my_custom_input_field_two><to_order>*</to_order></my_custom_input_field_two>
            </sales_convert_quote>

            <sales_convert_order>                                              
                <my_custom_input_field_one><to_quote>*</to_quote></my_custom_input_field_one>
                <my_custom_input_field_two><to_quote>*</to_quote></my_custom_input_field_two>
            </sales_convert_order>
        </fieldsets>
        <helpers>
            <vshippingone>
                <class>VivasIndustries_Vshippingone_Helper</class>
            </vshippingone>            
        </helpers>

        <models>
            <vshippingone>
                <class>VivasIndustries_Vshippingone_Model</class>
                <resourceModel>vshippingone_mysql4</resourceModel>
            </vshippingone>
        </models>
        <resources>
            <vshippingone_setup>
                <setup>
                    <module>VivasIndustries_Vshippingone</module>
                    <class>Mage_Sales_Model_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </vshippingone_setup>
            <vshippingone_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </vshippingone_write>
            <vshippingone_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </vshippingone_read>
        </resources>

        <events>
            <checkout_controller_onepage_save_shipping_method>
                 <observers>
                     <vshippingone>
                          <type>singleton</type>
                          <class>vshippingone/observer</class>
                          <method>saveCustomDataOne</method>
                     </vshippingone>
                 </observers>
            </checkout_controller_onepage_save_shipping_method>
            <checkout_controller_onepage_save_shipping_method>
                 <observers>
                     <vshippingone>
                          <type>singleton</type>
                          <class>vshippingone/observer</class>
                          <method>saveCustomDataTwo</method>
                     </vshippingone>
                 </observers>
            </checkout_controller_onepage_save_shipping_method>         
        </events>

        <blocks>
            <vshippingone>
                <class>VivasIndustries_Vshippingone_Block</class>
            </vshippingone>
        </blocks>
    </global>
</config>

这是我的观察员:

<?PHP
class VivasIndustries_Vshippingone_Model_Observer 
{
    public function saveCustomDataOne($event)
    {
        $quote = $event->getQuote();
        $quote->setData('my_custom_input_field_one', $event->getRequest()->getPost('shipping_address_id'));

        return $this;
    }
    public function saveCustomDataTwo($event)
    {
        $quote = $event->getQuote();
        $quote->setData('my_custom_input_field_two', $event->getRequest()->getPost('shipping_office'));

        return $this;
    }   
}

不知怎的,我在第二个自定义字段中出错了。数据不会保存到数据库中。我的错误在哪里,如何保存数据?

提前致谢!

1 个答案:

答案 0 :(得分:0)

试试这个:

    <events>
        <checkout_controller_onepage_save_shipping_method>
             <observers>
                 <vshippingone>
                      <type>singleton</type>
                      <class>vshippingone/observer</class>
                      <method>saveCustomDataOne</method>
                 </vshippingone>
                 <vshippingtwo>
                      <type>singleton</type>
                      <class>vshippingone/observer</class>
                      <method>saveCustomDataTwo</method>
                 </vshippingtwo>
             </observers>
        </checkout_controller_onepage_save_shipping_method>         
    </events>

你有两个名为vshippingone的观察者,他们都可以在checkout_controller_onepage_save_shipping_method标签内