【问题标题】:Create a shipment for specific items in Magento via Soap API v2 for an order with configurable products - Cannot create an empty shipment error通过 Soap API v2 在 Magento 中为具有可配置产品的订单创建特定项目的货件 - 无法创建空货件错误
【发布时间】:2017-07-25 01:32:49
【问题描述】:

我在 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);

我正在使用 v2 的 soap api,如下面的文档所述: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
        )
)

有什么想法可能是错的吗?

【问题讨论】:

    标签: php magento soap


    【解决方案1】:

    //尝试检查以下行。

    $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);
    

    【讨论】:

    • 我试过了,还是不行。我认为问题与为可配置产品创建货件有关。
    • 我们不能在magento中为可配置产品发货,而只能发货配置子产品。
    • 我知道这一点。如果您查看我的代码,当我遍历订单项时,我只加载item_id where product_type = simple
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多