0

我希望在 Google 购物中将订单标记为已发货,但对如何格式化lineItems. 我正在关注运输订单项的官方文档:

https://developers.google.com/shopping-content/v2/reference/v2.1/orders/shiplineitems

这是我的代码:

$client = new Google_Client();
$service = new Google_Service_ShoppingContent($client);

// Get Order and Line Items
$order = $service->orders->get('MERCHANT-ID', 'ORDER-ID', array());
$lineItems = $order->getLineItems();

// Prepare Item Info
foreach($lineItems as $item) {
  $items = array('lineItemId' => $item->getId(),'productId' => $item->getProduct()->getId(), 'quantity' => $item->quantityPending);
}

// Prepare Shipment Info
$shipment = array('shipmentId' => 'xxx', 'carrier' => 'ups', 'trackingId' => '1234567890');

// Prepare PostBody
$postBody = new Google_Service_ShoppingContent_OrdersShipLineItemsRequest();
$postBody->operationId = rand();
$postBody->lineItems = $items;
$postBody->shipmentInfos = $shipment;

// Mark Google Order as Shipped
$service->orders->shiplineitems('MERCHANT-ID', 'ORDER-ID', $postBody, array());

这会产生以下错误,但我无法弄清楚到底出了什么问题:

Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "lineItems 的值无效:{lineItemId=HI2PTRMVLNCZEXP, productId=online:en :US:d3k3245, quantity=2}", "locationType": "other", "location": "" } ], "code": 400, "message": "lineItems 的值无效:{lineItemId=HI2PTRMVLNCZEXP, productId =online:en:US:d3k3245, 数量=2}" } }

任何想法我做错了什么?

4

1 回答 1

0

API 需要一个 Google_Service_ShoppingContent_OrderShipmentLineItemShipment 类的数组。

$lineItemShipments = array();
$lineItemShipment = new Google_Service_ShoppingContent_OrderShipmentLineItemShipment();
$lineItemShipment->setLineItemId($item->getId());
$lineItemShipment->setQuantity($item->quantityPending);
$lineItemShipments[] = $lineItemShipment;
$postBody->setLineItems($lineItemShipments);
于 2019-09-12T13:22:15.687 回答