Hello,

I would like to add the possibility of adding a thumbnail to cart/view when the node is an image (added in turn to the store).

I know a bit of PHP and CSS, but I am new to drupal, so I would need some assistance on where exactly and how I could achieve this. Some hint to point me in the right direction would already be helpful.

The following archived email (http://lists.heydon.com.au/htdig.cgi/ecommerce-heydon.com.au/2006-April/...) seems to suggest that it is possible, but I'm afraid it's still too cryptic for me as a starting point...

So, where should I begin?

Thanks,

Comments

drupaceous’s picture

This is the function that displays the cart form. I put this in my template.php to override the original function. I added a column to display the thumbnail. Currently it just displays the string 'thumbnail'. Is there a simple variable I could substitute in order to display the thumbnail, something like print $image[thumbnail]?

I do already have the $nid in the function. So what could I do with this?

/**
 * Returns a themed shopping cart form.
 */
function sandbox_cart_view($form) {
  $total = 0;
  $header = array('', t('Items'), t('Qty.'), '');

  foreach (element_children($form['items']) as $nid) {
    $total+= $form['items'][$nid]['#total'];
    $total+= $form['items'][$nid]['#specials'];
    $desc = form_render($form['items'][$nid]['title']) .'<br />';
    if ($form['items'][$nid]['recurring']) {
      $desc.= '<div class="recurring-details">'. form_render($form['items'][$nid]['recurring']) .'</div>';
    }
    if ($form['items'][$nid]['availability']) {
      $desc.= form_render($form['items'][$nid]['availability']);
    }
    $desc.= '<p>'. payment_format($form['items'][$nid]['#total']+$form['items'][$nid]['#specials']) .'</p>';

    $row[] = array(
      array('data' => 'thumbnail'),
      array('data' => $desc),
      array('data' => $form['items'][$nid]['qty'] ? form_render($form['items'][$nid]['qty']) : '', 'align' => 'center'),
      array('data' => l(t('Remove'), "cart/delete/$nid")),
    );
  }
  $row[] = array(array("data" => "<strong>". t('Subtotal:') . '</strong> ' . payment_format($total), "colspan" => 4, "align
" => "right"));
  $output.= theme('table', $header, $row);
  $output.= form_render($form);
  return $output;
}
Phillip Mc’s picture

I was searching for adding images to the shopping cart view form, found this thread and thought I would post how I did it using Drupal 5.1 and the ecommerce version 3.x-dev suite of modules.

Step 1: (with CCK and the imagefield.module for cck enabled) I added an image field to products under CONTENT MANAGEMENT -> CONTENT TYPES -> PRODUCT -> ADD FIELD. I called the field product_image so if you call it something else, you will need to edit the template.php theme override below to match what you called your imagefield.

Step 2: create your template.php override.

<?php
// CHANGE yourthemename TO SUIT

function yourthemename_cart_view_form($form) {
  $total = 0;
  $header = array(t('Items'), t('Qty.'), '');
  $extra = array_filter($form['items'], '_cart_form_filter_extra');
  if ($extra) {
    $header[] = '';
  }

  foreach (element_children($form['items']) as $nid) {
    $total+= $form['items'][$nid]['#total'];
    $total+= $form['items'][$nid]['#specials'];
    $desc = drupal_render($form['items'][$nid]['title']) .'<br />';
    if ($form['items'][$nid]['recurring']) {
      $desc.= '<div class="recurring-details">'. drupal_render($form['items'][$nid]['recurring']) .'</div>';
    }
    if ($form['items'][$nid]['availability']) {
      $desc.= drupal_render($form['items'][$nid]['availability']);
    }
    $desc.= '<p>'. payment_format($form['items'][$nid]['#total']+$form['items'][$nid]['#specials']) .'</p>';
  
    // LOAD THE PRODUCT IMAGE

    $img = '';
    $productnode = node_load($nid);
    $path = $productnode->field_product_image[0]['filepath'];
    if (file_exists($path)) {
    $img = '<img src="'. $productnode->field_product_image[0]['filepath'] .'" height="100px" width="100px" alt="Product image" />';
    }
    else {
      $img = '';
    }
    $row = array(
      array('data' => $img),
      array('data' => $desc),
      array('data' => $form['items'][$nid]['qty'] ? drupal_render($form['items'][$nid]['qty']) : '', 'align' => 'center'),
    );
    if ($extra && $form['items'][$nid]['extra']) {
      $row[] = array('data' => drupal_render($form['items'][$nid]['extra']));
    }
    elseif ($extra) {
      $row[] = '';
    }
    $row[] = array('data' => l(t('Remove'), "cart/delete/$nid"));
    $rows[] = $row;
  }
  $rows[] = array(array("data" => "<strong>". t('Subtotal:') . '</strong> ' . payment_format($total), "colspan" => $extra ? 4 : 3, "align" => "right"));
  
  // GIVE THE VIEW CART TABLE A CLASS NAME CALLED "cartview" FOR STYLING USING CSS

  $attributes = array('class' => 'cartview');
  $output.= theme('table', $header, $rows, $attributes);
  $output.= drupal_render($form);
  return $output;
}
?>

Step 3: Copy that into an existing template.php file using a text editor like pspad or create a new template.php file if one doesn't exist andupload it to yourthemename folder. I have set the thumbnails to be output at 100 x 100 pixels. You can change that in the template.php override to suit.

In my template.php override, I have called the cck image field product_image remember to change that to match what you called the imagefield for your product nodes.

I have also added a class name to the view cart table, so it's easier to style the contents using CSS after the template.php override is applied.

hope that helps others.

MHz’s picture

I am using Drupal 6.22 and eCommerce 6.x-4.4, your method doesn't seem to work for me, any ideas why? I am getting frustrated trying to add thumbnails, any help you could give would be a massive help!

WorldFallz’s picture

this thread is 3 years old and based on d4.7-- the chances of it working as is are pretty much nil.