Update Cart image with Option Image

jonathan.hebel - May 9, 2008 - 12:44
Project:Ubercart Option Images
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:pillarsdotnet
Status:active
Description

Hi, great module... very much appreciated!

A great feature would be if the users' chosen Attribute Option Image showed in the cart as well -- so if say if the default prod pic was a yellow shirt but I chose a blue shirt (attribute option), the blue shirt would show in the cart instead of the default prod image (yellow shirt in this case).

#1

tjholowaychuk - May 9, 2008 - 14:53
Assigned to:Anonymous» tjholowaychuk

Thank you, I like the suggestion I will certainly add this to the todo list :)

#2

jonathan.hebel - May 10, 2008 - 02:40

That's great! Thank you.

#3

tjholowaychuk - May 12, 2008 - 00:40
Status:active» postponed

#4

ablewave - October 29, 2008 - 03:39

Any progress on this feature? I am having other problems with this module as well, but if this isn't active I won't use it anyway. Having the wrong color item shown in the cart creates a major uncertainty in the buyer's mind and can prevent checkouts.

#5

tjholowaychuk - October 29, 2008 - 15:52

Unfortunately I have had no time to work on this one as I have been working on a bunch of other projects. For a quick-fix you may want to simply override the theme in order to make the picture switch appropriately.

#6

scottrigby - November 9, 2008 - 02:42

Hi tjholowaychuk, I just found this module - thank you!

+1 for this feature :)

In the meantime, can you give any tips about how to override the theme function?

#7

Poieo - November 12, 2008 - 18:38

Great module...add one more to the request above. Any insight on how to accomplish this through a theme override would be great.

#8

mattcoady - March 19, 2009 - 05:10

Also looking for a fix as well. If it helps, in "uc_cart.module" on line 1271, you'll find the line:

$data['image'][] = array('data' => drupal_render($form['items'][$i]['image']), 'class' => 'image');

Which appears to be the code to present the image in the cart. Anyone know what to do with this?

#9

pillarsdotnet - April 16, 2009 - 19:17
Version:5.x-1.0-beta2» 6.x-1.x-dev
Assigned to:tjholowaychuk» pillarsdotnet
Status:postponed» active

Will be adding a "default image" feature in version 6. The support code is already there; just need to add the UI. Once it's working, I'd appreciate any assistance in backporting to 5.x as I no longer have access to a 5.x server.

#10

tjmoyer - April 23, 2009 - 03:58

For what it's worth, I just hacked the UC Cart module to show the option image. I'm using UC Cart 6.x-2.0-beta5 and options images 6.x-1.4. Here's my code (may be a bit simple, but it works).

I haven't fully tested this, but seems to work so far.

Added the following function, which mimics the output of uc_product_get_picture() in UC Product module, at the end of the file:

function uc_cart_get_option_picture($path, $node_id, $format = 'thumbnail') {
  $output = '';
  $product = node_load($node_id);

  if (!module_exists('imagecache') || !($field = variable_get('uc_image_'. $product->type, ''))) {
    return '';
  }

  // Get the current product image widget.
  $image_widget = uc_product_get_image_widget();
  $image_widget_func = $image_widget['callback'];

  if (isset($product->$field)) {
    $image = array();
    $image['alt'] = $product->title;
    $image['title'] = $product->title;
    if (file_exists($path)) {
      $img = theme('imagecache', $format, $path, $image['alt'], $image['title']);
      if ($format == 'thumbnail') {
        if ($image_widget) {
          $output .= '<a title="'. $image['title'] .'" href="'. imagecache_create_url('product_full', $path) .'" '. $image_widget_func(NULL) .'>';
        }
        $output .= $img;
        if ($image_widget) {
          $output .= '</a>';
        }
      }
      else {
        $output = l($img, 'node/'. $product->nid, array('html' => TRUE));
      }
    }
  }

  return $output;
}

Then I replaced this line:

      $form['items'][$i]['image']['#value'] = uc_product_get_picture($display_item['nid']['#value'], 'cart');

with this:

      if (module_exists('uc_option_image')) {
            $attribs = $item->data['attributes'];
            foreach ($attribs as $key => $value) {
                  $aid = $key;
                  $oid = $value;
            }
            $option_img = uc_option_image_load($display_item['nid']['#value'], $aid, $oid);
            $img_path = $option_img->filepath;
            $form['items'][$i]['image']['#value'] = uc_cart_get_option_picture($img_path, $item->nid);
      }
      if (empty($form['items'][$i]['image']['#value'])) {
            $form['items'][$i]['image']['#value'] = uc_product_get_picture($display_item['nid']['#value'], 'cart');
}

Now my cart pulls in the selected option image rather than the default product image. I'll attach my hacked copy of uc_cart.module, as well. Hope this helps!

#11

pillarsdotnet - April 24, 2009 - 14:03

It should be possible for uc_option_image to do the swap via javascript without hacking the cart module.

#12

acdtrp - September 4, 2009 - 05:38

It would be great if the modules does that by itself but for now the tjmoyer's hack works for me.

#13

squiggle86 - September 25, 2009 - 06:53

+1 for this feature, would be very very handy as customers would probably get confused otherwise

Will use tjmoyers hack until this feature is implemented. Love ya work

 
 

Drupal is a registered trademark of Dries Buytaert.