【发布时间】:2013-05-29 11:14:29
【问题描述】:
我的订单如下所示:
我想为该订单上的以下商品创建发货(不是所有商品):
2 x VCF001
1 x SBA364
为此,我在发货 api 上找到了以下信息:http://bit.ly/17rpuwj
基于 API 的文档,我想出了以下代码。当我尝试执行它时,我收到以下错误无法创建空货件:
$order_number = '300000002';
$order = Mage::getModel('sales/order')->loadByIncrementId($order_number);
$allocations = array(
array('sku' => 'VCF001', 'allocated_qty' => 2),
array('sku' => 'SBA364', 'allocated_qty' => 1)
);
function GetOrderItemId($order_items, $sku) {
foreach ($order_items as $order_item) {
if ($order_item->getSku() == $sku) {
return $order_item->getItemId();
}
}
return 0;
}
function CreateShipment($order, $allocations)
{
// Get Order Items
$order_items = $order->getItemsCollection();
// Parepare Item Qtys For Shipment
$item_qtys = array();
foreach ($allocations as $allocation) {
$item_qtys[] = array(GetOrderItemId($order_items,
$allocation['sku']) => $allocation['allocated_qty']);
}
// Anticipate Errors
try
{
// Create Shipment
$shipment = new Mage_Sales_Model_Order_Shipment_Api();
$shipmentId = $shipment->create($order->getIncrementId(),
$item_qtys, 'Pick #123 Sent to Warehouse');
// Done
echo 'Shipment Created - ID #'. $shipmentId;
}
catch (Exception $e)
{
print_r($e);
}
}
CreateShipment($order, $allocations);
知道为什么这不能按预期工作吗?在此处查看完整的异常日志:http://pastebin.com/raw.php?i=GMN4WCAE
【问题讨论】:
标签: magento