Is there an event for customer account registration in Magento?

28,571

Solution 1

The answer to this question is that there isn't an event for that.

Solution 2

Whenever I'm looking for an event, I'll temporarily edit the Mage.php file to output all the events for a particular request.

File: app/Mage.php
public static function dispatchEvent($name, array $data = array())
{
    Mage::log('Event: ' . $name); //not using Mage::log, as 
    //file_put_contents('/tmp/test.log','Dispatching '. $name. "\n",FILE_APPEND); //poor man's log
    Varien_Profiler::start('DISPATCH EVENT:'.$name);
    $result = self::app()->dispatchEvent($name, $data);
    #$result = self::registry('events')->dispatch($name, $data);
    Varien_Profiler::stop('DISPATCH EVENT:'.$name);
    return $result;
}

and then perform whatever action it is I'm trying to hook into. Magento events are logically named, so scanning/sorting through the resulting logs usually reveals what I'm after.

Solution 3

customer_register_success is what you are looking for:

<config>
  <frontend>
    <events>
      <customer_register_success>
        <observers>
          <your_module>
            <type>singleton</type>
            <class>your_module/observer</class>
            <method>yourMethod</method>
          </your_module>
        </observers>
      </customer_register_success>
    </events>
  </frontend>
</config>

Solution 4

I discovered how to achieve this today. It involves using one of the generic controller events. This node in the config.xml will hook into the right event:

<events>
 ....
  <controller_action_postdispatch_customer_account_createPost>
    <observers>
     <your_module_here>...etc

The controller_action_postdispatch_REQUESTPATH event is thrown for every controller that extends Mage_Core_Controller_Front_Action (which is basically all of them) which makes it very easy to target. Ditto for controller_action_predispatch_REQUESTPATH.

Solution 5

I'm a bit surprised that none of the answers if solving the case completely.

Customer create can happen

  1. by url customer/account/create
  2. by register in checkout

I solved it by tracking two events:

config.xml

    <events>
        <controller_action_postdispatch_customer_account_createpost>
            <observers>
                <myextensionkey_create_account>
                    <class>myextensionkey/observer</class>
                    <method>createAccount</method>
                    <type>singleton</type>
                </myextensionkey_create_account>
            </observers>
        </controller_action_postdispatch_customer_account_createpost>
        <checkout_submit_all_after>
           <observers>
              <myextensionkey_checkout_create_account>
                    <class>myextensionkey/observer</class>
                    <method>createAccountCheckout</method>
                    <type>singleton</type>
              </myextensionkey_checkout_create_account>
           </observers>
        </checkout_submit_all_after>
    </events>

and in Observer.php

public function createAccount($observer) { ... } //Nothing special here

public function createAccountCheckout($observer) {
    if ($observer->getQuote()->getData('checkout_method') != Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) {
            return;
    }

Edit: I changed

<controller_action_predispatch_customer_account_createpost>

into

<controller_action_postdispatch_customer_account_createpost>

because on predispatch the account is not created yet. There can be an error for example if the email already exists in the shop.

Share:
28,571
Prattski
Author by

Prattski

Web Developer

Updated on January 26, 2020

Comments

  • Prattski
    Prattski over 4 years

    I would like to be able to run some functionality with a module that I am building whenever a customer registers an account, but I can't seem to find any event that is fired upon a new customer registration.

    Does anybody know of an event that is dispatched for that?