The problem is simple:
- After a user logs into the website, redirect them to a specific URL.
The solutions across the internet are vast and code heavy. But this solution really only requires a simple change to your template file.
In the login template:
persistent/customer/form/login.phtml
Update the form action to include your specific redirect path.
This is what exists currently:
1 | <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form" class="scaffold-form" autocomplete="off" > |
What I suggest is writing your redirect into a PHP variable, and then apply that to the action parameter. Like this:
1 2 3 4 5 6 7 8 | <?php // set redirect URL $session->setBeforeAuthUrl( Mage::getBaseUrl() ); $redirectUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB,array('_secure'=>true)).'your-redirect-path.html'; $formActionUrl = $this->getPostActionUrl() . ( strpos( $this->getPostActionUrl(), "?" ) > 0 ? "&" : "?" ) . "referer=" . Mage::helper('core')->urlEncode( $redirectUrl ); ?> <form action="<?php echo $formActionUrl ?>" method="post" id="login-form" class="scaffold-form" autocomplete="off" > |
Let me explain what is happening here a bit.
- The core Magento code expects the $session->setBeforeAuthUrl to be set to respect the referer query parameter. For that reason, I simply set it to the homepage. This is really just a failsafe in-case something goes wrong.
- The $redirectUrl is the URL you’d like your visitors to land on after logging in.
- The $formActionUrl simply takes the current form post URL that exists and adds the referer query parameter with your redirect URL. The one bit of “trickery” here is to pass it through Magento’s urlEncode function in the core helper which base64 encodes the URL.
- If you’re asking what does base64 encode mean/do???, don’t worry it’s nothing big you need to worry about. But simply put, it turns the url into garbly-gook – which is how Magento expects the URL to be formatted. Later, Magento will un-garbly-gook (yes, a technical term) the URL on the backend so they know what it means.
And that’s it – simple as that. No modules, fancy trickery, etc. But of course remember to copy this template to your theme folder (don’t edit in the base or default directory) before making these changes.
I hope that helps someone!