Magento观察员在结帐时

时间:2013-05-28 14:56:06

标签: php xml magento

我刚刚学习了如何创建简单模型观察器的教程。当用户点击“继续结账”时,有人可以帮助我或指出正确的方向来调用方法吗?

以下是代码:

 <events>
  <checkout_onepage_controller_success_action>
    <observers>
      <sales_order_place_before>
        <type>singleton</type>
        <class>my_Observer</class>
        <method>send_email</method>
      </sales_order_place_before>
    </observers>
  </checkout_onepage_controller_success_action>     
 </events> 

1 个答案:

答案 0 :(得分:2)

尝试

创建:app / code / local / MagePal / MyCheckout / etc / config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MagePal_MyCheckout>
            <version>1.0.1</version>
        </MagePal_MyCheckout>
    </modules>

    <global>
        <models>
            <magepal_mycheckout>
                <class>MagePal_MyCheckout_Model</class>
            </magepal_mycheckout>
        </models>
         <events>
            <checkout_onepage_controller_success_action>
                <observers>
                    <magepal_mycheckout>
                        <type>singleton</type>
                        <class>mycheckout/observer</class>
                        <method>sendEmail</method>
                    </magepal_mycheckout>
                </observers>
            </checkout_onepage_controller_success_action>
        </events>
    </global>
</config>

创建:app / code / local / MagePal / MyCheckout / Model / Observer.php

class MagePal_MyCheckout_Model_Observer 
{
    /**
     *
     * @param Varien_Event_Observer $observer
     * @return object
     */
    public function sendEmail(Varien_Event_Observer  $observer)
    {
        //add logic here

        return $this;
    }
}

创建:app / etc / modules / MagePal_MyCheckout.xml

  <?xml version="1.0"?>
    <config>
           <modules>
                  <MagePal_MyCheckout>
                          <active>true</active>
                          <codePool>local</codePool>
                  </MagePal_MyCheckout>
           </modules>
    </config>