Drupal Amazon Module

One of the top search engine hits is the Drupal Amazon module. Using a simple module name like Amazon is very ambiguous. Amazon is a lot of things. A quick inspection reveals the Drupal Amazon supports the Amazon Product Advertising API. This API is all about trying to help sell things that are already listed on Amazon,

So what does the module actually do? Well nothing and everything at the same time. A quick install reveals no new menu entries, no new content types and no visible features on your site (well except for module configuration screens). Why is that you ask? The reason is that this module is a helper api module. It provides an interface to Amazon Product Advertising API that can be leveraged by other modules. For example, the Drupal Amazon Store module relies on it.

A quick peak at the code reveals a set of modules:

  • Amazon Api
  • Amazon field
  • Amazon Filter
  • Amazon media
  • Amazon search
  • Amazon Examples

Amazon Api is the main module. It provides integration with the Amazon Product Advertising API. It is simple, easy to understand and powerful. To understand its scope it is useful to also understand the extent of the Amazon Product Advertising Api. Which is pretty simple. The documentation page provides the list of supported operations. A single Search, a couple Lookup's to drill down within a category and a bunch of Shopping Cart operations. This module provides a generic amazon_http_request function and the whole of the combined modules make 3 ItemSearch calls and 2 ItemLookup calls.

The following information can be gleaned from a quick skim of the modules info files. The Amazon field module "Provides a field for Amazon products". The Amazon Filter module "Lets writers use the [amazon] tag to embed Amazon product information in text". The Amazon media module "Stores extended Amazon product information for books, music, DVDs, and software". the Amazon search module "Provides an API for searching Amazon product information, and integration with the Drupal search system".

But that is not all it does. Some of the hidden details are:

  • the creation of an amazon_item table and a cron hook that will query Amazon and update stored product information.
  • a set of template files that can be used to display Amazon products on your Drupal website
  • a set of views plugin handlers to support Amazon specific data like title, date, image,...

What about the drawbacks? My early investigative work revealed a few downsides that required some addition effort to solve:

  • Single marketplace support
  • Insufficient request timeout handling

Part of the module configuration is providing an administrative screen where the Amazon credentials are captured. But the screen (and the module design) assumes support for only a single marketplace. This restriction was designed into the core architecture of the module. The module takes a simple approach. Providing generic adhoc multiple marketplace support introduces a large amount of complexity. Providing support for multiple marketplaces is currently left as an exercise for the reader. One of my projects required specific dual marketplace support which was simple enough to implement on top of the base code.

The other issue was the base ItemSearch code did not distinguish between no response (a call failure) and a successful response containing no matches. At first glance this distinction seems trivial. But load tests revealed that the Amazon API calls routinely timed out and failed to provide a response. Resubmitting the request generally resulted in a valid response.