I am trying to get the tracking number from an event sales_order_shipment_track_save_afterin Magento 1.9.0.1. For some reason, the event does not seem to include sending because it $observer->getEvent()->getShipment()returns NULL. Am I using the wrong event?
These are the relevant parts of my code:
config.xml (module)
<events>
<sales_order_shipment_track_save_after>
<observers>
<pixelstore_sms>
<type>model</type>
<class>pixelstore_sms/observer</class>
<method>shipments</method>
</pixelstore_sms>
</observers>
</sales_order_shipment_track_save_after>
</events>
Observer.php (model)
public function shipments($observer) {
$event = $observer->getEvent();
$shipment = $event->getShipment();
if (!$shipment) {
Mage::log('shipments event did not contain shipment', null, 'track.log');
return false;
}
$trackings = $shipment->getAllTracks();
$tracking = end($trackings);
$trackingId = $tracking->getNumber();
}
As you might have guessed, the operator ifmatches. get_class()shows that the observer Varien_Event_Observer.
Am I observing the wrong event or is there some other method that I have to call to get the tracking id?
source
share