googleads-shopping-samples icon indicating copy to clipboard operation
googleads-shopping-samples copied to clipboard

PHP I just need to UPDATE a product (not insert as new)

Open 7starsone opened this issue 2 years ago • 2 comments

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

7starsone avatar Jan 27 '23 19:01 7starsone

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

7starsone avatar Jan 28 '23 08:01 7starsone

There is an update utility but for some reason not mentioned in the docs anywhere

$service->products->update(GOOGLE_MERCHANT_ID,  $productId, $productObj);

Whip avatar Apr 27 '24 05:04 Whip