Zend_Service_AmazonIntroductionZend_Service_Amazon is a simple API for using Amazon web services.
Zend_Service_Amazon has two APIs: a more traditional one that follows Amazon's own API, and a
simpler "Query API" for constructing even complex search queries easily.
Zend_Service_Amazon enables developers to retrieve information appearing throughout Amazon.com
web sites directly through the Amazon Web Services API. Examples include:
Store item information, such as images, descriptions, pricing, and more
Customer and editorial reviews
Similar products and accessories
Amazon.com offers
ListMania lists
In order to use Zend_Service_Amazon, you should already have an Amazon developer API key. To
get a key and for more information, please visit the
Amazon Web Services web site.
Attention
Your Amazon developer API key is linked to your Amazon identity,
so take appropriate measures to keep your API key private.
Search Amazon Using the Traditional API
In this example, we search for PHP books at Amazon and loop through the results, printing them.
itemSearch(array('SearchIndex' => 'Books',
'Keywords' => 'php'));
foreach ($results as $result) {
echo $result->Title . ' ';
}
]]>Search Amazon Using the Query API
Here, we also search for PHP books at Amazon, but we instead use the Query API, which
resembles the Fluent Interface design pattern.
category('Books')->Keywords('PHP');
$results = $query->search();
foreach ($results as $result) {
echo $result->Title . ' ';
}
]]>Country Codes
By default, Zend_Service_Amazon connects to the United States ("US") Amazon
web service. To connect from a different country, simply specify the appropriate country code string
as the second parameter to the constructor:
Choosing an Amazon Web Service CountryCountry codes
Valid country codes are: CA, DE, FR, JP,
UK, and US.
Looking up a Specific Amazon Item by ASIN
The itemLookup() method provides the ability to fetch a particular Amazon item when
the ASIN is known.
Looking up a Specific Amazon Item by ASINitemLookup('B0000A432X');
]]>
The itemLookup() method also accepts an optional second parameter for handling search
options. For full details, including a list of available options, please see the
relevant Amazon documentation.
Image information
To retrieve images information for your search results, you must set
ResponseGroup option to Medium or Large.
Performing Amazon Item Searches
Searching for items based on any of various available criteria are made simple using the
itemSearch() method, as in the following example:
Performing Amazon Item SearchesitemSearch(array('SearchIndex' => 'Books',
'Keywords' => 'php'));
foreach ($results as $result) {
echo $result->Title . ' ';
}
]]>Using the ResponseGroup Option
The ResponseGroup option is used to control the specific information that will be returned
in the response.
itemSearch(array(
'SearchIndex' => 'Books',
'Keywords' => 'php',
'ResponseGroup' => 'Small,ItemAttributes,Images,SalesRank,Reviews,' .
'EditorialReview,Similarities,ListmaniaLists'
));
foreach ($results as $result) {
echo $result->Title . ' ';
}
]]>
The itemSearch() method accepts a single array parameter for handling search
options. For full details, including a list of available options, please see the
relevant Amazon documentation
The Zend_Service_Amazon_Query class
is an easy to use wrapper around this method.
Using the Alternative Query APIIntroductionZend_Service_Amazon_Query provides an alternative API for using the Amazon Web Service.
The alternative API uses the Fluent Interface pattern. That is, all calls can be made using chained method
calls. (e.g., $obj->method()->method2($arg))
The Zend_Service_Amazon_Query API uses overloading to easily set up an item search and then
allows you to search based upon the criteria specified. Each of the options is provided as a method call,
and each method's argument corresponds to the named option's value:
Search Amazon Using the Alternative Query API
In this example, the alternative query API is used as a fluent interface to specify options and their
respective values:
Category('Books')->Keywords('PHP');
$results = $query->search();
foreach ($results as $result) {
echo $result->Title . ' ';
}
]]>
This sets the option Category to "Books" and Keywords to "PHP".
For more information on the available options, please refer to the
relevant Amazon documentation.
Zend_Service_Amazon Classes
The following classes are all returned by
Zend_Service_Amazon::itemLookup()
and
Zend_Service_Amazon::itemSearch():
Zend_Service_Amazon_ItemZend_Service_Amazon_ImageZend_Service_Amazon_ResultSetZend_Service_Amazon_OfferSetZend_Service_Amazon_OfferZend_Service_Amazon_SimilarProductZend_Service_Amazon_AccessoriesZend_Service_Amazon_CustomerReviewZend_Service_Amazon_EditorialReviewZend_Service_Amazon_ListManiaZend_Service_Amazon_ItemZend_Service_Amazon_Item is the class type used to represent an Amazon item returned by the
web service. It encompasses all of the items attributes, including title, description, reviews, etc.
Zend_Service_Amazon_Item::asXML()stringasXMLReturn the original XML for the itemPropertiesZend_Service_Amazon_Item has a number of properties directly related to their standard
Amazon API counterparts.
Zend_Service_Amazon_Item PropertiesNameTypeDescriptionASINstringAmazon Item IDDetailPageURLstringURL to the Items Details PageSalesRankintSales Rank for the ItemSmallImageZend_Service_Amazon_ImageSmall Image of the ItemMediumImageZend_Service_Amazon_ImageMedium Image of the ItemLargeImageZend_Service_Amazon_ImageLarge Image of the ItemSubjectsarrayItem SubjectsOffers
Zend_Service_Amazon_OfferSet
Offer Summary and Offers for the ItemCustomerReviewsarray
Customer reviews represented as an array of
Zend_Service_Amazon_CustomerReview
objects
EditorialReviewsarray
Editorial reviews represented as an array of
Zend_Service_Amazon_EditorialReview
objects
SimilarProductsarray
Similar Products represented as an array of
Zend_Service_Amazon_SimilarProduct
objects
Accessoriesarray
Accessories for the item represented as an array of
Zend_Service_Amazon_Accessories
objects
TracksarrayAn array of track numbers and names for Music CDs and DVDsListmaniaListsarray
Item related Listmania Lists as an array of
Zend_Service_Amazon_ListmainList
objects
PromotionalTagstringItem Promotional Tag
Back to Class List
Zend_Service_Amazon_ImageZend_Service_Amazon_Image represents a remote Image for a product.Properties
Zend_Service_Amazon_Image PropertiesNameTypeDescriptionUrlZend_UriRemote URL for the ImageHeightintThe Height of the image in pixelsWidthintThe Width of the image in pixels
Back to Class List
Zend_Service_Amazon_ResultSetZend_Service_Amazon_ResultSet objects are returned by
Zend_Service_Amazon::itemSearch()
and allow you to easily handle the multiple results returned.
SeekableIterator
Implements the SeekableIterator for easy iteration (e.g. using foreach), as
well as direct access to a specific result using seek().
Zend_Service_Amazon_ResultSet::totalResults()inttotalResultsReturns the total number of results returned by the search
Back to Class List
Zend_Service_Amazon_OfferSet
Each result returned by
Zend_Service_Amazon::itemSearch()
and
Zend_Service_Amazon::itemLookup()
contains a
Zend_Service_Amazon_OfferSet
object through which pricing information for the item can be retrieved.
Properties
Zend_Service_Amazon_OfferSet PropertiesNameTypeDescriptionLowestNewPriceintLowest Price for the item in "New" conditionLowestNewPriceCurrencystring
The currency for the
LowestNewPriceLowestOldPriceintLowest Price for the item in "Used" conditionLowestOldPriceCurrencystring
The currency for the
LowestOldPriceTotalNewintTotal number of "new" condition available for the itemTotalUsedintTotal number of "used" condition available for the itemTotalCollectibleintTotal number of "collectible" condition available for the itemTotalRefurbishedintTotal number of "refurbished" condition available for the itemOffersarray
An array of
Zend_Service_Amazon_Offer
objects.
Back to Class List
Zend_Service_Amazon_Offer
Each offer for an item is returned as an
Zend_Service_Amazon_Offer
object.
Zend_Service_Amazon_Offer Properties
PropertiesNameTypeDescriptionMerchantIdstringMerchants Amazon IDGlancePagestringURL for a page with a summary of the MerchantConditionstringCondition of the itemOfferListingIdstringID of the Offer ListingPriceintPrice for the itemCurrencyCodestringCurrency Code for the price of the itemAvailabilitystringAvailability of the itemIsEligibleForSuperSaverShippingbooleanWhether the item is eligible for Super Saver Shipping or not
Back to Class List
Zend_Service_Amazon_SimilarProduct
When searching for items, Amazon also returns a list of similar products that the searcher may find to
their liking. Each of these is returned as a Zend_Service_Amazon_SimilarProduct object.
Each object contains the information to allow you to make sub-sequent requests to get the full information
on the item.
Properties
Zend_Service_Amazon_SimilarProduct PropertiesNameTypeDescriptionASINstringProducts Amazon Unique ID (ASIN)TitlestringProducts Title
Back to Class List
Zend_Service_Amazon_Accessories
Accessories for the returned item are represented as Zend_Service_Amazon_Accessories objects
Properties
Zend_Service_Amazon_Accessories PropertiesNameTypeDescriptionASINstringProducts Amazon Unique ID (ASIN)TitlestringProducts Title
Back to Class List
Zend_Service_Amazon_CustomerReview
Each Customer Review is returned as a Zend_Service_Amazon_CustomerReview object.
Properties
Zend_Service_Amazon_CustomerReview PropertiesNameTypeDescriptionRatingstringItem RatingHelpfulVotesstringVotes on how helpful the review isCustomerIdstringCustomer IDTotalVotesstringTotal VotesDatestringDate of the ReviewSummarystringReview SummaryContentstringReview Content
Back to Class List
Zend_Service_Amazon_EditorialReview
Each items Editorial Reviews are returned as a Zend_Service_Amazon_EditorialReview object
Properties
Zend_Service_Amazon_EditorialReview PropertiesNameTypeDescriptionSourcestringSource of the Editorial ReviewContentstringReview Content
Back to Class List
Zend_Service_Amazon_Listmania
Each results List Mania List items are returned as Zend_Service_Amazon_Listmania objects.
Properties
Zend_Service_Amazon_Listmania PropertiesNameTypeDescriptionListIdstringList IDListNamestringList Name