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();
精彩评论