PHP
  Home arrow PHP arrow Page 6 - Using Amazon Web Services With PHP And...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway