How to redirect after login to a particular page which depend upon the page from which the login is clicked in magento? I know redirection haappens in AccountController.php. But how to get the link of page from where customer logged in.I have two different pages for login .
How to redirect after login to a particular page which depend upon the page
Share
This is actually pretty easy. All you have to do is insert next code somewhere on your pages from which you’re making Log In.
What it does – it sets the variable to Customer session, that holds url of the referrer page.
AccountControllerwill send you back on that page after logging in, if the variable is set.UPDATE
Just thought I may need to edit the post, since the info is not full. So as I’ve learned some time ago, there are actually 2 session keys that rule the logic of "returning back/redirecting" after logging in:
before_auth_url: this should be set to the page, you want your user to see, if his login/password haven’t passed the validationafter_auth_url: this is url you want your user to be redirected to after successful log inNow the solution above worked, because Magento automatically sets
after_auth_url=before_auth_urlif the former is not set.Here’s the quick example: you have login form on Checkout. So you want your users to be redirected back to Checkout after they’ve logged in. BUT you don’t want your users to be redirected back to checkout if they failed to enter valid credentials. Rather than that you want them to stay on Login page, so they have ability to request Forget Password email or Register anew. Once they are able to login, you want them to be back at Checkout.
As complex as that use-case sounds, it’s actually quiet simple to achieve, and is’t already done in Magento Checkout. So here’s what you need to set:
That’s all folks 🙂