Reputation: 64
I am trying to insert products on Google Merchant Center. I am currently using Google API PHP client, and I am unable to find toSimpleObject function in any of the class and class extending it.
$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);
Error:
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
Upvotes: 2
Views: 1714
Reputation: 1
Just in case someone is looking for this 5 years later...
The $productObject->setEntries($entries);
function requires an array of ProductsCustomBatchRequestEntry
, not an array of products.
This is how I sent it:
$batch_request = new Google\Service\ShoppingContent\ProductsCustomBatchRequest();
$entries = [];
// $google_products are an array of Google\Service\ShoppingContent\Product
foreach ($google_products as $key => $google_product) {
$batch_entry = new Google\Service\ShoppingContent\ProductsCustomBatchRequestEntry();
$batch_entry->setProduct($google_product);
$batch_entry->setMerchantId({{your merchant id}});
$batch_entry->setMethod('insert');
$batch_entry->setBatchId($key);
$entries[] = $batch_entry;
}
$batch_request->setEntries($entries);
Upvotes: 0
Reputation: 1
You should be using Google_Service_ShoppingContent_Product
to insert data to your product instance then you can use custombatch to upload it
$product = new Google_Service_ShoppingContent_Product();
$product->setId($id);
$product->setTitle($title);
Upvotes: 0