Magento新用户注册-注入自己的代码 [英] Magento new user registration - inject own code

查看:76
本文介绍了Magento新用户注册-注入自己的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Magento安装和另一个应用程序之间建立松散的连接.特别是,我目前只关心两件事-客户及其购买.到目前为止,我编辑的是文件app/code/core/Mage/Customer/controllers/AccountController.php-函数createPostAction()被扩展为将客户的信息发送到其他应用程序.在success.phtml文件中进行了另一处修改,以在下达订单后发送订单的详细信息.

I'm trying to make a loose connection between a Magento installation and another application. In particular, there are only two things I care about at the moment - customers and their purchases. What I edited thus far is the file app/code/core/Mage/Customer/controllers/AccountController.php - function createPostAction() is augmented to send the customer's info to the other application. Another modification was made in success.phtml file to send out the details of the order once it's placed.

我遇到的问题是,如果用户只是将物品放入购物车(作为客人),然后在结帐过程中进行注册-则永远不会在第二个应用程序中创建客户记录.只有在用户先明确注册然后单独签出后,该功能才起作用.

The problem I'm having is that if a user just places items in a cart (as a guest) and then registers as part of the checkout process - the customer's record in the second application is never created. It only works if the user first explicitly registers, and then checks out separately.

我想AccountController.php可能是修改错误的文件以实现所需的结果,应该改用哪个文件?

I suppose AccountController.php may be the wrong file to modify to achieve my desired result, which file should I use instead?

我不包括代码示例,因为它基本上无关紧要-问题不在于代码,而在于它显然放在错误的位置.在哪里添加添加自定义代码的好地方,该代码应在新客户注册后运行?

I am not including the code samples, as it's largely irrelevant - the problem is not with the code, but with the fact that it's apparently in the wrong place. Where would be a good place to add custom code which should run when a new customer is registered?

推荐答案

在Magento中干净地执行此操作有些棘手,但有可能实现.我前段时间做过相同的任务,并使用观察员解决了

This is a bit tricky to do cleanly in Magento but possible to achieve. I've had the same task a while ago and solved using observers

首先,您需要创建一个监听controller_action_postdispatch事件的观察者:

First you need to create an observer which listens controller_action_postdispatch event:

<events>
    <controller_action_postdispatch>
        <observers>
            <yourmodule_anything>
                <type>singleton</type>
                <class>yourmodule/observer</class>
                <method>someMethod</method>
            </yourmodule_anything>
        </observers>
    </controller_action_postdispatch>
</events>

然后在您的观察者方法中,您可以按以下方式检查动作名称

Then in your observer method you can check action names as follows

<?php
$action = $observer->getEvent()->getControllerAction();
if ($action->getFullActionName() == 'customer_account_createpost') {
    if (Mage::getSingleton('customer/session')->isLoggedIn()) { // this check allows to determine if customer session was created which means successfull registration
    }
}

可以为结帐注册执行类似的操作.通常,观察者是扩展Magento功能的好方法(也是正确的方法).在此处

Something similar can be done for checkout registration. In general observers are great (and proper) way to extend Magento functionality. Read more about them here

这篇关于Magento新用户注册-注入自己的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆