googleads-shopping-samples
googleads-shopping-samples copied to clipboard
PHP I just need to UPDATE a product (not insert as new)
Hello, please, how to update availability and ExcludedDestinations?
public function updateProduct(
Google_Service_ShoppingContent_Product $product) {
// Let's add a product_type and update the product
$product->setProductTypes(['English/Classics']);
// Notice that we use insert. The products service does not have an update
// method. Inserting a product with an ID that already exists means the same
// as doing an update anyway.
$response = $this->session->service->products->insert(
$this->session->merchantId, $product);
printf ("Product updated: %s \n", $response->getId());
}
Please, how to use that to update a single product by ID?
If I do something like:
$product = new Google_Service_ShoppingContent_Product();
$product->setOfferId($offerId);
$product->setContentLanguage('de');
$product->setTargetCountry('DE');
$product->setChannel('online');
$product->setAvailability('out_of_stock');
$product->setExcludedDestinations('Shopping_ads');
$feedId=100786xxxxx;
$response = $this->session->service->products->insert(
$this->session->merchantId, $product, $feedId);
inside the function... IT complaints about service parameter missing
How to fix? Thanks
Maybe understood. At first I need to get a specific product, then pass it to the update function, then I don't know why you need to product->setSource(null), otherwise error on log [product.source] INSERT request must not specify product.source
There is an update utility but for some reason not mentioned in the docs anywhere
$service->products->update(GOOGLE_MERCHANT_ID, $productId, $productObj);