Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Stop dispatching in pre_dispatch observer

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_viewevent.

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?

like image 694
Alex Avatar asked Nov 22 '25 07:11

Alex


1 Answers

  1. the dispatched field of the request has to be true
  2. 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
);
like image 91
Alex Avatar answered Nov 24 '25 20:11

Alex