我有订单对象,我需要获取所有已发送的包裹追踪号码。我尝试了下面的代码,但它甚至没有返回任何我试过的包裹跟踪号码发送的订单。
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
$trackingNumbers = $order->getTrackingNumbers();
Order对象不为null,因为它返回其他方法的数据,如getShippingMethod等。
如果我点击“运输和处理”链接“信息跟踪订单”,则弹出窗口会显示所有跟踪号码。
答案 0 :(得分:4)
试试这个..
$shipmentCollection = Mage::getResourceModel('sales/order_shipment_collection')
->setOrderFilter($order)
->load();
foreach($ shipmentCollection as $ shipment){ $ shipment-> getAllTracks(); }
编辑: -
foreach ($shipmentCollection as $shipment){
foreach($shipment->getAllTracks() as $tracknum)
{
$tracknums[]=$tracknum->getNumber();
}
}
现在$ tracknums将拥有跟踪数字数组。
答案 1 :(得分:1)
你可以这样做:
$orderIncrementId = 100000016; // YOUR ORDER INCREMENT ID;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$trackNumber = array();
foreach ($order->getTracksCollection() as $track){
$trackNumber[] = $track->getNumber();
}