3

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

1

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
    } 
| improve this answer | |
  • Finally got what I want. Thanks, Prashant. – Shafeeque S Mar 17 '16 at 5:51
  • 1
    Never 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. – Raphael at Digital Pianism Mar 17 '16 at 8:18
  • You need to override class because its not working in app/code/local – Prashant Valanda Mar 17 '16 at 8:42
  • will try to do like that. thanks, Raphael and Prashant.......... – Shafeeque S Mar 17 '16 at 13:33
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.