Magento注册后如何重定向到主页

Magento注册后如何重定向到主页,magento,redirect,Magento,Redirect,我正在使用magento创建一个电子商务网站。当前,如果新用户注册,url将重定向到“我的帐户”页面。我想显示主页一旦一个新用户注册我的网站 请引导我这样做 提前感谢您可以覆盖AccountController,以便将客户重定向到您想要的页面。 如果您需要一个现成的解决方案,而且效果很好,那么您可以尝试以下扩展: 首先检查登录后用于重定向用户的后端转发是否是您所需要的。 转到系统>配置>客户端选项卡下的客户端配置>登录选项>选择否 默认功能是将用户重定向到登录前访问的最后/当前页面。在我看来,这

我正在使用magento创建一个电子商务网站。当前,如果新用户注册,url将重定向到“我的帐户”页面。我想显示主页一旦一个新用户注册我的网站

请引导我这样做


提前感谢

您可以覆盖AccountController,以便将客户重定向到您想要的页面。

如果您需要一个现成的解决方案,而且效果很好,那么您可以尝试以下扩展:

首先检查登录后用于重定向用户的后端转发是否是您所需要的。 转到系统>配置>客户端选项卡下的客户端配置>登录选项>选择否


默认功能是将用户重定向到登录前访问的最后/当前页面。在我看来,这应该是有用的,如果你什么客户完成交易的产品谁让他行动和登录

打开帐户控制器并添加代码$successUrl=Mage::getBaseUrl()行前返回$successUrl在函数中\u welcomeCustomer()

转到您的客户帐户控制器:

aap->core->code->Mage->customer->controllers->AccountController.php
然后搜索
\u welcomeCustomer()
函数

替换此代码:

$successUrl = $this->_getUrl('*/*/index', array('_secure' => true));
使用:
$successUrl=Mage::getBaseUrl()


注册后,此
$successUrl
将用户返回主页。

登录、注销和注册后的重定向在magento中非常常见。请找到下面的代码,它可以帮助您

public function customerRegistration(Varien_Event_Observer $observer)    
{    
    $_session = Mage::getSingleton('customer/session');      
    $_session->setBeforeAuthUrl(CustomUrl);    
}
Customurl是注册后要重定向的url


如果您想要在登录、注销和注册后为您的电子商务网站定制url重定向的完整解决方案。自定义重定向扩展可以帮助您。点击链接获得分机

虽然这是一篇老文章,但我觉得有必要在这里提供一个新的答案,因为许多其他答案显然没有遵循Magento的最佳实践(例如:直接修改核心文件),或者(在有效时)他们不必要地重写了客户帐户控制器

下面的解决方案完全通过使用observer类来执行。这样做将确保升级Magento时不会丢失逻辑(如果您直接修改了核心类文件),Magento的核心开发团队是否也应该选择调整
Mage_Customer_AccountController::createPostAction
方法?这些更改将在您升级站点时引入(如果您重写控制器类文件,则不会发生这种情况)

在以下步骤中,根据需要创建任何目录以创建所述文件

步骤1:定义您的模块

app/etc/modules/Stackoverflow_Question10470629.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Stackoverflow_Question10470629>
            <codePool>local</codePool>
            <active>true</active>
        </Stackoverflow_Question10470629>
    </modules>
</config>

地方的
真的
步骤2:定义模块配置

app/code/local/Stackoverflow/Question10470629/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Stackoverflow_Question10470629>
            <version>1.0.0</version>
        </Stackoverflow_Question10470629>
    </modules>
    <global>
        <models>
            <stackoverflow_question10470629>
                <class>Stackoverflow_Question10470629_Model</class>
            </stackoverflow_question10470629>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_postdispatch_customer_account_createPost>
                <observers>
                    <stackoverflow_question10470629>
                        <type>singleton</type>
                        <class>stackoverflow_question10470629/observer_frontend</class>
                        <method>controllerActionPostdispatchCreatePostAction</method>
                    </stackoverflow_question10470629>
                </observers>
            </controller_action_postdispatch_customer_account_createPost>
            <customer_register_success>
                <observers>
                    <stackoverflow_question10470629>
                        <type>singleton</type>
                        <class>stackoverflow_question10470629/observer_frontend</class>
                        <method>customerRegisterSuccess</method>
                    </stackoverflow_question10470629>
                </observers>
            </customer_register_success>
        </events>
    </frontend>
</config>

1.0.0
Stackoverflow_问题10470629_模型
独生子女
堆栈溢出问题10470629/观察者前端
controllerActionPostdispatchCreatePostAction
独生子女
堆栈溢出问题10470629/观察者前端
客户注册成功
步骤3:定义观察者类

app/code/local/Stackoverflow/Question10470629/Model/Observer/Frontend.php

<?php
/**
 * All publicly accessible method names correspond to the event they observe.
 *
 * @category    Stackoverflow
 * @package     Stackoverflow_Question10470629
 */
class Stackoverflow_Question10470629_Model_Observer_Frontend
{

    /**
     * @param Varien_Event_Observer $observer
     */
    public function customerRegisterSuccess($observer)
    {
        /* @var $session Mage_Customer_Model_Session */
        $session = Mage::getSingleton('customer/session');

        // This event occurs within Mage_Customer_AccountController::createPostAction
        // however it occurs before the controller sets it's own redirect settings.
        // Therefore we set this flag to true now, and then within the postdispatch
        // we'll redirect to our custom URL
        $session->setData('customer_register_success', true);
    }

    /**
     * @param Varien_Event_Observer $observer
     */
    public function controllerActionPostdispatchCreatePostAction($observer)
    {
        /* @var $controller Mage_Customer_AccountController */
        /* @var $session Mage_Customer_Model_Session */

        $session = Mage::getSingleton('customer/session');

        // We must test for a successful customer registration because they
        // could have failed registration despite reaching postdispatch
        // (for example: they used an existing email address)
        if ($session->getData('customer_register_success')) {
            $session->unsetData('customer_register_success');

            $url        = Mage::getBaseUrl();    
            $controller = $observer->getData('controller_action');
            $controller->getResponse()->setRedirect($url);
        }
    }

}

在客户账户控制器中使用以下代码

查找函数\u成功处理注册和

替换
$url=$this->\u welcomeCustomer($customer);//第350行


使用
$url=Mage::getBaseUrl();

不,不要这样做。app/code/core中的类文件不应直接修改。它不遵循升级友好型开发实践,如果您在完成后升级Magento,您的修改将丢失。有关升级友好型方法,请参阅我的答案。有关升级友好型方法,请参阅我的答案ach.当前接受的答案不符合Magento开发实践。在这种情况下,没有必要重写AccountController。解决方案完全可以通过observer类完成。请参阅我的答案以获取示例。这种方法不是一种升级友好的方法,对account controller的修改是如果Magento升级的话,我会迷路的。请看我的答案,这是一种使用observer类的方法。我喜欢这个扩展。我更愿意使用它,而不是在代码上捣乱。