Services_Amazon
[ class tree: Services_Amazon ] [ index: Services_Amazon ] [ all elements ]

Source for file amazon_ecs4_itemsearch.php

Documentation is available at amazon_ecs4_itemsearch.php

  1. <?php
  2. //
  3. // Example of usage for Services_AmazonECS4
  4. //
  5.  
  6. require_once 'PEAR.php';
  7. require_once 'Services/AmazonECS4.php';
  8.  
  9. echo <<<EOT
  10. <html>
  11. <head>
  12.     <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
  13.     <title>Services_AmazonECS4 example</title>
  14. </head>
  15. <body>
  16. <h1>Amazon ECS4 example - ItemSearch Operation</h1>
  17. <p>
  18. <a href="http://www.amazon.com/gp/aws/sdk/" target="_blank">Amazon.com Help: Documentation</a><br />
  19. <a href="http://www.amazon.com/gp/aws/sdk/main.html/?s=AWSEcommerceService&v=2005-07-26&p=ApiReference/ItemSearchOperation" target="_blank">Amazon ECS4.0 API Reference - ItemSearch Operation</a>
  20. </p>
  21. EOT;
  22.  
  23. $subid $_GET['subid'];
  24.  
  25. $amazon = new Services_AmazonECS4($subid$_GET['associd']);
  26.  
  27. // Locale
  28. if (isset($_GET['locale'])) {
  29.     $amazon->setLocale($_GET['locale']);
  30. }
  31.  
  32. // ItemSearch Operation
  33. if (!empty($subid&& $subid != 'your ID here'{
  34.     $options = array();
  35.     foreach ($_GET as $k => $v{
  36.         if ($k == 'subid' || $k == 'associd' || $k == 'locale'{
  37.             continue;
  38.         else if ($k == 'SearchIndex'{
  39.             $search_index $v;
  40.         else if ($k == 'ResponseGroup'{
  41.             foreach ($_GET['ResponseGroup'as $v{
  42.                 if (isset($ResponseGroup)) {
  43.                     $ResponseGroup .= ',' $v;
  44.                 else {
  45.                     $ResponseGroup $v;
  46.                 }
  47.             }
  48.             $options['ResponseGroup'$ResponseGroup;
  49.         else {
  50.             if (!empty($v)) {
  51.                 $options[$k$v;
  52.             }
  53.         }
  54.     }
  55.  
  56.     $result $amazon->ItemSearch($search_index$options);
  57.  
  58. else {
  59.     $subid 'your ID here';
  60. }
  61.  
  62.  
  63. // The list of all available search indexes can be found on the
  64. // "Amazon ECS API Reference - Search Index Values"
  65. // (http://www.amazon.com/gp/aws/sdk/main.html/?s=AWSEcommerceService&v=2005-07-26&p=ApiReference/SearchIndexValues).
  66. $search_indexes = array('Apparel''Baby''Beauty''Books''Classical''DigitalMusic',
  67.                         'DVD''Electronics''ForeignBooks''GourmetFood''HealthPersonalCare',
  68.                         'HomeGarden''Jewelry''Kitchen''Magazines''Merchants',
  69.                         'Miscellaneous''Music''MusicalInstruments''MusicTracks',
  70.                         'OfficeProducts''OutdoorLiving''PCHardware''PetSupplies',
  71.                         'Photo''Restaurants''Software''SoftwareVideoGames',
  72.                         'SportingGoods''Tools''Toys''VHS''Video''VideoGames',
  73.                         'Wireless''WirelessAccessories''Blended');
  74.  
  75. echo <<< EOT
  76. <form action="{$_SERVER['PHP_SELF']}" method="get">
  77. <table border="0">
  78. <tr>
  79.     <td>
  80.     Locale: 
  81.     <select name="locale">
  82. EOT;
  83.  
  84. $locales = array('US''UK''DE''JP''FR''CA');
  85. foreach($locales as $v{
  86.     echo '<option value="' $v ($v == $_GET['locale''" selected="selected"' '''">' $v '</option>';
  87. }
  88.  
  89. echo <<< EOT
  90.     </select>
  91.     <td>
  92. </tr>
  93. <tr>
  94.     <td>Subscription ID <input type="text" name="subid" value="{$subid}" size="30" /></td>
  95. </tr>
  96. <tr>
  97.     <td>Associate ID <input type="text" name="associd" value="{$_GET['associd']}" /></td>
  98. </tr>
  99. <tr>
  100.     <td>
  101.     Search Index <select name="SearchIndex">
  102. EOT;
  103.  
  104. foreach($search_indexes as $v{
  105.     echo '<option value="' $v ($v == $_GET['SearchIndex''" selected="selected"' '''">' $v '</option>';
  106. }
  107.  
  108. echo <<< EOT
  109.     </select>
  110.     </td>
  111. </tr>
  112. <tr>
  113.     <td>Keywords <input type="text" name="Keywords" value="{$_GET['Keywords']}" /></td>
  114. </tr>
  115. <tr>
  116.     <td>
  117.     <table border="0">
  118.     <tr>
  119.         <td>Title<br/><input type="text" name="Title" value="{$_GET['Title']}" /></td>
  120.         <td>Artist<br/><input type="text" name="Artist" value="{$_GET['Artist']}" /></td>
  121.         <td>Author<br/><input type="text" name="Author" value="{$_GET['Author']}" /></td>
  122.         <td>Actor<br/><input type="text" name="Actor" value="{$_GET['Actor']}" /></td>
  123.     </tr>
  124.     <tr>
  125.         <td>Director<br/><input type="text" name="Director" value="{$_GET['Director']}" /></td>
  126.         <td>Manufacturer<br/><input type="text" name="Manufacturer" value="{$_GET['Manufacturer']}" /></td>
  127.         <td>MusicLabel<br/><input type="text" name="MusicLabel" value="{$_GET['MusicLabel']}" /></td>
  128.         <td>Composer<br/><input type="text" name="Composer" value="{$_GET['Composer']}" /></td>
  129.     </tr>
  130.     <tr>
  131.         <td>Publisher<br/><input type="text" name="Publisher" value="{$_GET['Publisher']}" /></td>
  132.         <td>Brand<br/><input type="text" name="Brand" value="{$_GET['Brand']}" /></td>
  133.         <td>Conductor<br/><input type="text" name="Conductor" value="{$_GET['Conductor']}" /></td>
  134.         <td>Orchestra<br/><input type="text" name="Orchestra" value="{$_GET['Orchestra']}" /></td>
  135.     </tr>
  136.     </table>
  137.     </td>
  138. </tr>
  139. <tr>
  140.     <td>Power <input type="text" name="Power" value="{$_GET['Power']}" size="80" /></td>
  141. </tr>
  142. <tr>
  143.     <td>BrowseNode <input type="text" name="BrowseNode" value="{$_GET['BrowseNode']}" /></td>
  144. </tr>
  145. <tr>
  146.     <td>AudienceRating <input type="text" name="AudienceRating" value="{$_GET['AudienceRating']}" /></td>
  147. </tr>
  148. <tr>
  149.     <td>
  150.     TextStream <br/>
  151.     <textarea name="TextStream" cols="64" rows="4">{$_GET['TextStream']}</textarea>
  152.     </td>
  153. </tr>
  154. <tr>
  155.     <td>ItemPage <input type="text" name="ItemPage" value="{$_GET['ItemPage']}" /></td>
  156. </tr>
  157. <tr>
  158.     <td>Sort <input type="text" name="Sort" value="{$_GET['Sort']}" /></td>
  159. </tr>
  160. <tr>
  161.     <td>MinimumPrice <input type="text" name="MinimumPrice" value="{$_GET['MinimumPrice']}" /></td>
  162. </tr>
  163. <tr>
  164.     <td>MaximumPrice <input type="text" name="MaximumPrice" value="{$_GET['MaximumPrice']}" /></td>
  165. </tr>
  166. <tr>
  167.     <td>
  168.     Condition
  169.     <select name="Condition">
  170. EOT;
  171.  
  172. $conditions = array('''New''All''Used''Refurbished''Collectible');
  173.  
  174. foreach ($conditions as $v{
  175.     echo '<option value="' $v ($v == $_GET['Condition''" selected="selected"' '''">' $v '</option>';
  176. }
  177.  
  178. echo <<< EOT
  179.     </select>
  180.     </td>
  181. </tr>
  182. <tr>
  183.     <td>
  184.     ResponseGroup<br/>
  185. EOT;
  186.  
  187. $response_groups = array('Request''ItemIds''Small''Medium''Large''OfferFull''Offers',
  188.                          'OfferSummary''Variations''VariationMinimum''VariationSummary',
  189.                          'ItemAttributes''Tracks''Accessories''EditorialReview',
  190.                          'SalesRank''BrowseNodes''Images''Similarities''ListmaniaLists',
  191.                          'SearchBins''Subjects');
  192.  
  193. foreach ($response_groups as $v{
  194.     echo '<input type="checkbox" name="ResponseGroup[]" value="' $v '" ' (@in_array($v$_GET['ResponseGroup']'checked="checked"' '''/>' $v ' ';
  195. }
  196.  
  197. echo <<< EOT
  198.     </td>
  199. </tr>
  200. <tr>
  201.     <td><input type="submit" value="Search" /></td>
  202. </tr>
  203. </table>
  204. </form>
  205.  
  206. EOT;
  207.  
  208. // examples
  209. echo <<< EOT
  210. <table border="0">
  211. <tr>
  212.     <td>Examples:</td>
  213.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=Books&Keywords=php&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small">Keywords</a></td>
  214.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=Books&Keywords=php&ItemPage=2&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Medium">ItemPage</a></td>
  215.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=Blended&Keywords=teletubbies&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small">Blended</a></td>
  216.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=Books&Power=%28subject%3A+sushi+or+pizza%29+and+pubdate%3A+after+2000&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">Power</a></td>
  217.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=Electronics&BrowseNode=595046&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small&ResponseGroup%5B%5D=ItemAttributes">BrowseNode</a></td>
  218.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=Electronics&BrowseNode=301187&Sort=salesrank&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">Sort</a></td>
  219.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=Books&Keywords=programming&MinimumPrice=5000&MaximumPrice=10000&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=Small&ResponseGroup%5B%5D=OfferSummary">Price</a></td>
  220.     <td><a href="{$_SERVER['PHP_SELF']}?subid={$_GET['subid']}&SearchIndex=DVD&AudienceRating=PG-13&ResponseGroup%5B%5D=Request&ResponseGroup%5B%5D=ItemAttributes">AudienceRating</a></td>
  221. </tr>
  222. </table>
  223.  
  224. <hr/>
  225. EOT;
  226.  
  227. // REST request
  228. $lasturl $amazon->getLastUrl();
  229. echo '<p>REST request:<br/>';
  230. echo '<a href="' $lasturl '" target="_blank">' ereg_replace('&''<br/>&'$lasturl.  '</a></p>';
  231.  
  232. if (PEAR::isError($result)) {
  233.     // Error
  234.     echo '<p>Error:<br/>';
  235.     echo $result->message;
  236.     echo '</p>';
  237. else {
  238.  
  239.     // Processing Time
  240.     echo '<p>Processing Time: ' $amazon->getProcessingTime('sec</p>';
  241.  
  242.     // Result
  243.     echo '<p>Result:';
  244.     var_dump($result);
  245.     echo '</p>';
  246. }
  247.  
  248. echo <<< EOT
  249. </body>
  250. </html>
  251. EOT;
  252.  
  253. ?>

Documentation generated on Mon, 11 Mar 2019 14:13:44 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.