Hi there,

the module shows wrong product images for me.

I am using the latest Version on latest Drupal Version - I use Amazon Local: Germany.

The point is that the Module seems to catch the EU-Energielabel Image instead of the real Product image.

e.g.:
http://up.picr.de/22093039yb.jpg

You can see the label image on amazon also: http://www.amazon.de/Samsung-UE48JU6560-LED-Backlight-Fernseher-Sprachst...

Just search for EU-Energielabel and click on it.

My websites look really wired - all those fancy labels instead of nice product images.

Comments

epbarta’s picture

StatusFileSize
new17.61 KB

I'm having a similar situation with about half of the book covers on my sites. Some are showing the back cover, some show the author's image, and some show a icon of a person holding the book.

I'm located in America, so I'm not sure the problem is situated to a specific region.

sejtraav’s picture

I just noticed the same issue has just appeared on my site. Any ideas? Perhaps the Amazon API changed?

flashon’s picture

Having the same issue with back covers showing. It started about a week ago. In /admin/config/services/amazon/test the url used in the array is pointing straight to the back cover image

[smallimage] => Array
(
[url] => http://ecx.images-amazon.com/images/I/51si3vnGEeL._SL75_.jpg
[height] => 75
[width] => 49
)

flashon’s picture

I'm in Canada BTW.

honylein’s picture

Damn - it seems to be a general issue.
I have not found a solution so far!

jnycz’s picture

This issue is also occurring in D6 if anyone cares. I have books from Amazon returning the second image for some, first for others.

bavramor’s picture

Hi, I have the same Problem with D6, too. Is there any solution so far ?

aharown07’s picture

I'm seeing this on several USA book cover images lately... back covers.
Example: [amazon 082543047X thumbnail]
(D7)

Kirk’s picture

Also seeing this on D6. Looks like it's related to books that has the animated image on amazon's pages.

gaurishankar’s picture

I have same issues with D7

shearstock’s picture

I'm also having the same issue in D6. Any work arounds? Any advice?

kamescg’s picture

StatusFileSize
new733 bytes

Amazon API is offsetting the image in the returned XML by 1, so to get the first image we need to select the last image in the array.

This patch reverses the ImageSet array, so the correct image is stored in the amazon_item_image table

EDIT: Causes a parse error with Drush, so I need to revise the patch.

smitty’s picture

Status: Active » Closed (duplicate)

Marked as a duplicate of https://www.drupal.org/node/2508265

kamescg’s picture

Status: Closed (duplicate) » Active

@smitty The issue request is for 7.x-1.x and the other one is for 6.x-1.x - I think they should be dealt with separately.

To download the correct patch for Drupal 7.x-1.x visit https://www.drupal.org/files/issues/amazon-fix-image-order-2508265-7.patch - smitty do you want to submit the patch to this thread?

Sooo what happened? The Amazon API changed - the primary image is last in the ImageSets array now.

That being said, the primary ImageSet now includes (thanks to smitty for seeing it) the attribute "Category=primary". All other images use "Category=variant". In other words smitty's patch loops over the ImageSets array to find the image with the correct attribute.

It should be noted the XML request returns the primary image (small, medium, large) in three separate arrays right above the ImageSets array, so we could potentially just grab the image information via those arrays instead. It would prevent having to loop over the ImageSets array, which depending on the product could be anywhere from 2-8 images.

<SmallImage>
   <URL>http://ecx.images-amazon.com/images/I/51fVh4tnJUL._SL75_.jpg</URL>
   <Height Units="pixels">75</Height>
   <Width Units="pixels">75</Width>
</SmallImage>
<MediumImage>
   <URL>http://ecx.images-amazon.com/images/I/51fVh4tnJUL._SL160_.jpg</URL>
   <Height Units="pixels">160</Height>
   <Width Units="pixels">160</Width>
</MediumImage>
<LargeImage>
   <URL>http://ecx.images-amazon.com/images/I/51fVh4tnJUL.jpg</URL>
   <Height Units="pixels">500</Height>
   <Width Units="pixels">500</Width>
</LargeImage>
<ImageSets>
   <ImageSet Category="variant">
     ....
gaurishankar’s picture

@kamescg
Please post seprate patch for D6 and D7.

Currently you submitted path, that has not mentioned about drupal version (D6 or D7).

aharown07’s picture

Is the patch in 14 working for anyone? In my tests I'm not seeing any change to the displayed image (ran cron, flushed caches, too).

kamescg’s picture

@aharown07 I was having issues at first when trying to apply the patch. I ended up doing it manually, because I was getting whitespace Git errors. That being said, the code in the patch is right. Maybe try to insert manually and see what happens?

aharown07’s picture

The patch works now... It seemed to take a day or two even though I flushed all the caches. Perhaps there is a table you have to manually truncate to see immediate results? (It is also possible that browser cache was an issue, though I'm pretty sure I flushed that too)

Anyway, patch seems to be good.

kamescg’s picture

The "amazon_item_image" table isn't flushed during a clear cache. However, the products will be updated during a cron job or after a certain amount of time (usually 24 hours) for most websites.

For everyone applying the patch remember to run a cron job refresh the Amazon Product Image cache.

smitty’s picture

The time it takes to flush the "amazon_item_image" can be configured in admin/config/services/amazon/storage

Maybe reconfiguring this setting will empty the table immediately and force a reload of the images. But I'm not sue about this. Just give it a try ...

AntiNSA’s picture

Priority: Major » Critical

Im just getting the default image now for no image provided products... this needs to be moved to Critical, I used the first patch for d6 provided by OP....

kamescg’s picture

StatusFileSize
new869 bytes

I have uploaded the correct patch for this Drupal 7 thread. Smitty published it in the 6.x thread and we forgot to move it over here.

The patch is practically guaranteed to select the correct image. It will search for an image marked as primary. Unless Amazon is sending the wrong image (which I doubt) it's a problem on our end.

I suspect the problem has to do with cached images in the everyone's existing websites.

The core Amazon module contains the amazon_cron() function. From the way it's structured it's set to only update 50 Amazon Product's at a time. I guessing this function setting is tripping up existing websites with larger product inventories. However, I also can't find a call to this function, so it's not obvious when it's being executed and how exactly...

In addition the amazon_item_expire() function is not defined in the core Amazon module, but it's called in the hook_flush cache function. This may be another issue causing Amazon Product images not to expire.

Time permitting I'll write a patch to add a Product Refresh tab, where administrators can manually update all of the product images via the module dashboard.

Additionally, I'm just cleaning up a fork of the Amazon Module which adds support for images galleries and selecting a product's primary image. I'll be providing the link shortly if anyone feels compelled to help test it. Afterwards a patch will be provided to this thread.

function amazon_cron() {
  // Here, we're going to chug through all the existing ASINs and update them.
  // We'll grab 50 at a time to avoid thrashing things.
  $per_cron_limit = 50;
  $needs_update_time = REQUEST_TIME - variable_get('amazon_refresh_schedule', 86400);
  $result = db_select('amazon_item', NULL, array('fetch' => PDO::FETCH_ASSOC))
            ->fields('amazon_item', array('asin'))
            ->condition('timestamp', $needs_update_time, '<')
            ->range(0, $per_cron_limit)
            ->execute();
  $asins = $result->FetchCol();
  if (!empty($asins)) {
    if ($items = amazon_item_lookup_from_web($asins)) {
      foreach ($items as $item) {
        amazon_item_insert($item);
      }
      watchdog('amazon', 'Amazon items were updated.');
    }
    else {
      watchdog('amazon', 'Amazon items could not be updated.');
    }
  }
}
AntiNSA’s picture

Ill get the d6 patch from the other thread and give it a go. The product refresh tab would be an awesome feature!

Thanks for your great efforts.

kamescg’s picture

I recently published an update to the 7.x-1.x-dev Amazon Module, so it now includes support for product image galleries. For example you if the Amazon Product has 5 images the Amazon Module can display all 5 images using either the Small, Medium and Large gallery sizes.

You can download the update module at https://github.com/KamesCG/Amazon-Core/tree/master if you want to test/add support for image galleries to your website. I'll send the update the a maintainer and see if he's willing to publish the update.

BTW You have to run Drupal Update, because the module adds a new database table.

I'm still working on the Image Refresh function - I'll publish in the next 1-3 days.

Only local images are allowed.

AntiNSA’s picture

That would be nice. unfortunately I am stuck on D6 untill after our kickstarter.... so if there is a 6 version thats awesome :)

kamescg’s picture

I was made the maintainer for the Amazon Module yesterday, so I am going to do my best to release backwards compatibility as the project moves forward.

leahmd’s picture

I had the same issue with odd images, the patch in #22 solved it for me, thank you very much!

AntiNSA’s picture

any progress? SMittys d6 patch is not working : (

gaurishankar’s picture

This patch working for me
/*path for D-7
*amazon.module
*line -574
*/

if (isset($xml->ImageSets->ImageSet)) {
--foreach ((array) $xml->ImageSets->ImageSet as $key => $data) {
++$ImageSets = (array) $xml->ImageSets;
++if (is_array($ImageSets['ImageSet'])) {
++if (isset($ImageSets['ImageSet'][0])) {
++$ImageSets = $ImageSets['ImageSet'];
++foreach ($ImageSets as $number => $set) {
++$set = (array) $set;
++if ($set['@attributes']['Category'] == 'primary') {
++$ImageSet = $set;
++}
++}
++}
++}
++else {
++$ImageSet = $ImageSets['ImageSet'];
++}
++foreach ($ImageSet as $key => $data) {

Denis Waßmann’s picture

#29 works - thx! But you must wait a while for amazon cache (and set it on "Amazon refresh schedule" 1 houre)

smitty’s picture

The patch from #22 / #29 works fine, as long as Amazon is providing at least one image. But there are cases, where Amazon dosn't deliver a single image. And in such cases there are two php-Warnings/Notices in the error.log:

Warning: Invalid argument supplied for foreach() in amazon_item_clean_xml() (Zeile 593 von .../sites/all/modules/amazon/amazon.module).

Notice: Undefined variable: ImageSet in amazon_item_clean_xml() (Zeile 593 von .../sites/all/modules/amazon/amazon.module).

These messages disappear if we check if variable $ImageSet exists before trying to read it.

So the enhanced Patch is now (unfortunately I don' have a tool installed to make a true patch):

   if (isset($xml->ImageSets->ImageSet)) {
-    foreach ((array) $xml->ImageSets->ImageSet as $key => $data) {
+
+    $ImageSets = (array) $xml->ImageSets;
+    if (is_array($ImageSets['ImageSet'])) {
+      if (isset($ImageSets['ImageSet'][0])) {
+        $ImageSets = $ImageSets['ImageSet'];
+        foreach ($ImageSets as $number => $set) {
+          $set = (array) $set;
+          if ($set['@attributes']['Category'] == 'primary') {
+            $ImageSet = $set;
+          }
+        }
+      }
+    }
+    else {
+      $ImageSet = $ImageSets['ImageSet'];
+    }
+    if (isset($ImageSet)) {
+      foreach ($ImageSet as $key => $data) {
+        if (in_array($key, $supported_sizes)) {
+          $item['imagesets'][strtolower($key)] = array(
+            'url' => (string) $data->URL,
+            'height' => intval($data->Height),
+            'width' => intval($data->Width),
+          );
+        }
+      }
-      if (in_array($key, $supported_sizes)) {
-        $item['imagesets'][strtolower($key)] = array(
-          'url' => (string) $data->URL,
-          'height' => intval($data->Height),
-          'width' => intval($data->Width),
-        );
-      }
antiorario’s picture

StatusFileSize
new1.46 KB

This is the patch for #31.