Home arrow PHP arrow Page 9 - Using Amazon Web Services With PHP And SOAP (part 1)

Hooking Up - PHP

It's the coolest store on the Web - and now, its databases are accessible to you. Welcome to Amazon Web Services, an XML-based API that allows you to quickly build an online store that leverages off Amazon.com's massive databases. Find out more, inside.

  1. Using Amazon Web Services With PHP And SOAP (part 1)
  2. Remote Control
  3. The Bare Necessities
  4. Anatomy Class
  5. The Bookworm Turns
  6. Sorting Things Out
  7. Turning The Pages
  8. Weapon Of Choice
  9. Hooking Up
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 103
November 06, 2002

print this article


The ASINSearchRequest() method, combined with the AWS "heavy" data format, makes it easy to build detailed product information pages that are similar to the originals on Amazon.com. Consider the following revision to the example on the previous page, which accepts an ASIN on the URL and returns a neatly-formatted product information page:

<?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); // uncomment the next line to see debug messages // $soapclient->debug_flag = 1; // create a proxy so that WSDL methods can be accessed directly $proxy = $soapclient->getProxy(); // set up an array containing input parameters to be // passed to the remote procedure $params = array( 'asin' => sprintf("%010d", $_GET['asin']), 'tag' => 'melonfire-20', 'type' => 'heavy', 'devtag' => 'YOUR-TOKEN-HERE' ); // invoke the method $result = $proxy->ASINSearchRequest($params); $items = $result['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="7"><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> / <? echo implode(", ", $items[0]['Authors']); ?></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 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> </table> <font size="-1"> Disclaimer: All product data on this page belongs to Amazon.com. No guarantees are made as to accuracy of prices and information. YMMV! </font> </body> </html>
Here's what it looks like:

Pretty cool, huh?

Now here's something for you to think about. Remember how, a few pages back, I built a product catalog with the BrowseNodeSearchRequest() method and linked each item in that catalog to the actual product page on Amazon.com? Well, with the ASINSearchRequest() method, you no longer need to link to Amazon.com for detailed product information - you can generate it yourself! Simply alter the links in the product catalog to point to the PHP script above, send the script the ASIN via the GET method, and you can provide your visitors with detailed product information on your own site.

I'll leave this last to you as an exercise. Give it a shot, and come back next week for the second part of this article, when I'll be showing you how to add search capabilities to your rapidly-evolving online store. See you then!

Note: All examples in this article have been tested on Linux/i586 with Apache 1.3.24, PHP 4.2.3, NuSOAP 6.3 and AWS 2.0. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. All product data in this article belongs to Amazon.com. YMMV!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: