function AmazonWooCommerceamazon_request_callback() { global $AmazonWooCommerce; $amazon_settings = $AmazonWooCommerce->getAllSettings('array', 'amazon'); $plugin_uri = $AmazonWooCommerce->cfg['paths']['plugin_dir_url'] . 'modules/amazon/'; $requestData = array('search' => isset($_REQUEST['search']) ? htmlentities($_REQUEST['search']) : '', 'category' => isset($_REQUEST['category']) ? htmlentities($_REQUEST['category']) : '', 'page' => isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : ''); // load the amazon webservices client class require_once $AmazonWooCommerce->cfg['paths']['plugin_dir_path'] . '/lib/scripts/amazon/aaAmazonWS.class.php'; // create new amazon instance $aaAmazonWS = new aaAmazonWS($amazon_settings['AccessKeyID'], $amazon_settings['SecretAccessKey'], $amazon_settings['country'], $amazon_settings['AffiliateId']); // changing the category to {$requestData['category']} and the response to only images and looking for some matrix stuff. $response = $aaAmazonWS->category($requestData['category'])->page($requestData['page'])->responseGroup('Large')->search($requestData['search']); // print some debug if requested if ($_GET['dump'] == 1 && is_admin()) { var_dump('<pre>', $requestData, $response, '</pre>'); die; } if ($response['Items']['Request']['IsValid'] == 'False') { die('<div class="error" style="float: left;margin: 10px;padding: 6px;">BDA Amazon error id: <bold>' . $response['Items']['Request']['Errors']['Error']['Code'] . '</bold>: <br /> ' . $response['Items']['Request']['Errors']['Error']['Message'] . '</div>'); } elseif (count($response['Items']) > 0) { if ($response['Items']['TotalResults'] > 1) { ?> <div class="resultsTopBar"> <h2> Showing <?php echo $requestData['page']; ?> - <?php echo $response['Items']["TotalPages"]; ?> of <span id="AmazonWooCommerce-totalPages"><?php echo $response['Items']["TotalResults"]; ?> </span> Results </h2> <div class="AmazonWooCommerce-pagination"> <span>View page:</span> <select id="AmazonWooCommerce-page"> <?php for ($p = 1; $p <= 5; $p++) { echo '<option value="' . $p . '" ' . ($p == $requestData['page'] ? 'selected' : '') . '> ' . $p . ' </option>'; } ?> </select> </div> </div> <?php } // don't show paging if total results it's not bigget than 1 if (count($response['Items']['Item']) > 0) { echo ' <div class="AmazonWooCommerce-product-box"> <table class="product"> '; $cc = 0; foreach ($response['Items']['Item'] as $key => $value) { if ($response['Items']['TotalResults'] == 1) { $value = $response['Items']['Item']; if ($_REQUEST['dump'] == 1) { var_dump('<pre>', $value, '</pre>'); die; } } if ($cc + 1 > $response['Items']['TotalResults']) { continue; } $thumb = $value['SmallImage']['URL']; if (trim($thumb) == "") { // try to find image as first image from image sets $thumb = $value['ImageSets']['ImageSet'][0]['SmallImage']['URL']; } ?> <tr> <td class="product-number"><?php echo ++$cc; ?> .</td> <td class="product-image"> <a href="<?php echo $value['DetailPageURL']; ?> " target="_blank"> <img class="productImage" src="<?php echo $thumb; ?> "> </a> </td> <td class="product-data"> <h4 class="product-title"> <a href="<?php echo $value['DetailPageURL']; ?> " target="_blank"><?php echo $value['ItemAttributes']['Title']; ?> </a> </h4> <div class="newPrice"> <span class="price"><?php echo $value['Offers']['Offer']['OfferListing']['Price']['FormattedPrice']; ?> </span> </div> <div class="product-description"><?php echo $value['EditorialReviews']['EditorialReview']['Content']; ?> </div> </td> <td class="product-options"> <?php if ($value['CustomerReviews']['HasReviews'] == true) { echo '<a class="thickbox AmazonWooCommerce-option-btn" href="' . $value['CustomerReviews']['IFrameURL'] . '&TB_iframe=true"> <img src="' . $plugin_uri . 'assets/comments.png" /> Customer Reviews</a>'; } ?> <a class="AmazonWooCommerce-option-btn AmazonWooCommerce-load-product" href="#" rel="<?php echo $value['ASIN']; ?> "><img src="<?php echo $plugin_uri; ?> assets/update.png" /> Load this product </a> <td> </tr> <?php } // end foreach echo '</table></div>'; // close the table } // end if have products } die; // this is required to return a proper result }