I have two observer file. One event is called for salesrule_validator_process and other observer file is called for sales_quote_collect_totals_after. How to get the result of salesrule_validator_process in sales_quote_collect_totals_after.

  • Both method are in same class? Sep 10, 2016 at 11:32
  • 1.Test_Subtotal_Model_Observer - sales_quote_collect_totals_after 2.Test_Mrp_Model_Observer - salesrule_validator_process. Not same class.
    – jassi
    Sep 10, 2016 at 11:33
  • @MurtuzaZabuawala If it has same class then what will be the solution? Give me any solution .
    – jassi
    Sep 10, 2016 at 11:37
  • Please check my answer Sep 10, 2016 at 11:40

2 Answers 2


If the observers are in the same class, you can save the result in a property, because by default observers are instantiated as singleton. That means, the same object is used in both events:

class Stack_Example_Model_Observer
    protected $_result;

    public function validatorProcess($observer)
        $this->_result = ...;

    public function afterTotalsCollect($observer)
        // here you can use $this->_result;

Otherwise, you can always use a third class as singleton. Simple example:

class Stack_Example_Model_Result extends Varien_Object



// first observer:
Mage::getSingleton('stack_example/result')->setData('result', $result);

// second observer:
$result = Mage::getSingleton('stack_example/result')->getData('result');

This example result singleton is just a dumb data object, but you could add more meaningful methods or actually process the result there instead of in the observer classes.

  • stack_example/result - Here what 'result' stand for? I am getting fatal error Fatal error: Call to a member function getData() on boolean
    – jassi
    Sep 10, 2016 at 12:12
  • "result" stands for the class name part after Model_ - please look up the basics for custom module creation and working with models. Sep 10, 2016 at 12:19
  • I created module file Result.php still it gives me fatal error.
    – jassi
    Sep 10, 2016 at 13:02

Solution 1: If values in different class

You can use magento registry for that

for storing registry you can do as below

Mage::register('my_need', $myvalue);

and getting value


after that unregister registry like below


Solution 2: if it is in the same class

protected $_myvariable;
function 1(){
   //set value
  $this->_myvariable  = $myvalue;
function 2(){
//fetch Value 


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.