开发者

Magento Tracking Number from Order Object

Given a magento order object how can I find the tracki开发者_运维知识库ng 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(); 
}


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.


Try the code below: Its not tested though.

$shipment->getAllTracks();


You can simply do this:

$order = Mage::getModel('sales/order')->loadByIncrementId(100000064);
$trackNumber = array();
foreach ($order->getTracksCollection() as $track){
    $trackNumber[] = $track->getNumber();
}


use

$order->getTrackingNumbers()


It should be

Mage::getResourceModel('sales/order_shipment_collection')
    ->setOrderFilter($order)
    ->load();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜