You are here

function _asin_devel_generate in Amazon Product Advertisement API 6

Same name and namespace in other branches
  1. 7.2 asin/asin.module \_asin_devel_generate()
  2. 7 asin/asin.module \_asin_devel_generate()

Utility function that actually provides the values for asin_devel_generate().

You can change the SearchIndex and Keywords used for the search by changing the variables amazon_devel_generate_search_index and asin_devel_generate_keywords.

1 call to _asin_devel_generate()
asin_content_generate in asin/asin.module

File

asin/asin.module, line 535
Defines a field type for referencing an Amazon product.

Code

function _asin_devel_generate($node, $field) {
  $search_index = variable_get('asin_devel_generate_search_index', 'Books');
  $keywords_picker = explode(',', variable_get('asin_devel_generate_keywords', 'computers'));
  $keywords_picker = array_flip($keywords_picker);
  $asins = variable_get('amazon_devel_generate_asins', array());
  $amazon_item_page = variable_get('amazon_devel_generate_item_page', 1);
  if (empty($asins)) {
    $parameters = array(
      'ResponseGroup' => 'ItemAttributes,EditorialReview,Images',
      'SearchIndex' => $search_index,
      'Keywords' => urlencode(array_rand($keywords_picker, 1)),
      'ItemPage' => $amazon_item_page % 400,
    );
    $amazon_item_page++;
    $results = amazon_http_request('ItemSearch', $parameters);
    foreach ($results->Items->Item as $xml) {
      $item = amazon_item_clean_xml($xml);
      amazon_item_insert($item);
      $asins[] = $item['asin'];
    }
  }
  $field = array();
  $asin = array_shift($asins);
  $field['asin'] = $asin;
  variable_set('amazon_devel_generate_asins', $asins);
  variable_set('amazon_devel_generate_item_page', $amazon_item_page);
  return $field;
}