Hi, we were playing around with DS and ND Ubercart to customise the catalog grid page and product node layout, but can't work out how to

a) only show the primary image on the catalog grid - currently it's showing all images if there are more than one, and

b) on the product node page, show the primary image using one image cache preset, and the remainder using another image cache preset, just as the standard Ubercart product node page does.

Any suggestions?

Have attached the catalog grid page - note the products in the second row. Have also attached the product node page for your reference.

btw, love the work you're doing.

Comments

swentel’s picture

Component: ND Ubercart » ND CCK

Aha, never knew ubercart had this behavior by default. We've encountered the issue a few times as well (for other content types too) and what we did was simply creating 2 separate imagefields - a workaround which in a way sounds silly but works effectively :)

I think this belongs to the node displays cck component, since other imagefields could profit from that change too. I think we should look at the imagecache formatters and add new formatters based on existing presets (a bit like all the ones that lightbox2 gives). This might result in a lot of new formatters of course, but I think a valuable feature request which everyone can profit from.

Could just confirm that these are imagefields from cck ? If so, I'll change the title afterwards and should go in before the next release!

swentel’s picture

Ok, after a long discussion with other developers, we came to this conclusion: only adding formatters for imagecache/imagefield is a waste of time, we need to make more general formatters which could apply to any cck field which has multiple items per instance. This implies some changes to the UI of display suite (so we can pass parameters to the formatters and other cool stuff). This won't make it for 1.1 at all, maybe not even 1.2 (depending on external factores like an UI change, because we're limited in that area right now), however, we'll post some snippets by the end of this week on the documentation pages which you can easily paste into a custom module to achieve the goal you want - and which we'll be able to reuse too in custom projects :) More to come later!

Stalski’s picture

subscribe.
I am already dreaming about a flexible showcase gallery for juwelery products I am working on...

swentel’s picture

Status: Active » Closed (fixed)

Ok, here's some code to add extra formatters. The formatter only prints one field if there are multiple images on a that field. Replace 'modulename' by the name of your custom module.

/**
 * Implementation of CCK's hook_field_formatter_info().
 */
function modulename_field_formatter_info() {
  $formatters = array(
    'image_single' => array(
      'label' => t('Image single'),
      'field types' => array('filefield'),
      'description' => t('Displays image files single in a format.'),
    ),
  );
  return $formatters;
}

/**
 * Implementation of hook_theme().
 */
function modulename_theme() {
  return array(
    'modulename_formatter_image_single' => array(
      'arguments' => array('element' => NULL),
    ),
  );
}

/**
 * Only show the first image with a specific image cache.
 */
function theme_modulename_formatter_image_single($element) {
  static $i = 0;

  // Stop after the first one.
  if ($i > 0) {
    return;
  }

  if (empty($element['#item']['fid'])) {
    return '';
  }
  $i++;

  $item = $element['#item'];

  $alt = isset($item['data']['alt']) ? $item['data']['alt'] : '';
  $title = isset($item['data']['title']) ? $item['data']['title'] : NULL;

  return theme('imagecache', 'small', $item['filepath'], $alt, $title);
}
Rene Hostettler’s picture

Hi

Thanks for providing the custom module code unfortunately we are having problems getting our custom module to work.
Having followed the tutorial in the Drupal 6 module development guide it appeared our custom module was working ok.

The module installed with no error messages, however when viewing the Ubercart full node display page the standard image cache theme function is being called rather then the one in our custom module making all images the same as being set in node display.

I have attached the custom module would really appreciate it you could have a look as we haven't had any experience building modules before.

Thanks again

Rene Hostettler’s picture

Status: Closed (fixed) » Active

reopen

swentel’s picture

Ok, there is a logical flaw in my theming function which makes imagecache stop at least on a list of different images. All the rest working fine now for me. Change the theming function underneath to fix the logic.

  static $images = array();

  $nid = $element['#node']->nid;

  // Stop after the first one.
  if (isset($images[$nid])) {
    return;
  }

  if (empty($element['#item']['fid'])) {
    return '';
  }
  $images[$nid] = TRUE;

  $item = $element['#item'];

  $alt = isset($item['data']['alt']) ? $item['data']['alt'] : '';
  $title = isset($item['data']['title']) ? $item['data']['title'] : NULL;

  return theme('imagecache', 'uc_category', $item['filepath'], $alt, $title);
Rene Hostettler’s picture

Thanks for taking the time to look at this issue swentel it's much appreciated. I have tried replacing the new theming function but still can't get it to work. Is there another module that may be interfering with it getting called? When I inspect the node output with theme developer it is still the standard theme_imagecache() function being called on all images. Just to confirm I have replaced all the code in the theme function with your new code as shown below.

Is there any chance you could post your working module?

function theme_imagecache_for_nd_contrib_formatter_image_single($element) {
 static $images = array();

  $nid = $element['#node']->nid;

  // Stop after the first one.
  if (isset($images[$nid])) {
    return;
  }

  if (empty($element['#item']['fid'])) {
    return '';
  }
  $images[$nid] = TRUE;

  $item = $element['#item'];

  $alt = isset($item['data']['alt']) ? $item['data']['alt'] : '';
  $title = isset($item['data']['title']) ? $item['data']['title'] : NULL;

  return theme('imagecache', 'uc_category', $item['filepath'], $alt, $title);
}
swentel’s picture

Well I've plugged in the module that you guys gave me (with the small changes I also posted) and it work without any problems. Saw the formatter popping up, chose the single image and it used the formatter which is defined in that module, so not exactly sure right now .. do you have this online somewhere to test ?

swentel’s picture

Status: Active » Closed (fixed)

I'm closing this one for now - did some more testing and everything worked out fine for now. Now that 1.1 is out, we're working on a fields ds plugin which makes it possible to order fields within a view if choose a fields style plugin - see http://drupal.org/node/770368

jr50’s picture

thank you

amariotti’s picture

Status: Closed (fixed) » Active

Any progress on this? I'm almost wondering if this should be pushed to be an ubercart feature, if it isn't already. The problem is that Ubercart just uses the imagefield module for product images. There must be some way to make this easier for people to create grid type views with just the primary image...help?

johnflower’s picture

I also would like to see support for replicating UBercart's default display of images in the Product node. It would be nice to have the first image large, and the following images smaller.

johnflower’s picture

1) To replicate Ubercart's handling of images in the product node, try the Gallery Formatter module. http://drupalmodules.com/module/gallery-formatter whilst not exactly the same (it's better!) it can make the first image large and the following images smaller, and it puts them tidily underneath.

2) To have one image for the product grid, you could use Views to create the catalogue and restrict it to using the first image field. Or you could add a second image field for the thumbnails, and allow only one image for the default field and unlimited images for the second. Probably need to do a bit of work for formatting in the node, but the catalogue should be fine :)

swentel’s picture

Status: Active » Closed (fixed)

Nice comment in #15 - closing again.

milplus’s picture

StatusFileSize
new30.1 KB
new86.5 KB

Guys

I'm trying to collect a snapshot of my store products onto a Region of a Panel or View.

I done this before - now reinstalled all onto live page- this view does not work anymore.

I need to have a Multipage view with all items thumbnail paged onto there - however now I canno tlimit the view to one Image Thumbnail only but I get listed all produc images in column instead in row.

See enclosed what I need , as per thread above.