Magento: Stop dispatching in pre_dispatch observer

dispatch, magento, observer-pattern, php

Solution

- the `dispatched` field of the request has to be true

- the `FLAG_NO_DISPATCH` flag of the front action has to be set to true

In code (inside observer):

// @see Mage_Core_Controller_Varien_Action::dispatch()
$controller = $observer->getControllerAction();
$controller->getRequest()->setDispatched(true);
$controller->setFlag(
    '', 
    Mage_Core_Controller_Front_Action::FLAG_NO_DISPATCH, 
    true
);

Problem

I want to influence product rendering (passing `$params` to `Mage_Catalog_Helper_Product_View::prepareAndRender()`) and registered an observer on the `controller_action_predispatch_catalog_product_view`event. rendering is working fine, but the original `catalog/product/view` action is still executed and so two products are displayed. How can I stop the dispatching during the pre-dispatch observer?

Original source