本文介绍了在magento中,如何为订单添加货件和单号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动态地将货件和货件跟踪添加到订单中,它必须是动态的,因为我们将批量进行,你们可以在这方面给我一些帮助吗?

I need to dynamically add a shipment and shipment track into an order, it needs to be dynamically because we will do it in batch, can you guys give me some help on this?


用户将看到一个包含订单列表的页面,然后他将输入每个订单的跟踪号并提交表格,因此我需要获得一个已知的承运人并通过该承运人发送所有订单.


The user will see a page with a list of orders, then he will input the track number for each and submit the form, so I need to get a known carrier and send all orders via this carrier.

推荐答案

如果您有订单ID和相应的跟踪编号的列表,则可以,

If you have a list of order ids and corresponding tracking numbers you can,

$shipment_collection = Mage::getResourceModel('sales/order_shipment_collection');
$shipment_collection->addAttributeToFilter('order_id', $order_id);

然后,您可以浏览所有货件并添加跟踪,例如

Then you can go through all the shipments and add the tracking like,

foreach($shipment_collection as $sc) {
    $shipment = Mage::getModel('sales/order_shipment');
    $shipment->load($sc->getId());
    if($shipment->getId() != '') {
        $track = Mage::getModel('sales/order_shipment_track')
                 ->setShipment($shipment)
                 ->setData('title', 'ShippingMethodName')
                 ->setData('number', $track_no)
                 ->setData('carrier_code', 'ShippingCarrierCode')
                 ->setData('order_id', $shipment->getData('order_id'))
                 ->save();
    }
}

您需要在此代码的顶部具有嵌套的订单ID和跟踪ID循环.

You would need to have a nested loop of order ID and tracking ID on top of this code.

这篇关于在magento中,如何为订单添加货件和单号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:37