Is it possible to bypass the logout page in Magento. I don't want to show the logout success page, want to show the current page
2 Answers
You can do it by using below code
override app/code/core/Mage/Customer/controllers/AccountController.php
There is a logoutAction
public function logoutAction()
{
$this->_getSession()->logout()
->renewSession();
$this->_redirect('*/*/logoutSuccess');
}
changed to
public function logoutAction()
{
$this->_getSession()->logout()
->renewSession();
$this->_redirectReferer(); //it will redirect to your previous page
}
-
-
2Never rewrite core files directly as your changes will be overriden during upgrades or can cause problems when patching. Copy the file in
app/code/local
instead and make your changes there instead. Mar 17, 2016 at 8:18 -
You need to override class because its not working in app/code/local Mar 17, 2016 at 8:42
-
will try to do like that. thanks, Raphael and Prashant.......... Mar 17, 2016 at 13:33
Unfortunately there's not a convenient event hook to manipulate the logout redirect location.
Mage_Customer_AccountController::logoutAction()
sets a redirect to ::logoutSuccessAction()
on the response object after the customer_logout
event is dispatched, and it's the rendering of the customer/logout.phtml template which uses PHP to set echo a javascript param to redirect to the homepage with no OOB possibility to pass an arg for an alternate JS-based redirect.
I think the cleanest solution would be to observe controller_action_postdispatch_customer_account_logout
, grab the controller object, and overwrite the location header using the response object's setRedirectWithCookieCheck()
method:
public function logoutRedirect($obs)
{
$obs->getControllerAction()
->setRedirectWithCookieCheck(/* your URL param(s) */);
}
------------------------------------------------------------------------- OR ---------------------------------------------------------------------------
I know it's not elegant, but the easiest method I have found is to copy and modify the template file at app/design/frontend/base/default/template/customer/logout.phtml
to your own theme directory.
Specifically this line:
<p><?php echo Mage::helper('customer')->__('You have logged out and will be redirected to our homepage in 5 seconds.') ?></p>
<script type="text/javascript">
//<![CDATA[
setTimeout(function(){ location.href = '<?php echo $this->getUrl() ?>'},5000);
//]]>
</script>
By modifying location.href url and even the timeout you can point the user to anywhere just after logout. E.g.:
<script type="text/javascript">
//<![CDATA[
setTimeout(function(){ location.href = '<?php echo $this->getUrl('*/*/login') ?>'},500);
//]]>
</script>
Again, it's not elegant, but it should be a quick enough redirect that the quick hop on the page will then shove them to another url, in the above example, back to the login screen.
More details check here.