Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Tracking Number from Order Object

Given a magento order object how can I find the tracking number associated with that order?

$order = Mage::getModel('sales/order')->loadByIncrementId(100000064);

$shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
    ->setOrderFilter($order)
    ->load();
foreach ($shipmentCollection as $shipment){
    // This will give me the shipment IncrementId, but not the actual tracking information.
    $shipment->getData(); 
}
like image 513
Blake Avatar asked Dec 02 '22 02:12

Blake


2 Answers

I struggled over this one too, returning null values. Finally figured it out though. First, as previously noted, retrieve the shipment collection associated with the given order:

$shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
            ->setOrderFilter($order)
        ->load();
        foreach ($shipmentCollection as $shipment){
            // This will give me the shipment IncrementId, but not the actual tracking information.
            foreach($shipment->getAllTracks() as $tracknum)
            {
                $tracknums[]=$tracknum->getNumber();
            }

        }

The array $tracknums will now contain each of the tracking numbers linked to this order/shipment.

like image 170
Dave Avatar answered Dec 23 '22 19:12

Dave


Try the code below: Its not tested though.

$shipment->getAllTracks();
like image 38
Anunay Avatar answered Dec 23 '22 20:12

Anunay