2

我正在尝试在 Google Merchant Center 上插入产品。我目前正在使用 Google API PHP 客户端,我无法在任何类和扩展它的类中找到 toSimpleObject 函数。

$this->service = new Google_Service_ShoppingContent($client);

$product = array("batchId" => $batchID,
                      "merchantId" => $this->googleapi->merchantID,
                      "method" => "insert",
                      "product" => array(
                        "kind" => "content#product",
                        "offerId" => $skuDetails['SKU'],
                        "title" => $skuDetails['TITLE'],
                        "description" => $skuDetails['DESCRIPTION'],
                        "imageLink" => $skuDetails['IMAGE'],
                        "contentLanguage" => "en",
                        "targetCountry" => "US",
                        "channel" => "online",
                        "availability" => ($skuDetails['QUANTITY'] > 0)?'in stock':'out of stock',
                        "brand" => $skuDetails['BRAND'],
                        "condition" => $skuDetails['CONDITION'],
                        "minHandlingTime" => $skuDetails['HANDLING_TIME'],
                        "ageGroup" => 'adult',
                        "maxHandlingTime" => ($skuDetails['HANDLING_TIME'] + 2),
                        "googleProductCategory" => (empty($skuDetails['CATEGORYID']))?$skuDetails['CATEGORYPATH']:$skuDetails['CATEGORYID'],
                        "price" => [
                          "value" => $price['lp'],
                          "currency" => "USD"
                        ]
                      )
                    );


$productObject = new Google_Service_ShoppingContent_ProductsCustomBatchRequest();
$productObject->setEntries($product);

$result = $this->service->products->custombatch($productObject);

错误:

An uncaught Exception was encountered
Type: Error

Message: Call to undefined method Google_Service_ShoppingContent_ProductsCustomBatchRequest::toSimpleObject()

Line Number: 108

Backtrace:

File: vendor/google/apiclient-services/src/Google/Service/ShoppingContent/Resource/Products.php
Line: 40
Function: call
4

1 回答 1

0

您应该使用Google_Service_ShoppingContent_Product将数据插入产品实例,然后您可以使用 custombatch 上传它

 $product = new Google_Service_ShoppingContent_Product();

 $product->setId($id);
 $product->setTitle($title);
于 2019-08-16T11:22:17.877 回答