0

My custom module controller CartController.php's add method

public function addAction()
{
  ..........
  $params = array(); //array of important data
  //here in event dispatcher, along with other data, i want to send $params to my even observer
  Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse()),$params);
  ........
}

My custom module's config.xml

<config>
   ........
   <frontend>
     ........
     <events>
        <checkout_cart_add_product_complete>
            <observers>
                <frontendconfigurableproductmatrix>
                    <type>singleton</type>
                    <class>frontendconfigurableproductmatrix/observer</class>
                    <method>addToCartEvent</method>
                </frontendconfigurableproductmatrix>
            </observers>
        </checkout_cart_add_product_complete>
    </events>
    .........
 </frontend>
 ..........
</config>

Now, in my observer file Observer.php

 public function addToCartEvent($observer) {
       $params = Mage::app()->getFrontController()->getParams();
       print_r($params); //prints nothing

       //but this below is printing data
       $request = Mage::app()->getFrontController()->getRequest();
       print_r($request); //prints data
 }

How do i pass this $param array from my controllers addAction method event dispatcher to my observer file ?

3

You can pass params like:

  Mage::dispatchEvent('checkout_cart_add_product_complete', array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse(),'my_params' => $params));

In the Observer method you can call

 public function addToCartEvent($observer) {
       $params = $observer->getMyParams()
       print_r($params);    
 }

The problem in your implementation was that you were passing $params to dispatchEvent array without a key. You need to add a key, like in my case I used my_params.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.