Get Free Audit

Magento Tips: How To Redirect A User To Other Page Than His Account Page After Login In Magento

Feb 22, 2013

6506 Andrey Litvin

Magento Tips: How To Redirect A User To Other Page Than His Account Page After Login In Magento

In some cases we need to change the default Magento behavior so it would redirect a user not to his account page but to some other page after login. To accomplish this we will use the customer_login event and change the address where the customer will be redirected to after login.

Let’s create a simple module consisting of a single model for observer and helper.

app/code/local/Belvg/Loginredirect/Model/Observer/Customer.php


In the admin part of the website we will indicate where the customer will be redirected to, and will use helper for that

app/code/local/Belvg/Loginredirect/Helper/Data.php

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor


* * @return string */ public function getRedirectUrl() { $_path = (string) $this->_getConfigValue(‘path_redirect’); return Mage::getUrl($_path); } …

And then define the event:

app/code/local/Belvg/Loginredirect/etc/config.xml


So these are the basic module steps.

Private Site

Download Login Redirect from GitHub

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

17 Comments

  1. I tried this before and set url correctly. Now, Is this necessary to define loginpost action file?
    { app\code\\Namespace\Modulename\controllers\AccountController.php }

  2. Hi Aleksander,

    I have been looking for this solution for a long time and this works great on my localhost, but when I try to implement it on my production site, I am still getting directed to the account dashboard. All other settings seem to be the same and cleared cache. Any suggestions for getting to work on the production version?

    Thanks,

  3. Thanks for your response Pavel.

    I may have broke the functionality of this module by attempting to setBeforeAuthUrl() on the last page viewed, as long as it’s not a customer-related page, within the header.phtml template.

    Is there a way to easily change the module to setBeforeAuthUrl() on any page but a customer page and have the user redirected back to it on successful login? I guess I would have to make a Product observer so it gracefully falls back to the admin-setting redirect URL!?

    Thanks!

  4. Hello Brett!
    Event customer_login is fired in Mage_Customer_Model_Session::setCustomerAsLoggedIn() method. This method is called only after all credentials verifications, so customer with incorrect login data will be redirected to the native magento login page with error message on it.

  5. Hi Aleksander,

    Great module! I do have one concern, though. If someone enters incorrect credentials when trying to login, the user is still redirected. How can the redirect be stopped if the login failed?

    Thanks again!

  6. Thank you very much

    i tried for this from fast one week finally i got solution here….

  7. I follow all the steps, then upload to my magento and nothing happens
    Thanks

  8. EssGee,

    Sorry for the late response. To be able to redirect customers of a certain group only you need to make the following changes:

    1. Add possibility to specify customer group into the system.xml file
    2. Add verification of a customer group in the observer

    See changes in the github repository.

  9. Hi, I’d have one question.

    I have set setBeforeAuthUrl to the base url of another store/storeview. The customer gets redirected to the correct url, but is not logged in in the store he was redirected to, but is logged in in the store he used the login form.

    I wanted to achieve that customers of a special customer group get redirected to one specific store, no matter in what store they log in.

    Account sharing is global.

    Best regards

  10. Hi Aleksander Tretjak,

    The above steps for redirecting a user to other page than his account page after login in magento are great.

    Can we done same thing in pretashop? If you know please suggest me how?

  11. hatim,

    What is the point of creating a cart that depends on an entry point for every single customer?

    The cart is tied to a user ID by default.

  12. Hi Aleksander, Have you come across a solution (on the community version) for having one login id and password but accessible from multiple PC’s or locations. What we are discovering is that the cart is duplicating the items from other browesers/sessions when the same User is sgined on from multiple PC’s, Browsers or different locations.

    We require this facility as a customer may have 30 users who are accessing the site with the same user name and password. This is unfortunately is required and cannot be altered.

    Would appreciate any help you can offer.

    Hatim

    we have a customer who may have upto 1000

  13. MagePsycho,

    Thanks a lot for your comment.

    The best way to change or enhance functionality is to use events. That is why we use the event and not expand the controller.

  14. Hi Aleksander,

    Thanks for sharing your tips.
    Alternatively, you can extend the Mage_Customer_AccountController::_loginPostRedirect() method for the purpose.

    Thanks
    Regards

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *