function amazonShortcode($atts, $content) { // extract attributes extract(shortcode_atts(array('num' => ''), $atts)); // We get $num variable if (empty($num)) { $num = 5; } // define HTML prefix and suffix for displayed App Store Box $preBox = '<hr style="border: 0; height: 0; border-top: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.3);">'; $sufBox = '<hr style="border: 0; height: 0; border-top: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.3);">'; // Require the class file // From https://github.com/chopin2256/Amazon require_once 'Amazon.php'; //Run Amazon $amazon = new Amazon(); //Instantiate Amazon object $kw = $content; //Set keyword $cnt = $num; //Set amazon max results, up to 10 //Set config options $amazon->config()->API_KEY(get_option('amazon_shortc_apikey'))->SECRET_KEY(get_option('amazon_shortc_secretkey'))->associate_tag(get_option('amazon_shortc_associatetag'))->locale(get_option('amazon_shortc_locale'))->maxResults($cnt); //Search for keyword $amazon->search($kw); //Loop through array in for loop to save your Amazon results for ($i = 0; $i < $cnt; $i++) { $result .= amazonLayout($i, $amazon) . $sufBox; } //Clear amazon object $amazon->clear(); //Set and return results, in this case, 5 product titles return $preBox . $result; }
function runAmazon() { $amazon = new Amazon(); //Instantiate Amazon object $kw = "product title"; //Set keyword $cnt = 5; //Set amazon max results, up to 10 //Set config options $amazon->config()->API_KEY('Your API')->SECRET_KEY('Your Secret Key')->associate_tag('associatetag-20')->locale('com')->maxResults($cnt); //Search for keyword $amazon->search($kw); //Loop through array in for loop to save your Amazon results for ($i = 0; $i < $cnt; $i++) { $result .= amazonLayout($i, $amazon); } //Clear amazon object $amazon->clear(); //Set and return results, in this case, 5 product titles echo $result; }
<?php require_once dirname(__FILE__) . '/../inc/init.php'; require_once BASE . 'inc/HTTPClient.php'; require_once BASE . 'inc/Amazon.php'; $AMZ = new Amazon($CONF['public_key'], $CONF['private_key']); $stmt_srch = $PDO->prepare("SELECT *\n FROM search\n WHERE added > datetime('NOW','-90 days')\n AND lastget > datetime('NOW','-5 days')"); $stmt_ins = $PDO->prepare('INSERT OR IGNORE INTO search_results (sid, asin, title, price, url, image, more) VALUES (?,?,?,?,?,?,?)'); $stmt_srch->execute(); while ($row = $stmt_srch->fetch(PDO::FETCH_ASSOC)) { printf("%5s %s\n", $row['region'], $row['query']); $AMZ->setRegion($row['region']); $items = $AMZ->search($row['query']); foreach ($items as $item) { $num = $item->OfferSummary->TotalNew + $item->OfferSummary->TotalUsed + $item->OfferSummary->TotalCollectible + $item->OfferSummary->TotalRefurbished; if (!$num) { continue; } // skip non available products if ($item->OfferSummary->LowestNewPrice->FormattedPrice) { $price = $item->OfferSummary->LowestNewPrice->FormattedPrice . ' (new)'; } else { $price = $item->OfferSummary->LowestUsedPrice->FormattedPrice . ' (used)'; } $stmt_ins->execute(array($row['sid'], $item->ASIN, $item->ItemAttributes->Title, $price, $item->DetailPageURL, $item->MediumImage->URL, $item->EditorialReviews->EditorialReview->Content)); } }