function addProductPartitionTreeExample(AdWordsUser $user, $adGroupId) {
// Get the AdGroupCriterionService, which loads the required classes.
$adGroupCriterionService = $user->GetService('AdGroupCriterionService',
ADWORDS_VERSION);
$helper = new ProductPartitionHelper($adGroupId);
// The most trivial partition tree has only a unit node as the root:
// $helper->createUnit(null, null, 100000);
$root = $helper->createSubdivision();
$helper->createUnit($root, new ProductCanonicalCondition('NEW'), 200000);
$helper->createUnit($root, new ProductCanonicalCondition('USED'), 100000);
$otherCondition = $helper->createSubdivision($root,
new ProductCanonicalCondition());
$helper->createUnit($otherCondition, new ProductType('shirts'), 200000);
$helper->createUnit($otherCondition, new ProductType('footwear'), 100000);
$otherBrand =
$helper->createSubdivision($otherCondition, new ProductType());
// The value for the bidding category is a fixed ID for the 'Luggage & Bags'
// category. You can retrieve IDs for categories from the ConstantDataService.
// See the 'GetProductCategoryTaxonomy' example for more details.
$helper->createUnit($otherBrand,
new ProductBiddingCategory('BIDDING_CATEGORY_L1',
'-3817140941569278349'), 750000);//for clothes
$helper->createUnit($otherBrand,
new ProductBiddingCategory('BIDDING_CATEGORY_L1'), 110000);
// Make the mutate request.
$result = $adGroupCriterionService->mutate($helper->getOperations());
$children = array();
$rootNode = null;
// For each criterion, make an array containing each of its children
// We always create the parent before the child, so we can rely on that here
foreach ($result->value as $adGroupCriterion) {
$children[$adGroupCriterion->criterion->id] = array();
if (isset($adGroupCriterion->criterion->parentCriterionId)) {
$children[$adGroupCriterion->criterion->parentCriterionId][] =
$adGroupCriterion->criterion;
} else {
$rootNode = $adGroupCriterion->criterion;
}
}
// Show the tree
displayTree($rootNode, $children);
}