I am trying to get data from a new order placed on our website to use it for integration with our ERP/CRM system.
I use the event sales_order_place_after
and my observer function fires as expected, but it seems the order object passed to the observer has no data at all. I also tried the event checkout_submit_all_after
as pointed in this answer with same results.
After placing a new order I can see it normally in the admin panel, with all the items and customer data, so maybe I am not accessing it correctly in the observer.
My observer function looks like this:
public function newOrder(Varien_Event_Observer $observer)
{
Mage::log(print_r('new order function start', true), null, 'new-order.log');
// tried both those
$order = $observer->getEvent()->getData('order');
$order = $observer->getEvent()->getOrder(); // tried this too
// tried both those
$items = $order->getAllVisibleItems();
$items = $order->getAllItems();
$customer_id = $order->getCustomerId();
$customer_name = $order->getCustomerName();
$customer_email = $order->getCustomerEmail();
// Those had same result
//$customer_id = $order->getCustomer()->getId();
//$customer_name = $order->getCustomer()->getName();
//$customer_email = $order->getCustomer()->getEmail();
Mage::log(print_r($items, true), null, 'new-order.log');
Mage::log(print_r($customer_id, true), null, 'new-order.log');
Mage::log(print_r($customer_name, true), null, 'new-order.log');
Mage::log(print_r($customer_email, true), null, 'new-order.log');
Mage::log(print_r('new order function end', true), null, 'new-order.log');
}
And the output on the log file:
2017-05-18T11:10:10+00:00 DEBUG (7): new order function start
The end function log never appears. Am I accessing the data in a wrong way?