public static function adjustLowestPriceForProducts($items = false, $verbose = false) { $items = $items ? $items : WPLA_ListingQueryHelper::getItemsWithMinMaxAndLowestPrice(); $changed_product_ids = array(); $repricing_margin = floatval(get_option('wpla_repricing_margin')); $lowest_offer_mode = get_option('wpla_repricing_use_lowest_offer', 0); // loop found listings foreach ($items as $item) { // make sure there is a product - and min/max prices are set (0 != NULL) if (!$item->post_id) { continue; } if (!$item->min_price) { continue; } if (!$item->max_price) { continue; } if (!$item->buybox_price && !$item->compet_price) { continue; } // build target price from BuyBox and/or competitor price if ($item->buybox_price && !$item->has_buybox) { // apply undercut to BuyBox price - if there is a BuyBox price and it's not the seller's $target_price = $item->buybox_price - $repricing_margin; if ($verbose) { wpla_show_message($item->sku . ': Other seller has BuyBox at ' . $item->buybox_price . ' - your target price: ' . $target_price); } } elseif ($item->buybox_price && $item->has_buybox && $item->compet_price) { // decide based on uppricing mode if ($lowest_offer_mode && $item->buybox_price != $item->compet_price) { // seller has BuyBox and there is competition - apply undercut to competitor price (beta) $target_price = $item->compet_price - $repricing_margin; if ($verbose) { wpla_show_message($item->sku . ': You have the BuyBox, but there is a competitor at ' . $item->compet_price . ' - new target price: ' . $target_price); } } else { // seller has BuyBox and there is competition - keep price for now $target_price = $item->buybox_price; if ($verbose) { wpla_show_message($item->sku . ': You have the BuyBox - keeping current price: ' . $target_price); } } } elseif ($item->buybox_price && $item->has_buybox && !$item->compet_price) { // seller has BuyBox and NO competition - fall back to max_price $target_price = $item->max_price; if ($verbose) { wpla_show_message($item->sku . ': You have the BuyBox but there is no competitor - falling back to Max Price: ' . $target_price); } } elseif ($item->compet_price) { $target_price = $item->compet_price; if ($verbose) { wpla_show_message($item->sku . ': No BuyBox price - falling back to next competitor: ' . $target_price); } } else { $target_price = $item->max_price; if ($verbose) { wpla_show_message($item->sku . ': No BuyBox price, no competitor - falling back to Max Price: ' . $target_price); } } $target_price = round($target_price, 2); // update price $price_was_changed = self::updateAmazonPrice($item, $target_price, $verbose); if ($price_was_changed) { $changed_product_ids[] = $item->post_id; WPLA()->logger->info('adjustLowestPriceForProducts() - new price for #' . $item->sku . ': ' . $target_price); } } // foreach item // echo "<pre>";print_r($changed_product_ids);echo"</pre>";#die(); // echo "<pre>";print_r($items);echo"</pre>";die(); return $changed_product_ids; }