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

bangpound - September 1, 2008 - 19:02
Status:active» needs review

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

If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.

I don't know if it's possible to force the array_merge function to treat the keys as strings instead of numerals.

AttachmentSize
amazon_array_merge.patch 619 bytes

#2

Shai - September 5, 2008 - 01:33

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

tcblack - September 16, 2008 - 16:47

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

bangpound - September 16, 2008 - 17:33

Please rename the issue title if it might help people find it. I didn't realize I was working exclusively with ISBN13.

#5

conniec - September 22, 2008 - 03:32

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

mleicester - November 4, 2008 - 03:46

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

joemoraca - November 10, 2008 - 00:47

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

bomarmonk - January 15, 2009 - 09:07

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

bomarmonk - January 23, 2009 - 09:38

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

Splicer - January 23, 2009 - 09:51

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

bomarmonk - January 23, 2009 - 17:25

I am still having trouble with the CCK field: it doesn't display anything after inputting the ISBN...

#12

rburr49 - March 10, 2009 - 13:39

Just a bump to say that this patch still seems to be necessary :(

RB

#13

skiquel - March 17, 2009 - 16:01

Same issue.

1590597559 works on test

But on node: ASIN : No Amazon product with the ID 1590597559 could be located.

#14

Shai - March 26, 2009 - 20:21

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

bangpound - March 26, 2009 - 21:55
Status:needs review» reviewed & tested by the community

I'm going to RTBC this, because it's really been ages...

#16

EloE - May 2, 2009 - 14:30

Thanks a lot for that patch, bangpound. Works perfectly for me.

#17

greggles - May 26, 2009 - 02:52

Agreed, tested and works for me.

#18

asb - May 27, 2009 - 09:11

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

eaton - May 27, 2009 - 16:41
Status:reviewed & tested by the community» fixed

Committed to the current branch. Thanks for the fix, sorry it's taken so long to get this one in place.

#20

asb - May 27, 2009 - 21:20

@eaton:

Thank you. It's great to have you back ;)

Greetings, -asb

#21

eaton - May 28, 2009 - 03:52

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

System Message - June 11, 2009 - 04:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#23

calebm12 - August 27, 2009 - 12:29

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.

 
 

Drupal is a registered trademark of Dries Buytaert.