Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento redirect after logout

how can I redirect the customers after logout to default store view in magento? In logout I redirect them another store view.

like image 933
turbod Avatar asked Dec 09 '25 16:12

turbod


2 Answers

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.

like image 58
philwinkle Avatar answered Dec 12 '25 04:12

philwinkle


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) */);
}
like image 29
benmarks Avatar answered Dec 12 '25 04:12

benmarks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!