Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
7starsone opened this issue Jan 27, 2023 · 2 comments
Open

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

7starsone opened this issue Jan 27, 2023 · 2 comments

Comments

@7starsone
Copy link

7starsone commented Jan 27, 2023

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
Copy link
Author

7starsone commented Jan 28, 2023

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

@Whip
Copy link

Whip commented Apr 27, 2024

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants