/** * @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 deleteProductBatch($offer_ids) { $entries = array(); foreach ($offer_ids as $key => $offer_id) { $entry = new Google_Service_ShoppingContent_ProductsCustomBatchRequestEntry(); $entry->setMethod('delete'); $entry->setBatchId($key); $entry->setProductId($this->buildProductId($offer_id)); $entry->setMerchantId($this->merchant_id); $entries[] = $entry; } $batch_request = new Google_Service_ShoppingContent_ProductsCustomBatchRequest(); $batch_request->setEntries($entries); $batch_responses = $this->service->products->custombatch($batch_request); $errors = 0; foreach ($batch_responses->entries as $entry) { if (!empty($entry->getErrors())) { $errors++; } } print "Requested delete of batch inserted test products\n"; printf("There were %d errors\n", $errors); }
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; }