I think I have figured it out with the following code for anyone who is
interested!
$adGroupId = 'adgroupid';
$operations1 = [];
// This is creating the root partition
$root = ProductPartitions::createSubdivision();
$criterion = ProductPartitions::asBiddableAdGroupCriterion($adGroupId, $root
);
$operation1 = ProductPartitions::createAddOperation($criterion);
$operations1[] = $operation1;
// This is the product offer unit
$product = new ProductOfferId();
$product->setValue($productid);
$productUnit = ProductPartitions::createUnit($root, $product);
$criterion = ProductPartitions::asBiddableAdGroupCriterion($adGroupId,
$productUnit, 500000);
$operation1 = ProductPartitions::createAddOperation($criterion);
$operations1[] = $operation1;
// Then this is the OTHER part which needs to be added - in this case it is
a all other products excluded
$otherProduct = ProductPartitions::createUnit($root, new ProductOfferId());
$criterion = ProductPartitions::asNegativeAdGroupCriterion($adGroupId,
$otherProduct);
$operation1 = ProductPartitions::createAddOperation($criterion);
$operations1[] = $operation1;
$adGroupCriterionService = $adWordsServices->get($session,
AdGroupCriterionService::class);
$result = $adGroupCriterionService->mutate($operations1);
print_r($result);
On Monday, December 11, 2017 at 9:15:29 AM UTC, David Courtney wrote:
>
> Hi,
>
> I am having trouble adding a new product offer to an existing adgroup. I
> used to do it like this but can't seem to get the code working with the new
> API:
>
>
> $adGroupCriterionService = $user->GetService('AdGroupCriterionService',
> ADWORDS_VERSION);
> $helper = new ProductPartitionHelper($adGroupId);
> $root = $helper->createSubdivision();
>
>
> if (is_array($ids)) { // Then there are options for the item and we
> need to add them all
> foreach ($ids AS $ident) {
> $helper->createUnit($root, new ProductOfferId($ident), 500000);
> }
> } else {
> // Ad Product Partion
> $helper->createUnit($root, new ProductOfferId($id), 500000);
> }
> $helper->createUnit($root,new ProductOfferId(null));
> $result = $adGroupCriterionService->mutate($helper->getOperations());
>
>
> I can't seem to find that specific example in the docs either.
>
> Any help would be appreciated.
>
> Thanks
>
> Dave
>
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/51d59c8a-d264-4595-8606-6b21437f8ae6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.