$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());$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);