Logo         Community
  Trog
Services
The Company
Community
Columns
Your Account
Contact Us
 
 
Using Amazon E-Commerce Services With PEAR SOAP
Integrate Amazon.com's ECS service into your own Web site.

| Wanting More... |

Now, while the previous listings were certainly illustrative, they weren't very practical. After all, if you want your customers to purchase a book from your online store, you'll have to give them some more information about it - a description, a cover image, maybe some reviews. Heck, at the very least, you'll need to tell them the price (which, if you go back and look closely at the output of the previous script, wasn't actually included in the ECS response packet).

It's precisely to satisfy this need for more information that ECS includes "response groups". A response group is basically a filter that you attach to your ECS request; this filter lets you control the type (and amount) of information returned by ECS. Let's look at one of them in particular, the "Large" response group, which should provide sufficient information to create a detailed product page:


<html>
<head><basefont face="Arial"></head>
<body>
<?php
// include SOAP class
include("SOAP/Client.php");

// initialize SOAP client
$soapclient = new SOAP_Client("http://webservices.amazon.com/onca/soap?Service=AWSECommerceService");

// set data for SOAP request
// ask for "Large" data set
$params = array('SubscriptionId' => 'YOUR-ID-HERE',
                'ItemId' => '0385504209',
                'ResponseGroup' => 'Large');         
               
// get item information
$result = $soapclient->call("ItemLookup", $params);

if (PEAR::isError($result)) {
    die("Something went wrong...");
}

// format and print results
$data = $result['Items']->Item;   
?>
    <table cellpadding="10">
    <tr>
    <!-- book cover image -->
    <td>
<?php
if (isset($data->MediumImage->URL)) {
?>
    <img src="<?php echo $data->MediumImage->URL; ?>" align="left">
<?php
}
?>
    </td>
    <td>
        <!-- book title -->
        <b><?php echo $data->ItemAttributes->Title; ?></b>
        <br />
        <!-- author -->
        <?php echo $data->ItemAttributes->Author; ?>
        <p />
        <!-- publisher -->
        Publisher: <?php echo $data->ItemAttributes->Publisher; ?>
        <br />
        <!-- binding -->
        Binding: <?php echo $data->ItemAttributes->Binding; ?>
        <br />
        <!-- pages -->
        Pages: <?php echo $data->ItemAttributes->NumberOfPages; ?>
        <p />
        <!-- price -->
        <b>Amazon.com Price: <?php echo $data->ItemAttributes->ListPrice->FormattedPrice; ?></b>
    </td>
    </tr>
    </table>
    <p />
<?php
// check for editorial review
// print if available
if (isset($data->EditorialReviews)) {
?>
    <b>Book description</b>
    <br />   
    <?php echo $data->EditorialReviews[0]->Content; ?>
    <p />
<?php
}
?>
<?php
// check for customer reviews
// print if available
if (isset($data->CustomerReviews->Review)) {
?>
    <b>Customer reviews</b>
    <br />   
<?php
    $x = 0; // counter for reviews array
    while ($review = $data->CustomerReviews->Review[$x]) {
        echo "<u>" . $review->Summary . "</u> <br />";
        echo $review->Content . "<p />&nbsp;<p />";
        $x++;
    }
}
?>
    <p />
    <!-- amazon.com URL for this product -->
    <a href="<?php echo $data->DetailPageURL; ?>">Go to Amazon.com Product Page...</a>
</body>
</html>


Here's what the output looks like:

Output image

ECS comes with a bunch of pre-defined response groups, each designed for a specific purpose. The one I've used above, "Large", produces extremely detailed product information, including product reviews, images, pricing, availability, seller offers and more.

In addition to "Large", ECS has 35 (yup, 35!) other response groups for specific types of data -  images, product attributes and accessories, customer reviews, editorial reviews and similar products. For an exhaustive listing and usage examples, look in the ECS developer kit.

Interestingly, you can combine response groups to customize the ECS return value even further, simply by using a comma-separated list of response group names. The following brief example illustrates:


<?php
// include SOAP class
include("SOAP/Client.php");

// initialize SOAP client
$soapclient = new SOAP_Client("http://webservices.amazon.com/onca/soap?Service=AWSECommerceService");

// set data for SOAP request
// ask for custom data set
$params = array('SubscriptionId' => 'YOUR-ID-HERE',
                'ItemId' => '0385504209',
                'ResponseGroup' => 'Images,ItemAttributes,SalesRank,Similarities');         
               
// get item information
$result = $soapclient->call("ItemLookup", $params);

if (PEAR::isError($result)) {
    die("Something went wrong...");
}
print_r($result);
?>



How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!


previous page more like this  print this article  next page
 
Search...
 
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
more...
 
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
more...
 
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
more...
 
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
more...
 
In cut!...
American Chai
The Core
Possession
more...
 
Find out how you can use this article on your own Web site!


Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback