/** * @param array products * @param integer store id * * @return array */ public function productBatchInsert($products, $storeId = null) { $merchantId = $this->getConfig()->getConfigData('account_id', $storeId); $entries = array(); foreach ($products as $itemId => $product) { $product->setChannel("online"); $expDate = date("Y-m-d", time() + 30 * 24 * 60 * 60); //product expires in 30 days $product->setExpirationDate($expDate); $entry = new Google_Service_ShoppingContent_ProductsCustomBatchRequestEntry(); $entry->setBatchId($itemId); $entry->setMerchantId($merchantId); $entry->setMethod('insert'); $entry->setProduct($product); $entries[] = $entry; } $batchReq = new Google_Service_ShoppingContent_ProductsCustomBatchRequest(); $batchReq->setEntries($entries); $result = $this->getShoppingService($storeId)->products->customBatch($batchReq); return $result; }
public function insertProductBatch($products) { $entries = array(); foreach ($products as $key => $product) { $entry = new Google_Service_ShoppingContent_ProductsCustomBatchRequestEntry(); $entry->setMethod('insert'); $entry->setBatchId($key); $entry->setProduct($product); $entry->setMerchantId($this->merchant_id); $entries[] = $entry; } $batch_request = new Google_Service_ShoppingContent_ProductsCustomBatchRequest(); $batch_request->setEntries($entries); $batch_response = $this->service->products->custombatch($batch_request); printf("Inserted %d products.\n", count($batch_response->entries)); foreach ($batch_response->entries as $entry) { if (empty($entry->getErrors())) { $product = $entry->getProduct(); printf("Inserted product %s with %d warnings\n", $product->getOfferId(), count($product->getWarnings())); } else { print "There were errors inserting a product:\n"; foreach ($entry->getErrors()->getErrors() as $error) { printf("\t%s\n", $error->getMessage()); } } } }
public function addEntry($product, $productId) { $entry = new \Google_Service_ShoppingContent_ProductsCustomBatchRequestEntry(); $entry->setBatchId($productId); $entry->setMerchantId($this->merchantId); $entry->setMethod($this->method); if ($this->method !== "insert") { $entry->setProductId($productId); } $entry->setProduct($product); $this->entries[] = $entry; }