Magento – Redirect action from pre-dispatch hook


Varien action dispatch design, allows developers to seamlessly prevent dispatch, forward request to different action, or simply redirect. First step in accomplishing this is creating a pre-dispatch event observer for desired action.

In our example, we will prevent logged out users from accessing cart page:

If we now try to access cart page as a guest customer, we should expect to be redirected to login page instead. However, this is not the case due to core bug within Mage_Core_Controller_Varien_Exception.

Lastly, we have to move core file to local code pool and correct the bug: