从特定订单我想创建该订单的货件,并以编程方式为其分配跟踪编号。 请帮忙 。 感谢
答案 0 :(得分:10)
问题仅在于知识共享目的。
可以从Ref_Link
了解一些观点// $order_id = Order ID
$_order = Mage::getModel('sales/order')->load($order_id);
if($_order->canShip())
{
$shipmentId = Mage::getModel('sales/order_shipment_api')->create($_order->getIncrementId(), $itemsarray ,'your_comment' ,false,1);
echo $shipmentId; // Outputs Shipment Increment Number
$trackmodel = Mage::getModel('sales/order_shipment_api')
->addTrack($shipmentId,'your_shipping_carrier_code','your_shipping_carrier_title','carrier_tracking_number');
}
$itemsarray
=此处说明格式Ref_link
那就是它!
一个简单的代码片段
希望它可以帮到某人。
答案 1 :(得分:1)
接受的答案是正确的,并且在CE 1.9上为我工作,但我想扩展它。
您不需要使用$itemsQty
参数,您可以传递空array()
,或完全不让它。它是一个可选参数,prepareShipment()
中的方法app\code\core\Mage\Sales\Model\Service\Order.php
将检查该数据并在必要时执行查找。
如果您想在发货电子邮件中包含跟踪号,请务必先添加跟踪,然后使用Mage::getModel('sales/order_shipment_api')->sendInfo($shipmentIncrementId)
。
代码段:
$shipmentApi = Mage::getModel('sales/order_shipment_api');
//pass false for email, unless you want Magento to send the shipment email without any tracking info
//could also be written as $shipmentIncrementId = $shipmentApi->create($order->getIncrementId());
$shipmentIncrementId = $shipmentApi->create($order->getIncrementId(), array(), '' , false, 0);
//add tracking info ($shippingCarrier is case sensitive)
$shipmentApi->addTrack($shipmentIncrementId, $shippingCarrier, $shippingTitle, $trackingNumber);
//send shipment email with tracking info
$shipmentApi->sendInfo($shipmentIncrementId);
create()方法签名:
public function create($orderIncrementId, $itemsQty = array(), $comment = null,
$email = false, $includeComment = false)
有关所有方法,请参阅app\code\core\Mage\Sales\Model\Order\Shipment\Api.php
。