我希望在 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}" } }
任何想法我做错了什么?