Magento : Redirect to a url from Event Observer Model

Posted on Updated on

//get the required url

$url = Mage::getUrl('checkout/cart');//eg to redirect to cart page

//get the http response object

$response = Mage::app()->getFrontController()->getResponse();

//set the redirect header to the response object

$response->setRedirect($url);

//send the response immediately and exit since there is nothing more to do with the current execution 🙂

$response->sendResponse();
exit;

Thank you for reading.
Hope this was helpful to you.
Cheers!!

Advertisements

2 thoughts on “Magento : Redirect to a url from Event Observer Model

    Sankar_k said:
    July 15, 2016 at 12:09 PM

    $response->setRedirect($url); In this coding not working in admin side(shop admin). Please replay the another coding for admin side observer.

      shakyaabiral responded:
      July 19, 2016 at 3:21 AM

      Hi Sankar, did you put in the right admin url to redirect to? Generally it should work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s