4

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(); 
}
clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
Blake
  • 1,168
  • 1
  • 14
  • 15
  • http://stackoverflow.com/questions/3155671/magento-cronjob-outside-magento-to-update-shipment-status some relevant code here. – B00MER Apr 20 '11 at 22:40
  • An answer that helped me while googling for this: http://stackoverflow.com/questions/9433627/ – Krista K Jan 16 '13 at 23:02

5 Answers5

9

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.

Dave
  • 91
  • 1
  • 2
5

Try the code below: Its not tested though.

$shipment->getAllTracks();
Anunay
  • 497
  • 3
  • 13
3

You can simply do this:

$order = Mage::getModel('sales/order')->loadByIncrementId(100000064);
$trackNumber = array();
foreach ($order->getTracksCollection() as $track){
    $trackNumber[] = $track->getNumber();
}
Mukesh Chapagain
  • 25,063
  • 15
  • 119
  • 120
2

use

$order->getTrackingNumbers()
Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
Vasil Kulakov
  • 190
  • 2
  • 4
-1

It should be

Mage::getResourceModel('sales/order_shipment_collection')
    ->setOrderFilter($order)
    ->load();
clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
zhlmmc
  • 1