通过Soap API v2为Magento中的特定商品创建货件,以获取可配置产品的订单 - 无法创建空货件错误

时间:2017-07-25 01:32:49

标签: php magento soap

我在magento 1.x中订购了2行。其中一条是简单的产品,另一条是可配置的产品。这两款产品的order_qty都是2

我正在尝试为数量为1的可配置产品之一创建货件。

这是我的requestBody(json对象),用于定义我要创建的特定货件:

{
    "orderIncrementId":"100006762",
    "items":[
        {
            "sku":"ABCD1234",
            "qty":1
        }
    ]
}

以下是我的实施部分,显示了货件的创建:

// Parse shipment sku => qty hash map
$shipmentQtys = [];
foreach ($requestBody['items'] as $shipmentItem)
    $shipmentQtys[$shipmentItem['sku']] = (int)$shipmentItem['qty'];

// Load sales order info
$orderInfo = $this->getOrder($requestBody['orderIncrementId']);

// Build itemsQty from shipment
$itemsQty = [];
foreach ($orderInfo->items as $orderItem) {
    if ($orderItem->product_type != 'simple') {
        continue;
    }
    $itemSku = $orderItem->sku;
    $itemId = $orderItem->item_id;
    if (array_key_exists($itemSku, $shipmentQtys)) {
        $itemsQty[] = [
            'order_item_id' => $itemId,
            'qty' => $shipmentQtys[$itemSku]
        ];
    }
}

// Create shipment
$comments = '';
$email = false;
$includeComment = false;
$shipmentIncrementId = $this->apiClient->salesOrderShipmentCreate(
    $this->sessionId,
    $orderIncrementId,
    $itemsQty,
    $comments,
    $email,
    $includeComment);

// Debug
var_dump($shipmentIncrementId);

我正在使用soap api的v2,如文档中所述:http://devdocs.magento.com/guides/m1x/api/soap/sales/salesOrderShipment/sales_order_shipment.create.html

当我的代码运行时,我收到以下错误:

  

无法创建空货。

所以我抛弃了我的$itemQty,以确保我已经为一个简单的产品解析了匹配的sku并且它有正确的数据:

Array
(
    [0] => Array
        (
            [order_item_id] => 9657
            [qty] => 1
        )
)

任何想法可能出错?

1 个答案:

答案 0 :(得分:0)

//尝试检查以下行。

$shipmentIncrementId = $this->apiClient->salesOrderShipmentCreate(
    $this->sessionId,
    $orderIncrementId,
    $itemsQty,
    $comments,
    $email,
    $includeComment);

chnage to

$shipmentIncrementId = $this->apiClient->salesOrderShipmentCreate(
    $this->sessionId,
    $orderInfo->orderIncrementId,
    $itemsQty,
    $comments,
    $email,
    $includeComment);