Redirect customer after login in Magento

29 / Nov / 2012 by amatya 5 comments

When customers sign in magento they will redirect to account’s dashbord page by default. There is no setting in magento which will let you to set your own landing page for customer after login. If you want to achieve this feature then you need to do some custom coding .

First step is, create a custom module “local/Intell/Customer” and override “AccountController” of core customer module to your custom module. Following will be the content of your module’s config.xml file (local/Intell/Customer/etc/config.xml):

[php]
<?xml version="1.0"?>
<config>
<modules>
<Intell_Customer>
<version>1.1.0</version>
</Intell_Customer>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<intell_customer before="Mage_Customer">Intell_Customer</intell_customer>
</modules>
</args>
</customer>
</routers>
</frontend>
<global>
<helpers>
<intell>
<class>Intell_Customer_Helper</class>
</intell>
</helpers>
</global>
</config>

[/php]

Controller function responsible for customer redirection after login is “_loginPostRedirect “. Override this function to your custom account controller. Following is the code of custom account controller (local/Intell/Customer/controllers/AccountController.php). In this code “$customerRedirectUrl ” contains yourcustom page url :

[php]
<?php
require_once ‘Mage/Customer/controllers/AccountController.php’;
class Intell_Customer_AccountController extends Mage_Customer_AccountController
{
protected function _loginPostRedirect()
{
//customer session
$session = $this->_getSession();
$preUrl = $session->getBeforeAuthUrl(true);
$cusromerRedirectStatus = 1;
//your custom url
$customerRedirectUrl = "customer/address/new";
$redirectUrl = $preUrl;
if(($cusromerRedirectStatus) && ($customerRedirectUrl) && ($session->getCustomerRedirectFlag()) && (strpos($preUrl, ‘checkout/onepage’) == ”)){
$redirectUrl = Mage::getUrl().$customerRedirectUrl;
}
if(($cusromerRedirectStatus) && ($customerRedirectUrl)){
$redirectUrl = Mage::getUrl().$customerRedirectUrl;
}
if ($this->_getSession()->isLoggedIn()) {
$this->_redirectUrl($redirectUrl);
return;
}
$this->_redirectUrl($preUrl);
}
}

[/php]

Last step is, create a helper (local/Intell/Customer/Helper/Data.php) :

[php]
<?php
class Intell_Customer_Helper_Data extends Mage_Core_Helper_Abstract
{
}

[/php]

And yes, add your module’s pool file in app/etc/modules

That’s it. Hope this will help you.


Regards,
Amatya Trivedi
amatya@intelligrape.com

FOUND THIS USEFUL? SHARE IT

comments (5)

  1. Ajay

    Custom Redirection extension is a complete solution for custom url redirection for your ecommerce website after Login, Logout and SignUp. Click on below link for get the extension.

    Reply
  2. MagePsycho

    @Naresh
    There is option to configure customer group wise redirection url. You just need to go to admin to configure from ‘Customer Group Wise Redirection Url’ as:
    Normal Buyer => leave blank
    Seller => {{base_url}}sales/history

    Cheers!

    Reply
  3. Naresh

    I’m in different situation

    I have two types of users 1) Normal Buyer
    2) Seller

    i want redirect to My DashBoard(default one only) for Normal Buyer And

    for Seller it should redirect to My Order History

    what i have to do ?

    Reply
  4. Dana

    How do you redirect to the product page they were viewing right before they logged in? Magento doesn’t allow them to page back to the page and several customers have complained that once logged in, they can’t easily get back to the page without going through the menu and remembering the product they were on.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *