You are here

function amazon_item_lookup_from_db in Amazon Product Advertisement API 7.2

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

Look up ASINs in database and return arrays of information keyed by ASIN.

Parameters

$item_ids: An array of string ASINs.

Return value

array Array of Amazon 'cleaned' data structures keyed by ASIN.

1 call to amazon_item_lookup_from_db()
amazon_item_lookup in ./amazon.module
Look up an item using database or web. The default is to look in the database for existing data, and then to do the web search if that fails. $force_lookup==TRUE forces going to Amazon's API.

File

./amazon.module, line 559

Code

function amazon_item_lookup_from_db($item_ids = array(), $locale = NULL) {
  if (!empty($item_ids)) {
    $timestamp = REQUEST_TIME - variable_get('amazon_refresh_schedule', 86400);
    $query = db_select('amazon_item', 'a')
      ->fields('a')
      ->condition('a.asin', $item_ids, 'IN')
      ->condition('a.timestamp', $timestamp, '>');
    if (!is_null($locale)) {
      $query
        ->condition('a.locale', $locale, '=');
    }
    $result = $query
      ->execute();
    $items = array();
    foreach ($result
      ->fetchAll() as $item) {
      $item = (array) $item;
      _amazon_load_child_data($item);
      $item += module_invoke_all('amazon_item_load', $item);
      $items["{$item['asin']}"] = $item;
    }
    return $items;
  }
  return array();
}