Im Currently developing in the adwords SDK. Im querying whether the products are in stock from the database and setting the ad to either paused or enabled.
Now in my while loop i have an IF statement that is currently always firing true for some reason. I think maybe its only using the first value and not looping through $stock, if thats the case any ideas?
I need it to run through each stock status. IF 'In Stock' post enabled else set it to paused
Heres the code
$sql = "SELECT * FROM aavps_adcontrol.ad_assign" ;
$result = mysqli_query($conn, $sql);
if ($result) {
while($row = mysqli_fetch_array($result))
{
$adGroup = $row['adgroup'];
$adGroupId = $row['adgroup_id'];
$product = $row['product'];
$stock = $row['stock'];
$client = $row['client'];
if ($stock === "In Stock") {
if(!function_exists('UpdateAdGroupExample')){
function UpdateAdGroupExample(AdWordsUser $user, $adGroupId) {
// Get the service, which loads the required classes.
$adGroupService = $user->GetService('AdGroupService', ADWORDS_VERSION);
// Create ad group using an existing ID.
$adGroup = new AdGroup();
$adGroup->id = $adGroupId;
// Update the status.
$adGroup->status = 'ENABLED';
// Create operation.
$operation = new AdGroupOperation();
$operation->operand = $adGroup;
$operation->operator = 'SET';
$operations = array($operation);
// Make the mutate request.
$result = $adGroupService->mutate($operations);
// Display result.
$adGroup = $result->value[0];
printf("Ad group with ID '%s' has updated default bid '$%s'.\n", $adGroup->id,
$adGroup->status);
}
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
$user->SetClientCustomerId('2778207914');
// Log every SOAP XML request and response.
$user->LogAll();
// Run the example.
UpdateAdGroupExample($user, $adGroupId);
} catch (Exception $e) {
printf("An error has occurred: %s\n", $e->getMessage());
}
}
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
$user->SetClientCustomerId('2778207914');
// Log every SOAP XML request and response.
$user->LogAll();
// Run the example.
UpdateAdGroupExample($user, $adGroupId);
} catch (Exception $e) {
printf("An error has occurred: %s\n", $e->getMessage());
}
Aucun commentaire:
Enregistrer un commentaire