You are here

function amazon_test_form_submit in Amazon Product Advertisement API 6

Same name and namespace in other branches
  1. 7.2 amazon.admin.inc \amazon_test_form_submit()
  2. 7 amazon.admin.inc \amazon_test_form_submit()

File

./amazon.admin.inc, line 210

Code

function amazon_test_form_submit($form, &$form_state) {
  $asin = $form_state['values']['asin'];
  $asin = amazon_convert_to_asin($asin);

  // Normalize to an asin. ISBN-13 OK.
  $items = amazon_item_lookup_from_web(array(
    $asin,
  ));
  if (!empty($items) && is_array($items)) {
    $item = array_pop($items);
    amazon_item_delete($item['asin']);
    amazon_item_insert($item);

    // We could probably be sneaky and put the Amazon data in here directly,
    // but SimpleXML objects can't be serialized, and setting rebuild = TRUE
    // causes a serialization operation. Whoops.
    $form_state['amazon_item'] = $item;
    $form_state['rebuild'] = TRUE;
  }
  else {
    drupal_set_message(t("Test failed for this ASIN. Please check the !link for messages.", array(
      '!link' => l(t("error log"), 'admin/reports/dblog'),
    )));
  }
}