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"}
Use this Event Observer: sales_order_place_after
You will start getting the data.
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