amazon_similar.module in Amazon Product Advertisement API 6
File
amazon_similar/amazon_similar.module
View source
<?php
function amazon_similar_amazon_response_groups_alter(&$groups) {
$groups[] = 'Similarities';
}
function amazon_similar_amazon_item_clean_xml(&$item, $xml) {
if (isset($xml->SimilarProducts->SimilarProduct)) {
foreach ($xml->SimilarProducts->SimilarProduct as $data) {
$version = array();
$version['asin'] = (string) $data->ASIN;
$version['title'] = (string) $data->Title;
$item['similarproducts'][] = $version;
}
}
}
function amazon_similar_amazon_item_load($item) {
$alternates = array();
$item_ids = array();
$result = db_query("SELECT asin, title FROM {amazon_similar} WHERE item = '%s' ORDER BY delta ASC", $item['asin']);
while ($version = db_fetch_array($result)) {
$alternates[] = $version;
$item_ids[] = $version['asin'];
}
if (module_exists('amazon_import')) {
$node_ids = amazon_import_get_product_nodes($item_ids);
foreach ($alternates as $key => $version) {
if (!empty($node_ids[$version['asin']])) {
$alternates[$key]['nid'] = $node_ids[$version['asin']];
}
}
}
$additions['similarproducts'] = $alternates;
if (isset($additions)) {
return $additions;
}
}
function amazon_similar_amazon_item_insert($item) {
if (empty($item['similarproducts'])) {
return;
}
$delta = 0;
foreach ($item['similarproducts'] as $version) {
$version['item'] = $item['asin'];
$version['delta'] = $delta;
drupal_write_record('amazon_similar', $version);
++$delta;
}
}
function amazon_similar_amazon_item_delete($asin) {
db_query("DELETE FROM {amazon_similar} WHERE item = '%s'", $asin);
}