/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
*/
function AddPromotionExample(AdWordsUser $user, $businessId)
{
// Get the business service, which loads the required classes.
$businessService = $user->GetService('ExpressBusinessService', ADWORDS_VERSION);
// Get the business for the businessId. We will need its geo point
// to create a Proximity criterion for the new Promotion.
$businessSelector = new Selector();
$businessSelector->fields = array('Id', 'GeoPoint');
$businessPredicate = new Predicate('Id', 'EQUALS', array($businessId));
$businessSelector->predicates = array($businessPredicate);
$businessEntries = $businessService->get($businessSelector)->entries;
$business = $businessEntries[0];
// PromotionService requires the businessId on the user.
$user->SetExpressBusinessId($businessId);
// Get the promotion service.
$promotionService = $user->GetService('PromotionService', ADWORDS_VERSION);
// Set up the new Promotion.
$marsTourPromotion = new Promotion();
$budget = new Money();
$budget->microAmount = 1000000;
$marsTourPromotion->name = 'Mars Tour Promotion ' . uniqid();
$marsTourPromotion->status = 'PAUSED';
$marsTourPromotion->destinationUrl = 'http://www.example.com';
$marsTourPromotion->budget = $budget;
$marsTourPromotion->callTrackingEnabled = true;
// Criteria
$criteria = array();
// Criterion - Travel Agency product service
$productService = new ProductService();
$productService->text = 'Travel Agency';
$criteria[] = $productService;
// Criterion - English language
// The ID can be found in the documentation:
// https://developers.google.com/adwords/api/docs/appendix/languagecodes
$language = new Language();
$language->id = 1000;
$criteria[] = $language;
// Criterion - Within 15 miles
$proximity = new Proximity();
$proximity->geoPoint = $business->geoPoint;
$proximity->radiusDistanceUnits = 'MILES';
$proximity->radiusInUnits = 15;
$criteria[] = $proximity;
$marsTourPromotion->criteria = $criteria;
// Creatives
$creatives = array();
$creative1 = new Creative('Standard Mars Trip', 'Fly coach to Mars', 'Free in-flight pretzels');
$creatives[] = $creative1;
$creative2 = new Creative('Deluxe Mars Trip', 'Fly first class to Mars', 'Unlimited powdered orange drink');
$creatives[] = $creative2;
$marsTourPromotion->creatives = $creatives;
$operations = array();
$operation = new PromotionOperation();
$operation->operand = $marsTourPromotion;
$operation->operator = 'ADD';
$operations[] = $operation;
$result = $promotionService->mutate($operations);
$addedPromotion = $result[0];
printf("Added promotion ID %d with name '%s' to business ID %d\n", $addedPromotion->id, $addedPromotion->name, $businessId);
}