cancel
Showing results for 
Search instead for 
Did you mean: 

Order data is coming null in admin event observer

Order data is coming null in admin event observer

I am writing a observer when admin changes the order status. i used "sales_order_save_after"  and "sales_order_save_commit_after". with these two event observers iam getting order object data null.

$data = $observer->getEvent()->getData(); here in $data object order data is coming empty... Can you please help me out in solving this issue.

 

in config.xml

<config>

....

<adminhtml>
<events>
<sales_order_save_after>
<observers>
<order_status_change>
<class>Myanalytics_Events_Model_Observer</class>
<method>orderStatusChangeEvent</method>
</order_status_change>
</observers>
</sales_order_save_after>
</events>
</adminhtml>
</config>

 

in Observer.php

public function orderStatusChangeEvent(Varien_Event_Observer $observer) {

Mage::log("order status change by admin", null, 'eventAnalytics.log',true);
$order = $observer->getEvent()->getData();
$order_content = json_encode($order);
$current_time = time();
Mage::getModel('core/log_adapter', 'eventAnalytics.log')->log($order_content);
}

 

giving output like follows:

 

"data":{"data_object":{},"order":{},"name":"sales_order_save_after"}

2 REPLIES 2

Re: Order data is coming null in admin event observer

@gsateeshkumar28

 

Use this Event Observer: sales_order_place_after

You will start getting the data.

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Re: Order data is coming null in admin event observer

Your observer is configured correct, however you can't get what you want from json_encode, $order has to public vars, json_encode will always return {} unless you convert it to array or impelement JsonSerializable, you can try

$observer->getOrder()->getData();

instead