Steps to reproduce

1. Add a Amazon CCK field to content type
2. Make new content of that content type and fill in 1591840562 for the Amazon ID
3. Submit
4. A message will show up: "No Amazon product with the ID 1591840562 could be located."

Check the contents of the mysql database and the content for id 1591840562 is present. Furthermore the test

Furthermore if you go to
admin/settings/amazon/test
and fill in 1591840562 as the ID it works fine.

The error popups in asin.module

      foreach ($items as $delta => $item) {
        if (is_array($item)) {
          if (!empty($item['asin']) && empty($results[$item['asin']])) {
            form_set_error($field['field_name'] .']['. $delta .'][asin', t('%name : No Amazon product with the ID %id could be located.', array('%name' => t($field['widget']['label']), '%id' => $item['asin'])));
          }
        }
      }

I think empty($results[$item['asin']]) is not correct and should be empty($results[$delta]['asin']). In that case I don't get the error message but the amazon data doesn't show up

CommentFileSizeAuthor
#8 amazon.array_merge.patch725 bytesRobrecht Jacques
#3 amazon.zip5.62 KBArinaya

Comments

najibx’s picture

what's the different Amazon CCK item - Text Field and Lookup by Title?

when using admin/settings/amazon/test,
it shows the actual books, and array. I will then use the field of that array to create my field, field_AMAZON_FIELD
For example i use the field "asin" (which become field_asin CCK field ) for the ISBN.

but always getting ISBN : No Amazon product with the ID 1584794747 could be located.

Another question is, what happen for books not listed in Amazon? So I shall have 2 ISBN type?

amccann’s picture

I'm seeing the same thing but it is inconsistent - some products work, some don't.

Arinaya’s picture

Status: Active » Needs review
StatusFileSize
new5.62 KB

Ok, I was running into the same bug, so here is a fix.

This seems to affect any book whose ISBN begins with '1'. When adding these ISBNs as an array key, PHP automatically converts it to an integer, even though it was a string to start with. Then, when array_merge() is called at the end of amazon_item_lookup(), the ISBN is lost entirely (array_merge() sees a numeric index, and so resets it to 0, as far as I can tell).

So I replaced the call to array_merge() with a for loop that takes care of merging the two arrays. This seems to fix the issue, at least for the cases I have tested.

In other words, I replaced

return array_merge($items, $items_from_web);

with this:

  foreach($items_from_web as $delta => $item) {
      $items[$delta] = $item;
  }
  return $items;

Sorry, I don't know how we're supposed to submit code changes, I am attaching an updated amazon.module file as a .zip

Edit: the attached amazon.module is from 6.x-1.0-beta5, so if you're running a different version you may just want to copy-paste the above lines into the end of amazon_item_lookup().

scott859’s picture

Same problem here...

Thanks for the patch, I will try it.

Scott

bomarmonk’s picture

Arinaya, I tried your version of the module, but I get "warning: Invalid argument supplied for foreach() in /home/mysite.com/sites/all/modules/amazon/amazon.module on line 275."

bomarmonk’s picture

Hmmm... I switched to my own Amazon API key, and now things seem to work. Maybe the problem was with the default key when the module is first installed?

Jaap Haitsma’s picture

Thanks your proposed fix works for me

Robrecht Jacques’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new725 bytes

Patch attached. Tested and ready to commit.

Anonymous’s picture

Works for me too, thanks.

qmaria’s picture

I believe this is the same problem in this other issue
http://drupal.org/node/302721

The other issue has a patch that is only a one line change and is easier to apply.

The patch is available in comment 1 of that thread.

greggles’s picture

Status: Reviewed & tested by the community » Closed (duplicate)