You are here

function _amazon_item_batch_lookup_from_web in Amazon Product Advertisement API 6

Same name and namespace in other branches
  1. 7.2 amazon.module \_amazon_item_batch_lookup_from_web()
  2. 7 amazon.module \_amazon_item_batch_lookup_from_web()

Get 10 or less items from the AWS web service. AWS allows ONLY 10 items, See http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.ht....

Parameters

$item_ids: Array of ASINs to be looked up.

Return value

Array of ASIN data structures keyed by ASIN.

1 call to _amazon_item_batch_lookup_from_web()
amazon_item_lookup_from_web in ./amazon.module
Use Amazon API to look up an array of ASINs.

File

./amazon.module, line 356

Code

function _amazon_item_batch_lookup_from_web($item_ids = array()) {
  if (!empty($item_ids)) {
    $params = array(
      'ItemId' => implode(',', $item_ids),
      'ResponseGroup' => amazon_get_response_groups(),
    );
    $results = amazon_http_request('ItemLookup', $params);
    if (!empty($results->Items->Request->Errors)) {
      foreach ($results->Items->Request->Errors->Error as $error) {
        $code = (string) $error->Code;
        $message = (string) $error->Message;
        $matches = array();

        // Find and extract the failing ASIN, so we can mark it in the db.
        if (preg_match('/^([^ ]+) is not a valid value for ItemId/', $message, $matches)) {
          $error_asin = $matches[1];
          $query = "update {amazon_item} set invalid_asin = TRUE where asin = '%s'";
          db_query($query, $error_asin);
        }
        watchdog('amazon', 'Error retrieving Amazon item %code, message: %message.', array(
          '%code' => $code,
          '%message' => $message,
        ), WATCHDOG_WARNING);
      }
    }
    $items = array();
    if (!empty($results->Items->Item)) {
      foreach ($results->Items->Item as $xml) {
        $item = amazon_item_clean_xml($xml);
        amazon_item_insert($item);
        $items["{$item['asin']}"] = $item;
      }
    }
    return $items;
  }
  return array();
}