Magento 1.9在注册后重定向客户

时间:2014-09-07 14:09:55

标签: magento magento-1.9

我想在Magento 1.9成功注册后将所有客户重定向到自定义页面。

我尝试了很多东西。首先,我成功地覆盖了核心客户帐户控制器。

我试图自定义以下操作:

  • createPostAction
  • _successProcessRegistration
  • _welcomeCustomer

尝试设置重定向网址或设置BeforeAuthUrl

    //$successUrl = $this->_getUrl('*/*/index', array('_secure' => true));
    $successUrl = $this->_getUrl('*/*/success');
    $this->_getSession()->setBeforeAuthUrl('http://test.local/customer/account/success/');
    if ($this->_getSession()->getBeforeAuthUrl()) {
        $successUrl = $this->_getSession()->getBeforeAuthUrl(true);
    }
    return $successUrl;

请注意,此时$ successUrl在此处返回时是正确的。我看到有一些后期调度方法,我假设这些方法会破坏这个网址并始终返回到客户/帐户/索引。

我已阅读过有关此主题的几篇帖子,但无法找到解决此问题的明确答案。

我甚至设置了隐藏的表单元素'success_url',试图按照其他地方提供的步骤作为解决方案。

为了能够显示一次性注册成功页面,需要遵循的完整,正确的流程是什么?

3 个答案:

答案 0 :(得分:6)

我知道这是一个旧线程,也许这会帮助别人尝试完成同样的事情。您可以直接在register.phtml模板中设置重定向URL,而无需修改控制器或创建模块。您可以使用隐藏的输入设置成功和错误网址。

<input type="hidden" name="success_url" value="my-custom-success-url.html" />
<input type="hidden" name="error_url" value="my-custom-error-url.html" />

我使用它将用户重定向回他们进入登录/注册过程的位置,如下所示:

<?php $ref = $this->getRequest()->getParam('referer');?>
<input type="hidden" name="success_url" value="<?php echo !empty($ref)?Mage::helper('core')->urlDecode($ref):$this->getSuccessUrl(); ?>" />

答案 1 :(得分:1)

您正在以正确的方式执行此操作,这是将客户重定向到自定义网址的最佳方式。

  1. 转到客户帐户控制器查找_welcomeCustomer方法。
  2. 搜索$successUrl = $this->_getUrl('*/*/index', array('_secure' => true));将此代码替换为您的自定义网址$successUrl = $this->_getUrl('costomURL', array('_secure' => true));
  3. 它适用于我。

答案 2 :(得分:1)

如果您想this for customer successfully then you can do this using 事件观察员

客户successfully magento trigger之后的活动customer_register_success

此调用是一个观察者,它将重新查询到custtom页面

  Mage::app()->getResponse()->setRedirct($Yourdreicurll);

详细说明:

<强>步骤1: 创建config.xmlapp/code/community/Amit/Custommodule/etc/ - 请参阅:http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/#sthash.JSktrUD0.dpuf 它代码

<?xml version="1.0" ?>
<config>
    <modules>
        <Amit_Custommodule>
            <version>1.0.0</version>
        </Amit_Custommodule>
    </modules>
    <global>
        <models>
            <custommodule>
                <class>Amit_Custommodule_Model</class>
            </custommodule>
        </models>
    </global>
    <frontend>
      <events>
          <customer_register_success>
        <observers>
          <notify_user>
            <class>custommodule/observer</class>
            <method>myredirection</method>
          </notify_user>
        </observers>
          </customer_register_success>     
        </events>
    </frontend>
</config>

<强>步骤2:

在app / etc / modules /

创建模块控制文件模块名称为Amit_Custommodule.xml

它的代码是

<?xml version="1.0"?>
<config>
    <modules>
        <Amit_Custommodule>
            <codePool>community</codePool>
            <active>true</active>
        </Amit_Custommodule>
    </modules>
</config>

<强>步骤3:

在Amit&gt; Custommodule&gt; Model

创建observer.php

代码是

 <?php
    class Amit_Custommodule_Model_Observer {
        public function myredirection(Varien_Event_Observer $observer) {
        $AccountController = $observer->getEvent()->getAccountController();

        $Customer = $observer->getEvent()->getCustomer();

         $response1 = Mage::app()->getResponse(); // observers have event args

            $url = 'http://www.example.com/';
            $response1->setRedirect($url);
            Mage::app()->getFrontController()->sendResponse();

        return;
      }
    }