So I am simply trying to create a hook into registrations predispatch event. This is what I have so far:

config.xml:

<events>
  <controller_action_predispatch_customer_account_createpost>
    <observers>
      <mymodulename>
        <class>mymodulename/observer</class>
        <method>hookToAccountCreationBefore</method>
      </mymodulename>
    </observers>
  </controller_action_predispatch_customer_account_createpost>
</events>

and the observer:

Model/Observer.php :

public function hookToAccountCreationBefore($observer) {
  die('getting here');
}

So I go and do a registration and I see the controller_action_predispatch_customer_account_createpost event getting called in my event logs but its not calling my function.

Please help!

UPDATE:

The answer below worked perfectly for me. However, $observer->getEvent()->getCustomer() is getting NULL for me even though another observer is overriding the same exact event and this works fine. I've tried temporarily commenting out the observer config for the other extension and its still empty. Any ideas?

有帮助吗?

解决方案

In your config.xml you could also do

config.xml:

<global>
    <models>
        <mymodulename>
            <class>MyNamespace_MyModuleName_Model</class>
        </mymodulename>
    </models>
    <events>
        <controller_action_predispatch_customer_account_createpost>
            <observers>
                <mymodulename>
                    <type>singleton</type>
                    <class>mymodulename/observer</class>
                    <method>hookToAccountCreationBefore</method>
                </mymodulename>
            </observers>
        </controller_action_predispatch_customer_account_createpost>
    </events>
</global>

or

<global>
    <events>
        <controller_action_predispatch_customer_account_createpost>
            <observers>
                <mymodulename>
                    <type>singleton</type>
                    <class>MyNamespace_MyModuleName_Model_Observer</class>
                    <method>hookToAccountCreationBefore</method>
                </mymodulename>
            </observers>
        </controller_action_predispatch_customer_account_createpost>
    </events>
</global>

其他提示

Maybe try with following Event

customer_register_success
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top