How do I redirect user customer to the page he/she was before a log in success?
-
12-12-2019 - |
Question
I'm using Magento 1.4.1.1
Only logged in customer can access a couple of pages of my website. So, when a non-logged in customer tries to access a page that needs him/her to be logged in, he/she is redirected to the login page. Using the following code.
if(!$this->helper('customer')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
}
After login success the customer is redirected to his/her account panel (the previous page location is lost).
Is there any way to make magento go back to the page where the customer was, after login succes ?
Regards
Solution
You can add this to the page of the customer must login : Mage::getModel('customer/session')->setBeforeAuthUrl([the link of your page])
OTHER TIPS
Go to System->Configuration->Customer Configuration->Login Options and set the value for Redirect Customer to Account Dashboard after Logging in
to No
.
There are (at least) two options to control the redirect target after customer log in:
- Set the
after_auth_url
property at the customer session. - In combination with the aforementioned suggestion by Marius, add a
referer
request parameter to the loginPost request.
and trying to put it in the controller file 'app/code/local/Mage/Customer/controllers/AccountController.php' in the function "loginPostAction" just before "if ($this->getRequest()->isPost()) {"