事件观察员不在magento工作

时间:2016-10-23 12:29:52

标签: php events magento-1.9

测试LoginEvent在我的自定义模块中无效。

应用\代码\本地\ SZ \出版\等\ config.xml中

<?xml version="1.0"?>
<config>    
    <global>
      <models>
         <offers>
            <class>Sz_Offers_Model</class>
         </offers>
      </models>
      <events>      
         <customer_login>
            <observers>
               <offers>
                  <type>model</type>
                  <class>offers/observer</class>
                  <method>loginEvent</method>                 
               </offers>
            </observers>
         </customer_login>
      </events>
</global>
</config>

应用\代码\本地\ SZ \出版\模型\ Observer.php

    <?php   

    class Sz_Offers_Model_Observer
    {
    // Magento passes a Varien_Event_Observer object as the first parameter of dispatched events.
          public function loginEvent($observer)
          {
             Mage::log("sadasdasd");
echo "Event"; exit;                  
          }          
    }

应用\等\模块\ Sz_Offers.xml

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

请帮帮我。活动无效。

1 个答案:

答案 0 :(得分:1)

请按照下面提到的步骤在Magento中创建一个事件观察员。

1- app / etc / modules / config.xml

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

2- app / code / local / Lpf / ModuleCookie / etc / Lpf_ModuleCookie.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Lpf_ModuleCookie>
            <version>0.1</version>
        </Lpf_ModuleCookie>
    </modules>
    <global>
        <models>
            <lpf_modulecookie>
                <class>Lpf_ModuleCookie_Model</class>
            </lpf_modulecookie>
        </models>
    </global>
    <frontend>
        <events>
            <customer_login>
                <observers>
                    <lpf_modulecookie_customer_login>
                        <type>model</type>
                        <class>lpf_modulecookie/observer</class>
                        <method>customerLogin</method>
                    </lpf_modulecookie_customer_login>
                </observers>
            </customer_login>
        </events>
    </frontend>
</config>

3- app / code / local / Lpf / ModuleCookie / Model / Observer.php

class Lpf_ModuleCookie_Model_Observer

{
     /**
      * Run couple of 'php' codes after customer logs in
      *
      * @param Varien_Event_Observer $observer
      */
     public function customerLogin($observer)
     {
         Mage::log(__METHOD__ . '() Hello!'); // Remove afterwards. Check your var/log/system.log to see if came to this point
         $customer = $observer->getCustomer();
         // "run couple of 'php' codes"
     }

}