コード例 #1
0
 public function update_pricing_info_for_asins($listing_ASINs, $account_id)
 {
     $listingsModel = new WPLA_ListingsModel();
     // fetch Buy Box pricing info and process result
     $api = new WPLA_AmazonAPI($account_id);
     $result = $api->getCompetitivePricingForId($listing_ASINs);
     $listingsModel->processBuyBoxPricingResult($result);
     // return if lowest offers are disabled
     // if ( ! get_option('wpla_repricing_use_lowest_offer') ) return;
     // fetch Lowest Offer info and process result
     $api = new WPLA_AmazonAPI($account_id);
     $result = $api->getLowestOfferListingsForASIN($listing_ASINs);
     $listingsModel->processLowestOfferPricingResult($result);
 }
コード例 #2
0
 public function populateMatchesWithLowestPrices($products, $account)
 {
     // build array of ASINs
     $listing_ASINs = array();
     foreach ($products as $product) {
         if (sizeof($listing_ASINs) == 20) {
             continue;
         }
         $listing_ASINs[] = $product->ASIN;
     }
     if (!empty($listing_ASINs)) {
         $api = new WPLA_AmazonAPI($account->id);
         $result = $api->getCompetitivePricingForId($listing_ASINs);
         $ASIN_to_lowest_price = array();
         foreach ($result->products as $asin => $product) {
             $lowest_price = PHP_INT_MAX;
             foreach ($product->prices as $price) {
                 // $lowest_price = $price->LandedPrice;
                 // $condition    = $price->condition;
                 // $subcondition = $price->subcondition;
                 // $shipping_fee = $price->Shipping;
                 if ($price->LandedPrice < $lowest_price) {
                     if ($price->condition == 'New') {
                         $lowest_price = $price->LandedPrice;
                     }
                 }
             }
             // each pricing node
             if ($lowest_price != PHP_INT_MAX) {
                 $ASIN_to_lowest_price[$product->ASIN] = $lowest_price;
             }
         }
         // each product
     }
     foreach ($products as &$product) {
         if (isset($ASIN_to_lowest_price[$product->ASIN])) {
             $product->lowest_price = $ASIN_to_lowest_price[$product->ASIN];
         } else {
             $product->lowest_price = false;
         }
     }
     // echo "<pre>FINAL: ";print_r($products);echo"</pre>";#die();
     return $products;
 }
コード例 #3
0
 public function updateListingWithLowestPrice($listing, $account)
 {
     // get listing object
     $lm = new WPLA_ListingsModel();
     $listing = $lm->getItem($listing['id'], OBJECT);
     // fetch pricing info
     $api = new WPLA_AmazonAPI($account->id);
     $result = $api->getCompetitivePricingForId(array($listing->asin));
     if (empty($result) || empty($result->products) || !is_array($result->products)) {
         return;
     }
     // find lowest New price
     $product = reset($result->products);
     // get first product
     $lowest_price = PHP_INT_MAX;
     foreach ($product->prices as $price) {
         if ($price->LandedPrice < $lowest_price) {
             if ($price->condition == 'New') {
                 $lowest_price = $price->LandedPrice;
             }
         }
     }
     // each pricing node
     if ($lowest_price == PHP_INT_MAX) {
         return;
     }
     // update listing
     $lm->updateListing($listing->id, array('price' => $lowest_price));
 }
コード例 #4
0
 public function get_compet_price()
 {
     if (!isset($_REQUEST['listing'])) {
         return;
     }
     // get items
     $listing_ids = is_array($_REQUEST['listing']) ? $_REQUEST['listing'] : array($_REQUEST['listing']);
     if (!empty($listing_ids)) {
         $listingsModel = new WPLA_ListingsModel();
         $listings = WPLA_ListingsModel::getItems($listing_ids, OBJECT);
         $account_id = $listings[0]->account_id;
         // echo "<pre>";print_r($listings);echo"</pre>";die();
         // build array of ASINs
         $listing_ASINs = array();
         foreach ($listings as $listing) {
             // prevent invalid marketplace errors
             if ($account_id != $listing->account_id) {
                 $this->showMessage('You can only fetch pricing information from one account at a time. Item ' . $listing->asin . ' was skipped.', 1, 1);
                 continue;
             }
             $listing_ASINs[] = $listing->asin;
         }
         // limit to 20 ASINs at a time - for now
         if (sizeof($listing_ASINs) > 20) {
             $listing_ASINs = array_splice($listing_ASINs, 0, 20);
             $this->showMessage('You can only fetch pricing information for up to 20 ASINs at a time.', 2, 1);
         }
         if (!empty($listing_ASINs)) {
             $api = new WPLA_AmazonAPI($account_id);
             $result = $api->getCompetitivePricingForId($listing_ASINs);
             // echo "<pre>";print_r($result);echo"</pre>";
             if ($result->success) {
                 $message = '';
                 foreach ($result->products as $asin => $product) {
                     foreach ($product->prices as $price) {
                         $lowest_price = $price->LandedPrice;
                         $condition = $price->condition;
                         $subcondition = $price->subcondition;
                         $shipping_fee = $price->Shipping;
                         $shipping_msg = $shipping_fee ? "incl. {$shipping_fee} shipping" : 'free shipping';
                         $lowest_price = number_format_i18n(floatval($lowest_price), 2);
                         $message .= sprintf('BuyBox price for %s: %s ( %s / %s / %s )<br>', $asin, $lowest_price, $condition, $subcondition, $shipping_msg);
                     }
                     if (empty($product->prices)) {
                         $message .= sprintf('No Buy Box price found for %s<br>', $asin);
                     }
                 }
                 wpla_show_message($message);
             }
             // process result
             $listingsModel->processBuyBoxPricingResult($result);
         }
     }
 }