Magento 1.9 redirect customer after registration

↘锁芯ラ 提交于 2019-12-01 13:38:42
Amit Bera

if you want to do this for customer successfully then you can do this using event observer

after customer successfully magento trigger an event customer_register_success

This call an observer which will reequestion to custtom page

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

Details:

Step1: create config.xml is app/code/community/Amit/Custommodule/etc/ - See more at: http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/#sthash.JSktrUD0.dpuf and it code

<?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>

Step2:

create module control file Module name as Amit_Custommodule.xml at app/etc/modules/

it code is

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

Step3:

Create observer.php at Amit>Custommodule>Model

code is

 <?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;
      }
    }

I know this is an old thread maybe this will help someone else out trying to accomplish the same thing. You can set the redirect URL in the register.phtml template directly without having to modify controllers or create a module. You can set success and error URLs with hidden inputs like this.

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

I used this to redirect the user back to where they entered the login/register process like this:

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

You are doing this in right way, this is the best way to redirect customer to custom URL.

  1. Go to customer accountcontroller find _welcomeCustomer method.
  2. Search for $successUrl = $this->_getUrl('*/*/index', array('_secure' => true)); replace this code with your custom URL $successUrl = $this->_getUrl('costomURL', array('_secure' => true));

It works fine for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!