Magento REST API跟踪号未更新

时间:2018-01-12 12:53:55

标签: php rest api magento2

我正在使用Magento 2.2.2版本。我正在尝试通过其他API更新跟踪信息。这是我的代码:

$tracking_str   =   
        '{
         "items": [
            {
              "extension_attributes": {},
              "order_item_id": "'.$orderItemId.'",
              "qty": "'.$qty_invoiced.'"
            }
          ],
          "notify": false,
          "appendComment": true,
          "comment": {
            "extension_attributes": {},
            "comment": "Item(s) has been shipped",
            "is_visible_on_front": 0
          },
          "tracks": [
            {
              "extension_attributes": {},
              "track_number": "'.$TrackingNumber.'",
              "title": "'.$ShipTitle.'",
              "carrier_code": "'.$carrierCode.'"
            }
          ],
          "packages": [
            {
              "extension_attributes": {}
            }
          ],
          "arguments": {
            "extension_attributes": {}
          }

        }';

我将上述内容传递给php curl,这是我第一次收到货件ID的回复。订单状态正在变为“完成”状态。通过Magento API。但是,不会更新运营商代码和跟踪号等跟踪信息。当我再次运行代码时,我得到了响应:

 res is: stdClass Object
(    [message] => Shipment Document Validation Error(s):
The order does not allow a shipment to be created.
You can't create a shipment without products.
)

我不知道,我哪里出错了。

2 个答案:

答案 0 :(得分:0)

最后它起作用了!!!

$tracking_str = [ "items"=> [ [ "order_item_id"=>$orderItemId, "qty"=> $qty_invoiced ] ], "notify" => true, "appendComment" => true, "comment" => [ "extension_attributes" => [], "comment" => "Item(s) has been shipped", "is_visible_on_front" => 0 ], "tracks" => [ [ "extension_attributes" => [], "track_number" => $TrackingNumber, "title" => $ShipTitle, "carrier_code" => $carrierCode ] ] ]

以上代码,我用过。 github论坛中的一些人帮助了我。谢谢他们。现在正在更新跟踪号码,运营商代码和标题。

答案 1 :(得分:0)

此解决方案对我有用。

{
  "appendComment": true,
  "notify": true,
  "comment": {
    "comment": "shipment creado via webservice",
    "is_visible_on_front": 1
  },
  "tracks": [
    {
      "track_number": "3SCEMW182389201",
      "title": "UPS",
      "carrier_code": "Carrier code n"
    }
  ]
}

删除项目。