如何在Magento中按订单ID获取货件增量ID

时间:2013-12-22 21:15:11

标签: php magento

Hello Guys。有人能告诉我如何通过Magento中的订单ID获取货件增量ID吗?

我需要这个,因为我使用外部php文件将跟踪信息添加到货件中,并且需要货件ID。

感谢您的帮助。

我正在使用以下代码添加跟踪信息

$shipmentIncrementId='300000002';
$trackNumber='123456';
$carrier='custom';
$title='server10';


$shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipmentIncrementId);

         /* @var $shipment Mage_Sales_Model_Order_Shipment */



         $track = Mage::getModel('sales/order_shipment_track')
                     ->setNumber($trackNumber)
                     ->setCarrierCode($carrier)
                     ->setTitle($title);

         $shipment->addTrack($track);

         try {
             $shipment->save();
         } catch (Mage_Core_Exception $e) {
             $thiss->_fault('data_invalid', $e->getMessage());
         }

         return $track->getId();

print_r($shipment);

1 个答案:

答案 0 :(得分:13)

理论上,订单可以有多个货件。但是如果你制定一个约定,每个订单总是只有一个货物,你可以得到它的增量ID:

$orderIncrementId = 120000012;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$shipment = $order->getShipmentsCollection()->getFirstItem();
$shipmentIncrementId = $shipment->getIncrementId();