function amazon_item_insert in Amazon Product Advertisement API 6
Same name and namespace in other branches
- 7.2 amazon.module \amazon_item_insert()
- 7 amazon.module \amazon_item_insert()
Insert 'cleaned' amazon item into database.
Parameters
$item: 'Cleaned' amazon structure.
Return value
No return value.
4 calls to amazon_item_insert()
- amazon_cron in ./
amazon.module - amazon_test_form_submit in ./
amazon.admin.inc - _amazon_item_batch_lookup_from_web in ./
amazon.module - Get 10 or less items from the AWS web service. AWS allows ONLY 10 items, See http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.ht....
- _asin_devel_generate in asin/
asin.module - Utility function that actually provides the values for asin_devel_generate().
File
- ./
amazon.module, line 550
Code
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',
'editorial_reviews',
)))) {
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);
}
}
}
module_invoke_all('amazon_item_insert', $item);
}