When I have required attributes, so no attribute is selected when a product node is loaded, the uc option image is loaded with theme_uc_option_image_no_image().

theme_uc_option_image_no_image() outputs only an img tag.

Then, in the javascript function UCOI.switchImage() there is this code:

    } else if (image[0] == null) {
       parentImage = $(':not(.uc-option-image-preloaded) > div.uc-option-image-block');
       parentImage[0].innerHTML = "<img src=\""+Drupal.settings.basePath+images[oid].derivative+"\" class=\"uc-option-image\">";
    }

In the case of theme_uc_option_image_no_image() $(':not(.uc-option-image-preloaded) > div.uc-option-image-block') does not exist in the markup so parentImage[0] is undefined and no image gets added when you select an attribute.

Comments

ben coleman’s picture

Status: Active » Needs review
StatusFileSize
new928 bytes

I ran into this recently. Note that you can't just add a '

' '

to what theme_uc_option_image_no_image() returns, as it is also called to put the no_image image in the preloaded images (see theme_uc_option_image_preloadedtheme_uc_option_image_preloaded). The solution is to wrap the div around the call to theme_uc_option_image_no_image() in uc_option_image in theme_uc_option_image_preloaded. The attached patch fixes it.

hargobind’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and tested. Without the code, image switching is broken. This patch makes it work.

makbeta’s picture

I don't think the solution presented is the best one. To fix the root source of the problem you need to modify the theming function itself.
I have used the version of module from this comment https://drupal.org/node/712542#comment-4776218 & the switching works regardless of the markup around the no-image.png image.

<?php
function theme_uc_option_image_no_image($node, $size = '_original') {
  $attributes = array('class' => 'uc-option-image');
  $filename = drupal_get_path('module', 'uc_option_image') . '/no_image.png';

  if ($size != '_original') {
    $imagecache_image = theme('imagecache', $size, $filename, t('No Image'), NULL, $attributes);
  }
  else {
     $imagecache_image = theme('image', $filename, t('No Image'), NULL, $attributes, FALSE);
  }

  $option_image = '<div class="uc-option-image-block">' . $imagecache_image . '</div>';
  return $option_image;
}
?>