How to display attribute images on the Zen Cart shopping cart page

Although Zen Cart supports defining an image for a product’s attribute (i.e. different colors of t-shirts for a color attribute), once you add the product to your cart, only the default image will display.  Although you could hack the shopping cart page as per  instructions in the Zen Cart forum, a simpler approach is to edit the shopping_cart class.  This approach may be better as it will cause Zen Cart to output the attribute image anywhere that the shopping_cart class is used.

It is important that all Zen Cart stores that use attribute images implement one of these processes as it can be confusing to customers when they see a different product in their shopping cart than what they selected. The following implementation will resolve this issue.

To begin, open includes/class/shopping_cart.php and find:

$products_array[] = array('id' => $products_id,

Add before:

        // support attribute images
        if (isset($this->contents[$products_id]['attributes'])) {
          foreach ($this->contents[$products_id]['attributes'] as $options_id => $options_values_id) {
            // get the attributes image using the options_id and options_values_id
            $attributes_image = $db->Execute("SELECT attributes_image 
                                              FROM " . TABLE_PRODUCTS_ATTRIBUTES . " 
                                              WHERE products_id = " . (int)$products_id . "
                                              AND options_id = " . $options_id . "
                                              AND options_values_id = " . $options_values_id . "
                                              LIMIT 1;");
            if ($attributes_image->RecordCount() > 0 && $attributes_image->fields['attributes_image'] != '') {
              $products->fields['products_image'] = $attributes_image->fields['attributes_image'];
              break;
            }  
          }
        }

Now, when you visit your shopping cart page, assuming it uses the shopping_cart class, you will now see the image of the attribute that was added. There is one shortcoming, which more relates to Zen Cart itself than this method, and that is that if you have multiple attributes for a product and different images assigned to each attribute, it isn’t possible to assign an image to a combination of attributes (i.e. a large red t-shirt vs. a small red t-shirt). The above code will use the image from the first attribute that it finds (i.e. a red t-shirt, regardless of size).

We’ve also used a similar method in Fast and Easy AJAX Checkout v2.15.10+ which will allow showing product and attribute images in the checkout.

4 thoughts on “How to display attribute images on the Zen Cart shopping cart page


  1. Your mod works good on my local test store but not on my live store. I edited the class file like you said.
    zen-cart version 1.3.9h


  2. I wish I knew about this 2 years ago… I wrote my own custom mod that handles Image handling for attributes (Style, Color, Sizes) and it’s truly WYSIWYG now, for Product Info, View Cart, Checkout and Wish Lists, if not more. I’ve automated the whole thing to where I can put up a new product under 15 minutes with hundreds to thousands of images to support exponential variations due to Style, Color and Sizes. Oh well, I’m not gonna REWRITE the code now. LOL



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Chat with us Contact Account Cart Search Cart Open Menu Arrow Link Arrow Chat Close Close Popup Facebook Twitter Google Plus LinkedIn