订单对象的Magento跟踪编号

时间:2011-04-20 22:14:53

标签: magento magento-1.4

鉴于magento订单对象,如何找到与该订单关联的跟踪编号?

$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(); 
}

5 个答案:

答案 0 :(得分:9)

我也在努力克服这一点,返回空值。终于想通了。首先,如前所述,检索与给定订单关联的货件集合:

$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();
            }

        }

数组$ tracknums现在将包含链接到此订单/货件的每个跟踪号。

答案 1 :(得分:5)

尝试下面的代码:虽然没有经过测试。

$shipment->getAllTracks();

答案 2 :(得分:3)

你可以这样做:

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

答案 3 :(得分:2)

使用

$order->getTrackingNumbers()

答案 4 :(得分:-1)

应该是

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