Question

I'm using sales_order_shipment_save_after observer to collect tracking numbers. I have tried $event->getOrder but it will not load any order object. I suppose it's the shipment observer I use as opposed to order observer. Usually, getId or getIncrementId on Order would ok. Right now I was able to get tracking number and shipment ID just fine. Is there a way to get order ID from shipment ID in Magento?

Here is what I got

$shipment = $event->getShipment();
$tracks = $shipment->getAllTracks();
foreach ($tracks as $track) {
       $orderTracking = $track->getTrackNumber();
 }
Was it helpful?

Solution

need to try below code

$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$shippingMethod = $order->getShippingMethod();

I am try to get order details form shipment object

Your function , should like this

public function you_function_name(Varien_Event_Observer $observer)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top