php Magento 中是否有客户帐户注册事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/2968294/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an event for customer account registration in Magento?
提问by Prattski
I would like to be able to run some functionality with a modulethat I am building whenever a customer registersan account, but I can't seem to find any eventthat is fired upon a new customer registration. 
我希望能够使用module我正在构建customer registers的帐户运行一些功能,但我似乎无法找到任何event针对new customer registration.
Does anybody know of an eventthat is dispatched for that?
有没有人知道event为此而派遣的?
采纳答案by Prattski
The answer to this question is that there isn't an event for that.
这个问题的答案是没有一个事件。
回答by Alan Storm
Whenever I'm looking for an event, I'll temporarily edit the Mage.phpfile to output all the events for a particular request.
每当我寻找一个事件时,我都会临时编辑该Mage.php文件以输出特定请求的所有事件。
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.
然后执行我想要尝试的任何操作。Magento 事件按逻辑命名,因此扫描/排序结果日志通常会揭示我所追求的内容。
回答by Paul Grigoruta
customer_register_success is what you are looking for:
customer_register_success 是您正在寻找的:
<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>
回答by Jonathan Day
I discovered how to achieve this today. It involves using one of the generic controller events.  This node in the config.xmlwill hook into the right event: 
我今天发现了如何实现这一目标。它涉及使用通用控制器事件之一。config.xml将挂钩到正确的事件中的此节点:
<events>
 ....
  <controller_action_postdispatch_customer_account_createPost>
    <observers>
     <your_module_here>...etc
The controller_action_postdispatch_REQUESTPATHevent 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.
controller_action_postdispatch_REQUESTPATH为每个扩展的控制器Mage_Core_Controller_Front_Action(基本上是所有控制器)抛出该事件,这使得它很容易定位。同上controller_action_predispatch_REQUESTPATH。
回答by ahe_borriglione
I'm a bit surprised that none of the answers if solving the case completely.
我有点惊讶,如果完全解决这个案子,没有任何答案。
Customer create can happen
客户创造可能发生
- by url customer/account/create
- by register in checkout
- 通过 url 客户/帐户/创建
- 通过在结帐时注册
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
并在 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.
因为在 predispatch 帐户尚未创建。例如,如果商店中已经存在电子邮件,则可能会出现错误。
回答by Dumbrava Razvan Aurel
There isn't a direct event for this, but you could use the customer_save_commit_afterevent. This event also guarantees you that the customer is save in the shop's database. The problem with this event is that is triggered twice. Bellow is an hack that allows you to use this event - the observer function is listed:
没有针对此的直接事件,但您可以使用customer_save_commit_after事件。此事件还保证您将客户保存在商店的数据库中。这个事件的问题是它被触发了两次。Bellow 是一个允许您使用此事件的黑客 - 列出了观察者功能:
public function customer_save_commit_after($p_oObserver) {
    $l_oCustomer = $p_oObserver->getCustomer();
    if ($l_oCustomer->isObjectNew() && !$l_oCustomer->getMyCustomKeyForIsAlreadyProcessed()) {
        $l_oCustomer->setMyCustomKeyForIsAlreadyProcessed(true);
        // new customer
    }
    else {
        // existing customer
    }
    return false;
}
Hope this helps someone!
希望这可以帮助某人!
回答by Katapofatico
You have to consider also when the user register on-the-fly on checkout: a Register on chekout. Thinking on this case, you can catch the "checkout_type_onepage_save_order_after" event with your own Observer class, and then this code...
您还必须考虑用户何时在结账时即时注册:在结账时注册。考虑到这种情况,您可以使用自己的 Observer 类捕获“checkout_type_onepage_save_order_after”事件,然后这段代码...
if($observer->getEvent()->getQuote()->getCheckoutMethod(true) == Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER){
    (...)
}Anybody may say: Mage_Sales_Model_Quote->getCheckoutMethod() is deprecated since 1.4!!,but:
任何人都可能会说:Mage_Sales_Model_Quote->getCheckoutMethod() 自 1.4 以来已被弃用!!,但:
if ($this->getCustomerSession()->isLoggedIn()) {
            return self::METHOD_CUSTOMER;
        }... "METHOD_CUSTOMER" is the name for a checkout with an already registrated user, not our case.... but yes!, because....
if ($this->getCustomerSession()->isLoggedIn()) {
            return self::METHOD_CUSTOMER;
        }...“METHOD_CUSTOMER”是已注册用户结账的名称,不是我们的情况......但是是的!,因为......
Any other idea for the registration on checkout?
结帐时注册的任何其他想法?
回答by user392565
You can try customer_save_after, the only thing that the registration sends this event twice
可以试试customer_save_after,唯一的就是注册发送这个事件两次
回答by Mève
Actually there are customer_save_afterand customer_save_before(magento 1.5)
实际上有customer_save_after和customer_save_before(magento 1.5)
If you want to modify on-the-fly some data after form post, pick customer_save_before, change the data you want and that's all (the save action come after, so your change will be taken into account). 
如果您想在表单发布后即时修改一些数据,请选择customer_save_before,更改您想要的数据,仅此而已(保存操作在后,因此您的更改将被考虑在内)。
$customer->save()just doesn't work in customer_save_after. (fatal error) Use this observer to run a code after customer creation which are NOT related to customer data.
$customer->save()只是在customer_save_after. (致命错误)使用此观察者在客户创建后运行与客户数据无关的代码。
Hope that helps!
希望有帮助!
回答by Krishna
customer_register_success
customer_register_success
adminhtml_customer_save_after
adminhtml_customer_save_after
these two are the default events when a customer is inserted into the database.... first event fires in frontend when a user registers and second event fires in the backend when a customer is created through admin panel...i hope you know how to register an observer for an event...hope this will help you...
这两个是客户插入数据库时的默认事件......当用户注册时在前端触发第一个事件,当通过管理面板创建客户时在后端触发第二个事件......我希望你知道如何注册事件观察员...希望这对您有所帮助...
回答by Lance Badger
I found the event checkout_submit_all_after.
我发现了事件 checkout_submit_all_after。
<checkout_submit_all_after>
   <observers>
      <my_example>
         <class>my_example/observer</class>
            <method>customerRegistered</method>                        
      </my_example>
   </observers>
</checkout_submit_all_after>
In my Observer.php I get the quote object that is passed in.
在我的 Observer.php 中,我得到了传入的引用对象。
public function customerRegistered (Varien_Event_Observer $observer) {
    $quote = $observer->getQuote();
    $checkout_method = $quote->getData();
    $checkout_method = $checkout_method['checkout_method'];                      
    if ($checkout_method == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER) {        
}
Do not use $quote->getCheckoutMethod() it gives you login_in instead. Not sure why. Hope this helps.
不要使用 $quote->getCheckoutMethod() 它给你 login_in 代替。不知道为什么。希望这可以帮助。

