public function action_update_pricing_info() { WPLA()->logger->info("do_action: wpla_update_pricing_info"); $accounts = WPLA_AmazonAccount::getAll(); // $listingsModel = new WPLA_ListingsModel(); $batch_size = 200; // 10 requests per batch (for now - maximum should be 20 requests = 400 items / max. 600 items per minute) foreach ($accounts as $account) { $account_id = $account->id; $listings = WPLA_ListingQueryHelper::getItemsDueForPricingUpdateForAcccount($account_id, $batch_size); $listing_ASINs = array(); WPLA()->logger->info(sprintf('%s items with outdated pricing info found for account %s.', sizeof($listings), $account->title)); // build array of ASINs foreach ($listings as $listing) { // skip duplicate ASINs - they throw an error from Amazon if (in_array($listing->asin, $listing_ASINs)) { continue; } $listing_ASINs[] = $listing->asin; } if (empty($listing_ASINs)) { continue; } // process batches of 20 ASINs for ($page = 0; $page < 10; $page++) { $page_size = 20; // splice ASINs $offset = $page * $page_size; $ASINs_for_this_batch = array_slice($listing_ASINs, $offset, $page_size); if (empty($ASINs_for_this_batch)) { continue; } // run update $this->update_pricing_info_for_asins($ASINs_for_this_batch, $account_id); WPLA()->logger->info(sprintf('%s ASINs had their pricing info updated - account %s.', sizeof($listing_ASINs), $account->title)); } } // each account }