Amazon field rejects any product ID. Amazon API test feature works fine though.
bangpound - September 1, 2008 - 18:45
| Project: | Amazon Module |
| Version: | 6.x-1.0-beta3 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
When I enter a valid Amazon product ID in a node's amazon field, I'm told:
Amazon ID : No Amazon product with the ID 1842779079 could be located.
However, I can search for the same product ID using the test feature of the module (path admin/settings/amazon/test). That works fine.
I don't understand the workings of the module, but the validate operation of the asin_field will always fail.
<?php
$results = _asin_load_items($items);
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'])));
}
}
}
return $items;
?>The _asin_load_items function returns an array that is not indexed by ASIN, so empty($results[$item['asin']]) is always true.

#1
The problem appears to originate in the amazon_item_lookup function. It also may only affect PHP 5.
The function is returning a merged array. The array_merge function though destroys numeric keys on merged arrays.
see http://php.net/array_merge
I don't know if it's possible to force the array_merge function to treat the keys as strings instead of numerals.
#2
I had the same problem. I've tested the patch on it solved the problem perfectly for my installation.
Just to make things clear for folks about when the problem will occur. ISBNs or ASINs that begin with a zero will be processed without problem by the module (php sees that as a string). The problem comes when the product identifier number does not begin with a zero.
It would be great if a few more people could test the patch so that we could get this committed.
Thanks so much bangpoud.
#3
FWIW it does not break for ISBN's that start with 0's either. I haven't tested for other ISBN's yet though I can confirm that it still does not work with ISBN13
#4
Please rename the issue title if it might help people find it. I didn't realize I was working exclusively with ISBN13.
#5
I can second that confirmation that the patch doesn't work with 13 digit ISBNs.
I wrote a PHP script written to change 13 digit ISBNs to 10 digit ISBNs. I have no idea how to incorporate it into a patch so it's not really doing me much good except to convert my ISBNs so I can manually enter the shorter ones.
If anyone wants the script to use in a patch, let me know.
Connie
#6
I've added some EAN / 13 digit ISBN support to the CCK field / testing interface in a patch on #288577: 13 digit ISBNs / EAN support / converting to ASINs.
#7
The code in the patch worked for me. I just tried four books before I applied the patch it found none and then updated the code and it found all of the books -- I was just using the 10 digit ISBN
#8
bangpound, I tried your initial patch and the other patches listed in this post. I still get "warning: Invalid argument supplied for foreach() in /home/.muckl/mysite.com/sites/all/modules/amazon/amazon.module on line 269." Also see my post here http://drupal.org/node/269335 and a duplicate support request from someone else here: http://drupal.org/node/293826
#9
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?
#10
I'm using beta5 but applied the patch from bangpound, which fixed the issue for me.
More information if it is helpful: I did not encounter rejection on all products, and the one that I encountered was an ISBN-10, not 13.
I think it would be great if the patch were to be rolled in to the module distribution. It's a pretty simple patch.
#11
I am still having trouble with the CCK field: it doesn't display anything after inputting the ISBN...
#12
Just a bump to say that this patch still seems to be necessary :(
RB
#13
Same issue.
1590597559 works on test
But on node: ASIN : No Amazon product with the ID 1590597559 could be located.
#14
I had the same problem. ISBN numbers that begin with "1" did not work as described in the initial post. I applied the patch found in comment #1 to the latest dev version. It applied cleanly and fixed the problem.
Shai
#15
I'm going to RTBC this, because it's really been ages...
#16
Thanks a lot for that patch, bangpound. Works perfectly for me.
#17
Agreed, tested and works for me.
#18
Same issue here; bangpounds patch from #1 works for me and solves the problem. Could we please get this into a release?
Thanks & greetings, -asb
#19
Committed to the current branch. Thanks for the fix, sorry it's taken so long to get this one in place.
#20
@eaton:
Thank you. It's great to have you back ;)
Greetings, -asb
#21
It's great to be back. ;-) I realized I hadn't been receiving amazon module issue emails, and hadn't done a thorough manual scan of my issue queue for a while.
#22
Automatically closed -- issue fixed for 2 weeks with no activity.
#23
I dont know if maybe i am using an edition that already has the patch incorporated into it or not. But i was getting the same error people are talking about here. What i noticed is that if you Copy and Paste the ISBN number from Amazon it actually copies a blank space after the last digit in the ISBN. If you remove the space....or if you copy the number very carefuly from amazon before pasting it.....everything works fine.