在新订单属性Magento中保存自定义字段值

时间:2015-01-28 09:06:05

标签: magento get save observers

  1. 在此我需要在订单数据中保存一些自定义字段值。 为此,我创建了一个小模块,其结构如下。这会在 sales_flat_order 表中创建一个新字段。观察者也在工作,但当我尝试在观察者中打印自定义字段值时,它什么也没显示。那么请你帮我看看如何在观察者中以结算形式获取自定义字段的值,以便我可以使用订单数据保存它。
  2. 应用程序/代码/本地/ ICLP / Orderattribute的/ etc / config.xml中

    <?xml version="1.0"?>
    <config>
      <modules>
        <Iclp_Orderattribute>
          <version>0.1.0</version>
        </Iclp_Orderattribute>
      </modules>
      <global>
        <helpers>
          <orderattribute>
            <class>Iclp_Orderattribute_Helper</class>
          </orderattribute>
        </helpers>
        <models>
          <orderattribute>
            <class>Iclp_Orderattribute_Model</class>
            <resourceModel>orderattribute_mysql4</resourceModel>
          </orderattribute>
        </models>
        <resources>
          <salesattribute1422420996_setup>
            <setup>
              <module>Iclp_Orderattribute</module>
              <class>Mage_Sales_Model_Mysql4_Setup</class>
            </setup>
            <connection>
              <use>core_setup</use>
            </connection>
          </salesattribute1422420996_setup>
          <salesattribute1422420996_write>
            <connection>
              <use>core_write</use>
            </connection>
          </salesattribute1422420996_write>
          <salesattribute1422420996_read>
            <connection>
              <use>core_read</use>
            </connection>
          </salesattribute1422420996_read>
        </resources>
        <events>
          <checkout_type_onepage_save_order> <!-- identifier of the event we want to catch -->
            <observers>
              <checkout_type_onepage_save_order_handler> <!-- identifier of the event handler -->
                <type>model</type> <!-- class method call type; valid are model, object and singleton -->
                <class>orderattribute/observer</class> <!-- observers class alias -->
                <method>getorderattribute</method>  <!-- observer's method to be called -->
                <args></args> <!-- additional arguments passed to observer -->
              </checkout_type_onepage_save_order_handler>
            </observers>
          </checkout_type_onepage_save_order>
        </events>
      </global>
    </config> 
    

    应用程序/代码/本地/ ICLP / Orderattribute /型号/ Observer.php

    <?php
    class Iclp_Orderattribute_Model_Observer
    {
    
                public function getorderattribute(Varien_Event_Observer $observer)
                {
            $event = $observer->getEvent();
            $order = $event->getOrder();
            $fieldVal = Mage::app()->getFrontController()->getRequest()->getParams();
    
            $order->setOrder_Attribute($fieldVal['order_attribute']);
           // echo "success" ;
                }
    
    }
    

    应用程序/代码/本地/ ICLP / Orderattribute / SQL / salesattribute1422420996_setup / mysql4安装-0.1.0.php

    <?php
    $installer = $this;
    $installer->startSetup();
    
    $installer->addAttribute("order", "order_attribute", array("type"=>"varchar"));
    $installer->endSetup();
    

    模板/持久性/结帐/ onepage / billing.phtml

    <form id="co-billing-form" action="">
    
    <input id = "order_attribute" name="order_attribute" value= " order_attribute order_attribute " class="input-text" type=”text”>
    

1 个答案:

答案 0 :(得分:0)

您的自定义属性是否已使用您指定的值保存在数据库中?

如果是,则在观察者中加载订单ID或增量ID的订单,然后尝试获取自定义属性。