Home arrow PHP arrow Page 6 - Using Amazon Web Services With PHP And SOAP (part 2)

Bagging It - PHP

In this concluding article, find out how to add search features to your AWS-backed online store, and link your product pages up to Amazon.com's shopping carts and wish lists.

TABLE OF CONTENTS:
  1. Using Amazon Web Services With PHP And SOAP (part 2)
  2. Rolling The Stones
  3. Searching For Words
  4. Drilling Deeper
  5. Riding The Popularity Metrics
  6. Bagging It
  7. Linking Out
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 21
November 13, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: