Magento观察员没有射击

时间:2013-01-13 08:28:06

标签: magento

遇到自定义观察者没有接收事件的问题。该模块已启用并显示在仪表板的高级部分中。我已经清除了所有缓存等,所以它必须是一个小配置问题。

有人可以帮助发现问题吗?

config.xml中

<modules>
    <Hatclub_MembershipHandler>
        <version>1.0.0</version>
    </Hatclub_MembershipHandler>
</modules>

<global>

    <models>
        <dispatcher>
            <class>Hatclub_MembershipHandler_Model</class>
        </dispatcher>
    </models>

    <events>

        <customer_register_success>
            <observers>
                <registration_success_observer>
                    <class>dispatcher/observer</class>
                    <method>associateMembership</method>
                </registration_success_observer>
            </observers>
        </customer_register_success>

        <customer_session_init>
            <observers>
                <session_init_observer>
                    <class>dispatcher/observer</class>
                    <method>associateMembership</method>
                </session_init_observer>
            </observers>
        </customer_session_init>

        <customer_login>
            <observers>
                <login_observer>
                    <class>dispatcher/observer</class>
                    <method>associateMembership</method>
                </login_observer>
            </observers>
        </customer_login>

    </events>

</global>

Observer.php

class Hatclub_MembershipHandler_Model_Observer {

    // this is hook to magento event dispatched before action is run [only allow if membership exists]
    public function associateMembership(Varien_Event_Observer $observer) {

        // event
        $event = $observer->getEvent()->getControllerAction()->getFullActionName();

        Mage::log('**** EVENT FIRED ****' . $event);

        Mage::log(json_encode($observer->getEvent()));

    }

}

1 个答案:

答案 0 :(得分:2)

config.xml修改为

<modules>
    <Hatclub_MembershipHandler>
        <version>1.0.0</version>
    </Hatclub_MembershipHandler>
</modules>

<global>

    <models>
        <dispatcher>
            <class>Hatclub_MembershipHandler_Model</class>
        </dispatcher>
    </models>

    <events>

        <customer_register_success>
            <observers>
                <registration_success_observer>
                    <class>Hatclub_MembershipHandler_Model_Observer</class>
                    <method>associateMembership</method>
                </registration_success_observer>
            </observers>
        </customer_register_success>

        <customer_session_init>
            <observers>
                <session_init_observer>
                    <class>Hatclub_MembershipHandler_Model_Observer</class>
                    <method>associateMembership</method>
                </session_init_observer>
            </observers>
        </customer_session_init>

        <customer_login>
            <observers>
                <login_observer>
                    <class>Hatclub_MembershipHandler_Model_Observer</class>
                    <method>associateMembership</method>
                </login_observer>
            </observers>
        </customer_login>

    </events>

</global>

您提到了错误的班级名称。