You are here

function _asin_devel_generate in Amazon Product Advertisement API 7

Same name and namespace in other branches
  1. 6 asin/asin.module \_asin_devel_generate()
  2. 7.2 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 amazon_devel_generate_keywords.

1 call to _asin_devel_generate()
asin_devel_generate in asin/asin.module
Implements hook_devel_generate(). Callback for populating ASIN fields with devel_generate module.
1 string reference to '_asin_devel_generate'
asin_devel_generate in asin/asin.module
Implements hook_devel_generate(). Callback for populating ASIN fields with devel_generate module.

File

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

Code

function _asin_devel_generate($object, $field, $instance, $bundle) {
  $search_index = variable_get('amazon_devel_generate_search_index', 'All');
  $keywords_picker = explode(',', variable_get('asin_devel_generate_keywords', 'computer'));
  $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' => array_rand($keywords_picker, 1),
      'ItemPage' => $amazon_item_page % 10,
    );
    $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();

  //$field['asin'] = array_shift($asins);
  $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;
}