PHP
  Home arrow PHP arrow Page 6 - Using Amazon Web Services With PHP And SOAP (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Using Amazon Web Services With PHP And SOAP (part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 21
    2002-11-13


    Table of Contents:
  • Using Amazon Web Services With PHP And SOAP (part 2)
  • Rolling The Stones
  • Searching For Words
  • Drilling Deeper
  • Riding The Popularity Metrics
  • Bagging It
  • Linking Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Amazon Web Services With PHP And SOAP (part 2) - Bagging It
    ( Page 6 of 7 )

    Finally, after providing you with the API to build a product catalog, search for products, and obtain detailed product descriptions, AWS rounds things out by allowing you an entry point into Amazon's transaction system, providing constructs to add products to an Amazon.com shopping cart or wish list.

    For the first time in a while, accomplishing this doesn't involve using any special SOAP commands - all you need is a plain ol' HTML form, containing certain mandatory fields.

    <form method="POST" action="http://www.amazon.com/o/dt/assoc/handle-buy-box=<ASIN>"> <input type="hidden" name="asin. <ASIN>" value="1"> <input type="hidden" name="tag-value" value="<YOUR-ASSOCIATES-ID>"> <input type="hidden" name="tag_value" value="<YOUR-ASSOCIATES-ID>"> <input type="hidden" name="dev-tag-value" value="<YOUR-TOKEN>"> <input type="submit" name="submit.add-to-cart" value="Buy From Amazon.com"> or <input type="submit" name="submit.add-to-registry.wishlist" value="Add to Amazon.com Wish List"> </form>
    So, if you wanted to place a "Buy!" link on each product page for the book "XML and PHP" - Amazon.com ASIN 0735712271 - your form would look like this:

    <form method="POST" action="http://www.amazon.com/o/dt/assoc/handle-buy-box=0735712271"> <input type="hidden" name="asin.0735712271" value="1"> <input type="hidden" name="tag-value" value="melonfire-20"> <input type="hidden" name="tag_value" value="melonfire-20"> <input type="hidden" name="dev-tag-value" value="YOUR-TOKEN-HERE"> <input type="submit" name="submit.add-to-cart" value="Buy From Amazon.com"> or <input type="submit" name="submit.add-to-registry.wishlist" value="Add to Amazon.com Wish List"> </form>
    Needless to say, it's pretty easy to incorporate this into the product information page designed in the previous example - here's the script:

    <?php // include class include("nusoap.php"); // create a instance of the SOAP client object $soapclient = new soapclient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl", true); // create a proxy so that WSDL methods can be accessed directly $proxy = $soapclient->getProxy(); // format ASIN to ten-character format $asin = sprintf("%010d", $_GET['asin']); // set up an array containing input parameters to be // passed to the remote procedure $params = array( 'asin' => $asin, 'mode' => 'books', 'tag' => 'melonfire-20', 'type' => 'heavy', 'devtag' => 'YOUR-TOKEN-HERE' ); // get item details $result = $proxy->ASINSearchRequest($params); $items = $result['Details']; // get list of similar items $simResult = $proxy->SimilaritySearchRequest($params); $simItems = $simResult['Details']; // display the result ?> <html> <head> <basefont face="Verdana"> </head> <body bgcolor="white"> <p>&nbsp;<p> <table width="100%" cellspacing="0" cellpadding="5"> <tr> <td bgcolor="Navy"><font color="white" size="-1"><b>Welcome to The Mystery Bookstore!</b></font></td> <td bgcolor="Navy" align="right"><font color="white" size="-1"><b><? echo date("d M Y", mktime());?></b></font></td> </tr> </table> <p> <table width="100%" border="0" cellspacing="5" cellpadding="0"> <tr> <td align="center" valign="top" rowspan="8"><a href="<? echo $items[0]['Url']; ?>"><img border="0" src=<? echo $items[0]['ImageUrlMedium']; ?>></a></td> <td><font size="-1"><b><? echo $items[0]['ProductName']; ?></b></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1">List Price: <? echo $items[0]['ListPrice']; ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1">Amazon.com Price: <? echo $items[0]['OurPrice']; ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1">Publisher: <? echo $items[0]['Manufacturer']; ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1">Availability: <? echo $items[0]['Availability']; ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1">Amazon.com sales rank: <? echo $items[0]['SalesRank']; ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1">Average customer rating: <? echo $items[0]['Reviews']['AvgCustomerRating']; ?></font></td> </tr> <tr> <td align="left" valign="top"><font size="-1"> <form method="POST" action="http://www.amazon.com/o/dt/assoc/handle-buy-box=<? echo $asin; ?>"> <input type="hidden" name="asin.<? echo $asin; ?>" value="1"> <input type="hidden" name="tag-value" value="melonfire-20"> <input type="hidden" name="tag_value" value="melonfire-20"> <input type="hidden" name="dev-tag-value" value="YOUR-TOKEN-HERE"> <input type="submit" name="submit.add-to-cart" value="Buy From Amazon.com"> or <input type="submit" name="submit.add-to-registry.wishlist" value="Add to Amazon.com Wish List"> </form></font> </td> </tr> <tr> <td colspan="2"> <font size="-1"> <hr> <? foreach($items[0]['Reviews']['CustomerReviews'] as $r) { ?> <b><? echo $r['Summary']; ?></b> <br> <? echo $r['Comment']; ?> <hr> <? } ?> </font> </td> </tr> <tr> <td colspan="2"> <font size="-1"> Customers who shopped for this item also bought: <ul> <? foreach($simItems as $s) { echo "<li><a href="" . $_SERVER['PHP_SELF'] . "?asin=" . $s['Asin'] . "">" . $s['ProductName'] . "</a>"; } ?> </ul></font> </td> </tr> </table> </body> </html>
    And here's an example of the page generated:



    Clicking either of the form buttons will redirect the user to Amazon.com, where the selected item gets added to a shopping cart/wish list. Consummating the transaction is currently outside the scope of AWS, and is handled by the main Amazon.com site; if you're an Amazon.com Associate, your account will get credited with appropriate commission, since the URL passed to Amazon.com includes your Associate ID. It all fits together pretty neatly.

     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT