You are here

amazon_search.module in Amazon Product Advertisement API 7

Sets up hook_search for Amazon items.

File

amazon_search/amazon_search.module
View source
<?php

/**
 * @file
 * Sets up hook_search for Amazon items.
 *
 */

/**
 * Implements hook_permission.
 * @return unknown_type
 */
function amazon_search_permission() {
  return array(
    'access amazon search' => array(
      'title' => t('Access Amazon Search'),
      'description' => t('Perform searches on Amazon.'),
    ),
  );
}

/**
 * Implements hook_search_access().
 */
function amazon_search_search_access() {
  return user_access('access amazon search');
}

/**
 * Implements hook_search_info().
 */
function amazon_search_search_info() {
  return array(
    'title' => 'Amazon',
    'path' => 'amazon_search',
  );
}

/**
 * Implements hook_search_execute(). Implements remote Amazon searching.
 */
function amazon_search_search_execute($keys = NULL, $conditions = NULL) {
  $products = array();
  $items = amazon_search_simple_search($keys);
  foreach ($items as $item) {
    $products[] = array(
      'title' => '',
      'link' => check_url($item['detailpageurl']),
      'type' => check_plain($item['productgroup']),
      'snippet' => theme('amazon_item', array(
        'item' => $item,
        'style' => 'details',
      )),
      'item' => $item,
    );
  }
  return $products;
}

/**
 * Perform the search.
 *
 * @param $keywords
 *   Keywords to be provided to Amazon.
 * @param $parameters
 *   Optional extra parameters to be passed to the Amazon API.
 * @return
 *   Array of Amazon items.
 */
function amazon_search_simple_search($keywords = '', $parameters = array(), $locale = NULL) {
  $parameters += array(
    'ResponseGroup' => 'Large',
    'SearchIndex' => 'All',
  );
  $parameters['Keywords'] = $keywords;
  drupal_alter('amazon_search_parameters', $parameters);
  $items = array();
  $results = amazon_http_request('ItemSearch', $parameters, $locale);
  foreach ($results->Items->Item as $xml) {
    $item = amazon_item_clean_xml($xml);
    $items[$item['asin']] = $item;
  }
  return $items;
}

Functions

Namesort descending Description
amazon_search_permission Implements hook_permission.
amazon_search_search_access Implements hook_search_access().
amazon_search_search_execute Implements hook_search_execute(). Implements remote Amazon searching.
amazon_search_search_info Implements hook_search_info().
amazon_search_simple_search Perform the search.