You are here

function amazon_component_gallery_lookup in Amazon Product Advertisement API 7.2

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.

Parameters

$item_ids: An array of ASIN strings or a single ASIN as a string.

$force_lookup: If TRUE, skip the database lookup and just go to the Amazon API lookup.

Return value

array Array of "cleaned" XML item descriptions, keyed on ASIN.

1 call to amazon_component_gallery_lookup()
template_preprocess_amazon_gallery in amazon_component/amazon_component.preprocess.inc
The template_preprocess_amazon_gallery handles the "Amazon Gallery Block". The Amazon Gallery Block is rended on the Amazon Product Node Type and Amazon Store Module paths Galleries reference the Product ASIN # stored in the URL path

File

amazon_component/amazon_component.module, line 157

Code

function amazon_component_gallery_lookup($item_ids = array(), $force_lookup = FALSE, $locale = NULL) {

  // Function Variables
  $items = array();
  $items_to_fetch = array();

  // Return :: Empty Check
  if (empty($item_ids)) {
    return array();
  }

  // Convert :: single $item_ids from String to Array
  if (is_string($item_ids)) {
    $item_ids = array(
      $item_ids,
    );
  }

  // Query :: Database - Product ASIN Gallery
  if (!$force_lookup) {
    $items = amazon_component_lookup_gallery_from_db($item_ids, $size = 'mediumimage');
  }

  // Loop :: Exclude Database Product ASIN Results from Amazon Product API Request
  foreach ($item_ids as $item_id) {
    if (!isset($items[$item_id])) {
      $items_to_fetch[] = $item_id;
    }
  }

  // Query :: API - Product ASIN Gallery
  $items_from_web = amazon_component_gallery_lookup_from_web($items_to_fetch, $locale);

  // Concat :: Database Results + Amazon API Results
  $full_set = $items + $items_from_web;

  // Return :: Database Lookup + Amazon API Request
  return $full_set;
}