Redirect to previous page in Magento after logout
Feb 25, 2014 · 1 minute readCategory: magento
By default Magento sends a user to a logoutSuccess page after they choose to log out. This is ‘hard-baked’ into the Customer controller’s logout action in the line $this->_redirect('*/*/logoutSuccess');
. You can choose to set the Javascript redirect in the template customer/logout.phtml
, but a better idea is to bypass the logout success page entirely.
The way to do this is to override the logoutAction()
method in the customerController
:
- Rewrite the customer controller as documented here
- Override the
logoutAction()
method - Set the redirect as below
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class EdmondsCommerce_LogoutRedirect_AccountController extends Mage_Customer_AccountController {
public function logoutAction()
{
$url = Mage::getSingleton('core/session')->getLastUrl();
$this->_getSession()->logout()
->setBeforeAuthUrl(Mage::getUrl());
$this->_redirectUrl($url);
}
}