Custom Product Template Drupal Ubercart: node-product.tpl.php

<!--
Modification of ubercart product template: this one should look very similar to the 'default look'.
It has only few selected fields and comes with Lightbox support.
-->
<?php
  drupal_add_js("misc/collapse.js");
?>
 
<?php // Grabs the firsts image path and sets $imagePath.
$imagePath = $node->field_image_cache['0']['filepath'];
?>
 
<!-- node and node inner -->
<div class="node <?php print $node_classes ?>" id="node-<?php print $node->nid; ?>">
 
        <?php if ($unpublished || $submitted): ?>
                <div class="node-top">
                        <?php if ($unpublished) : ?>
                        <div class="unpublished"><?php print t('Unpublished'); ?></div>
                        <?php endif; ?>
 
                        <?php if ($submitted): ?>
                        <div class="submitted">
                          <?php print $submitted; ?>
                        </div>
                        <?php endif; ?>
                </div>
        <?php endif; ?>
 
        <div class="prod_content">
                <?php
                // Make the thickbox thing work
                // print $output in the section where you want the images to appear
                $images = $node->field_image_cache;
                $rel_count = 0;
                  $thickbox_enabled = module_exists('thickbox');
                  $first = array_shift($images);
                  $output = '<div class="image">';
                  if ($thickbox_enabled) {
                    $output .= '<a href="'. check_url(file_create_url($first['filepath'])) .'" title="'. $first['title'] .'" class="thickbox" rel="field_image_cache_'. $rel_count .'">';
                  }
                  $output .= theme('imagecache', 'product', $first['filepath'], $first['alt'], $first['title']);
                  /* if (count($images)) {
                    $output .= '<br />'. t('Click for more images.');
                  } */
                  if ($thickbox_enabled) {
                    $output .= '</a>';
                  }
                  $output .= '<br />';
                  foreach ($images as $thumbnail) {
                    if ($thickbox_enabled) {
                      $output .= '<a href="'. check_url(file_create_url($thumbnail['filepath'])) .'" title="'. $thumbnail['title'] .'" class="thickbox" rel="field_image_cache_'. $rel_count .'">';
                    }
                    $output .= theme('imagecache', 'uc_thumbnail', $thumbnail['filepath'], $thumbnail['alt'], $thumbnail['title']);
                    if ($thickbox_enabled) {
                      $output .= '</a>';
                    }
                  }
                  $output .= '</div>';
                  $rel_count++;
                ?>
 
 
                <!--show fields: sku, description, prices-->
                <?php //print $title ?>
                <div class="prod_code">
                        <div class="model"><?php print t( '<h4>Product Code:</h4>') . ('<span class="prod_code">') . $node->model . ('</span><br />') ?></div>
                </div>
 
                <div class="prod_desc">
                    <?php print '<fieldset class="collapsible"><legend>Description</legend>'; ?>
                    <?php print $node->content['body']['#value'];  ?>
                        <?php print '</fieldset>'; ?>
                        <!--/show fields: sku, description, prices-->
 
                </div>
 
                <div class="prod_cart">
                        <!--show add to cart button-->
                        <div id="basket_head"><?php print t( '<h4>Basket:</h4>') ?></div>
                        <img id="basket_img" alt="Basket" src="/sites/all/modules/ubercart-5.x-1.7/ubercart/uc_cart/images/cart_full.gif" />
                        <div class="add_to_cart">
                        <?php print $node->content['add_to_cart']["#value"]; ?>
                        </div>
                        <!--/show add to cart button-->
                </div>
 
 
                <div class="prod_img"> 
                        <?php print t( '<h4>Images:</h4><br /> ') ?>           
                        <div id="image_block" class="product_image">
                        <?php // default image display
                              if (file_exists($imagePath)){
                              print $output;
                              }
                              else {
                              print "<p id='image_error'>Sorry, we don't have a photo for this product at the moment.</p>";  
                              }
                              ?>
                        </div>
                        <?php // /image block ?>
 
                </div>
 
                <div class="prod_feat">
                    <?php print '<fieldset class="collapsible"><legend>Features</legend>'; ?>          
                    <?php print $node->content['field_features']['#value'];  ?>
                        <?php print '</fieldset>'; ?>                  
                        <!--/show fields: sku, description, prices-->
 
                </div>
 
 
                <div class="prod_cat">
                        <!-- show categories, etc. -->
                        <?php if (count($taxonomy)): ?>
                          <div id="prod_taxonomy" class="taxonomy"><?php print t(' <h4>Categories:</h4> ') . $terms; ?></div>
                        <?php endif; ?>
                        <!-- /show categories, etc. -->
                </div>
 
                <?php
                if (isset($node->files) && user_access('view uploaded files')) {
                        print '<div class="prod_attach">';
                        print '<fieldset class="collapsible"><legend>Data Sheets</legend>';
                        if (count($node->files)) {
                                print theme('upload_attachments', $node->files);
                        }
                        print '</fieldset>';                   
                        print '</div>';
                }
                ?>
 
                <?php if ($links): ?>
                  <div id="prod_links" class="links"><?php print $links ?></div>
                <?php endif; ?>
 
        </div>
</div>
<!-- /node and node inner -->