订单对象中的 Magento 追踪号码

发布于 2024-11-03 04:14:11 字数 439 浏览 1 评论 0原文

给定一个 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(); 
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

刘备忘录 2024-11-10 04:14:11

我也为这个问题苦苦挣扎,返回空值。终于想通了。首先,如前所述,检索与给定订单关联的发货集合:

$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 现在将包含链接到该订单/发货的每个跟踪号码。

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.

殊姿 2024-11-10 04:14:11

尝试下面的代码:但它尚未经过测试。

$shipment->getAllTracks();

Try the code below: Its not tested though.

$shipment->getAllTracks();
甜嗑 2024-11-10 04:14:11

你可以简单地这样做:

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

You can simply do this:

$order = Mage::getModel('sales/order')->loadByIncrementId(100000064);
$trackNumber = array();
foreach ($order->getTracksCollection() as $track){
    $trackNumber[] = $track->getNumber();
}
生生漫 2024-11-10 04:14:11

使用

$order->getTrackingNumbers()

use

$order->getTrackingNumbers()
与往事干杯 2024-11-10 04:14:11

应该是

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

It should be

Mage::getResourceModel('sales/order_shipment_collection')
    ->setOrderFilter($order)
    ->load();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文