amazon_item_insert($item)Insert 'cleaned' amazon item into database.
$item 'Cleaned' amazon structure.
No return value.
contrib-6/amazon/amazon.module, line 543
<?php
function amazon_item_insert($item) {
// We have boatloads of data to insert in here, so we're going to
// cheat and blow away the old entries first.
amazon_item_delete($item['asin']);
$metadata = amazon_data_cache();
$item['timestamp'] = time();
drupal_write_record('amazon_item', $item);
// Handle the various credits for a product, including Artist, Author,
// Actor, etc. We map these to a separate table.
if (in_array('creators', variable_get('amazon_core_data', array('creators', 'images')))) {
$participant_types = split(',', AMAZON_PARTICIPANT_TYPES);
foreach ($participant_types as $type) {
if (isset($item[strtolower($type)])){
foreach((array)$item[strtolower($type)] as $participant) {
$item_participant = array('asin' => $item['asin'], 'type' => strtolower($type), 'participant' => $participant);
drupal_write_record('amazon_item_participant', $item_participant);
}
}
}
}
// Save the product images if they exist, or provide defaults
if (in_array('images', variable_get('amazon_core_data', array('creators', 'images')))) {
// If we have no images, go get default images.
// TODO: This is pretty ugly. Find a better way. Store this information as
// variable, whatever. No reason to do this every time.
if (empty($item['imagesets'])) {
$default_image = variable_get('amazon_default_image', '');
foreach (array('small', 'medium', 'large') as $key) {
$preset_name = variable_get('amazon_default_image_' . $key . '_preset', '');
if (!empty($preset_name)) {
$preset = imagecache_preset_by_name($preset_name);
$themed_image = theme('imagecache', $preset_name, $default_image, t('No image was provided'));
if ($key == 'medium') {
$themed_default_image = $themed_image;
}
preg_match_all('/(src|height|width)=("[^"]*")/i', $themed_image, $tags);
foreach ($tags[1] as $tag_index => $tag) {
if ($tag == 'src') {
$item['imagesets']["{$key}image"]['url'] = str_replace('"', '',$tags[2][$tag_index]);
}
if ($tag == 'width') {
$item['imagesets']["{$key}image"]['width'] = str_replace('"', '',$tags[2][$tag_index]);
}
if ($tag == 'height') {
$item['imagesets']["{$key}image"]['height'] = str_replace('"', '',$tags[2][$tag_index]);
}
}
}
}
}
if (isset($item['imagesets'])) {
foreach($item['imagesets'] as $size => $data) {
$image = array('asin' => $item['asin'], 'size' => $size, 'height' => $data['height'], 'width' => $data['width'], 'url' => $data['url']);
drupal_write_record('amazon_item_image', $image);
}
}
}
// Save the editorial reviews if they exist.
if (in_array('editorial_reviews', variable_get('amazon_core_data', array('creators', 'images')))) {
if (isset($item['editorialreviews'])) {
foreach($item['editorialreviews'] as $data) {
$review = array('asin' => $item['asin'], 'source' => $data['source'], 'content' => $data['content']);
drupal_write_record('amazon_item_editorial_review', $review);
}
}
}
// Save the customer reviews if they exist.
if (in_array('customer_reviews', variable_get('amazon_core_data', array('creators', 'images')))) {
if (isset($item['customerreviews'])) {
foreach($item['customerreviews'] as $data) {
$review = array('asin' => $item['asin'], 'rating' => $data['rating'], 'date' => $data['date'], 'summary' => $data['summary'], 'content' => $data['content']);
drupal_write_record('amazon_item_customer_review', $review);
}
}
}
module_invoke_all('amazon_item_insert', $item);
}
?>