Using Amazon Web Services With PHP And SOAP (part 2) - Riding The Popularity Metrics (
Page 5 of 7 )
One of the things I've always
liked about Amazon.com is its recommendations system - each time a customer makes
a purchase, the Amazon.com system registers it and, keeping the customer's past
purchases in context, evolves a database of customer likes and dislikes. This
database is then used to provide other customers with a list of similar items
("...customers who purchased this item also bought..."), thereby serving the role
of a very experienced sales person. It's a great system, works like a charm...and
is now available to you via the AWS SimilaritySearchRequest() call.
In order to demonstrate how this works, consider the following 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);
//
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']),
'mode'
=> 'books',
'tag' => 'melonfire-20',
'type'
=> 'heavy',
'devtag' => 'YOUR-TOKEN-HERE'
);
// invoke the method
$result = $proxy->ASINSearchRequest($params);
$items = $result['Details'];
$simResult
= $proxy->SimilaritySearchRequest($params);
$simItems = $simResult['Details'];
//
display the result
?>
<html>
<head>
<basefont face="Verdana">
</head>
<body
bgcolor="white">
<p> <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></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>
<tr>
<td colspan="2">
<font
size="-1">
Customers who shopped for this item also bought:
<ul>
<?
foreach($simItems
as $s)
{
echo "<li><a href="" . $s['Url'] . "">" . $s['ProductName'] .
"</a>";
} ?> </ul></font> </td> </tr> </table>
</body>
</html>
The key to this script is the SimilaritySearchRequest() method call - this method
accepts an ASIN (Amazon.com's unique code for each product) and returns a list
of similar items, based on Amazon's customer purchase statistics, together with
brief descriptive information. This information can then be formatted and displayed
as a neat little addition to your product catalog - exactly what I've done above
With the addition of the call to SimilaritySearchRequest(), the page now also
includes helpful data on other customer's past purchases in the same context,
together with links to the relevant product pages (notice how I'm using the returned
ASIN's to re-invoke the same PHP script again, but with a different ASIN).