2 replies [Last post]
webmaker's picture
Offline
Joined: 04/22/2009
Juice: 76
Was this information Helpful?

Hi,

in my template file I want to check if there is one or more images set for the product - to avoid that the following code is taken over to the output:

        <?php if (!empty($node->field_image_cache)): ?>

        <?php // main picture
         
$imagePath = $node->field_image_cache['0']['filepath']; ?>

        <a href="<?php print base_path() . "sites/default/files/imagecache/product_full/" . $imagePath; ?>" rel="lightbox[prod]">
        <img src="<?php print base_path() . "sites/default/files/imagecache/product/" . $imagePath; ?>" alt="<?php print $title?>" title="<?php print $title?>" /></a>

       <?php // other pictures ?>

        <ul class="other_imgs">
        <?php foreach ($node->field_image_cache as $images) { if ($images['filepath'] != $imagePath) { ?>
        <li><a href="<?php print base_path() . "sites/default/files/imagecache/product_full/" . $images['filepath']; ?>" rel="lightbox[prod]" title="<?php print $title; ?>">
       <img src="<?php print base_path() . "sites/default/files/imagecache/uc_thumbnail/" . $images['filename']; ?>" alt="<?php print $title; ?>" /></a> </li>
   <?php } } ?>
   </ul>
   <?php endif; ?>

If there is no image for the product this leads to the following output:

<a href="/seeliger/sites/default/files/imagecache/product_full/" rel="lightbox[prod]">
        <img src="/seeliger/sites/default/files/imagecache/product/" alt="Eyeliner waterproof" title="Eyeliner waterproof" /></a>
               <ul class="other_imgs">
           </ul>

If there is just one image set it leads to the following output:

<a href="/seeliger/sites/default/files/imagecache/product_full/sites/default/files/200130_duo.jpg" rel="lightbox[prod]">
        <img src="/seeliger/sites/default/files/imagecache/product/sites/default/files/200130_duo.jpg" alt="Fuß-Schaum-Creme Intensivpflege Plus 125 ml" title="Fuß-Schaum-Creme Intensivpflege Plus 125 ml" /></a>
               <ul class="other_imgs">
           </ul>

If there are two or more images set it is ok - the first main image is shown correctly and the output of the further images in a HTML list is as it should be. Just the output in case that just one or no image is set is incorrect. Can anybody help with "if"-statement I can check for the product images?

Thank you very much in advance!

Best,
Tobias

diwakar's picture
Offline
Joined: 07/27/2011
Juice: 6
product image not displaying

/sites/default/files/imagecache/product_full//sites/default/files/Satin_Wedding_5.1.jpg

imagecache is taking in this url instead of /sites/default/files/imagecache/product_full/Satin_Wedding_5.1.jpg

pl suggest, thank you

nightlife2008's picture
Offline
Joined: 12/08/2010
Juice: 50
Hi guys, Just to note that

Hi guys,

Just to note that you probably should be using the proper ubercart theme functions to format your product imagery. I'm using the following function in my theme's "template.php":

<?php
/**
* Format a product's images with imagecache and an image widget
* (Colorbox, Thickbox, or Lightbox2).
*
* @ingroup themeable
*/
function THEME_uc_product_image($images, $teaser = 0, $page = 0) {
  static
$rel_count = 0;

 

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

 

$first = array_shift($images);

 

$output  = '<div class="product-image">';
 
$output .= '  <div class="main-product-image">';
 
$output .= '      <a href="'. imagecache_create_url('uc_product_enlarge', $first['filepath']) .'" title="'. $first['data']['title'] .'"';
  if (
$image_widget) {
   
$output .= $image_widget_func($rel_count);
  }
 
$output .= '>';
 
$output .= theme('imagecache', 'product', $first['filepath'], $first['alt'], $first['title']);
 
$output .= '      </a>';
 
$output .= '  </div>';

  if (

$page == 1 ) {
   
$output .= '  <div class="more-product-images">';
    foreach (
$images as $i => $thumbnail) {
     
$i++;
     
// Node preview adds extra values to $images that aren't files.
     
if (!is_array($thumbnail) || empty($thumbnail['filepath'])) {
        continue;
      }
     
$class = ( $i % 3 == 0 ) ? ' class="third"' : '';
     
$output .= '    <a href="'. imagecache_create_url('product_full', $thumbnail['filepath']) .'"'.$class.' title="'. $thumbnail['data']['title'] .'"';
      if (
$image_widget) {
       
$output .= $image_widget_func($rel_count);
      }
     
$output .= '>';
     
$output .= theme('imagecache', 'uc_thumbnail', $thumbnail['filepath'], $thumbnail['alt'], $thumbnail['title']);
     
$output .= '    </a>';
    }
   
$output .= '  </div>';
  }
 
$output .= '</div>';
 
$rel_count++;

  return

$output;
}
?>

The code in my node-product.tpl.php file is actually reduced to the following:

<?php
print $node->content['image']['#value'];

Hope to be of service!
?>