amazon_versions.module in Amazon Product Advertisement API 6
File
amazon_versions/amazon_versions.module
View source
<?php
function amazon_versions_amazon_response_groups_alter(&$groups) {
$groups[] = 'AlternateVersions';
}
function amazon_versions_amazon_item_clean_xml(&$item, $xml) {
if (isset($xml->AlternateVersions->AlternateVersion)) {
foreach ($xml->AlternateVersions->AlternateVersion as $data) {
$version = array();
$version['asin'] = (string) $data->ASIN;
$version['title'] = (string) $data->Title;
$version['binding'] = (string) $data->Binding;
$item['alternateversions'][] = $version;
}
}
}
function amazon_versions_amazon_item_load($item) {
$alternates = array();
$item_ids = array();
$result = db_query("SELECT asin, title, binding FROM {amazon_versions} 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['alternateversions'] = $alternates;
if (isset($additions)) {
return $additions;
}
}
function amazon_versions_amazon_item_insert($item) {
if (empty($item['alternateversions'])) {
return;
}
$delta = 0;
foreach ($item['alternateversions'] as $version) {
$version['item'] = $item['asin'];
$version['delta'] = $delta;
drupal_write_record('amazon_versions', $version);
++$delta;
}
}
function amazon_versions_amazon_item_delete($asin) {
db_query("DELETE FROM {amazon_versions} WHERE item = '%s'", $asin);
}