Help with displaying product thumbnail in cart mod

  • Posts: 100
  • Thank you received: 1
12 years 2 months ago #62826

Hi all,

From searching the forum i understand that there is no option to add the product image into the cart module as standard. However if i override the product/cart.php file with some additional PHP and HTML this can be achieved.

I have attempted to do this by adding this code after line 139:

<td class="hikashop_cart_module_product_image hikashop_cart_value">
<div class="image">
   <?php if(!empty($row->images)){
      $image = reset($row->images);
      if(!$this->config->get('thumbnail')){
         echo '<img src="'.$this->image->uploadFolder_url.$image->file_path.'" alt="'.$image->file_name.'" id="hikashop_main_image" style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle" />';
      }else{
         $height = $this->config->get('thumbnail_y');  ?>
         <div class="hikashop_cart_product_image_thumb" >
            <?php echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"'); ?>
         </div>
      <?php }
      } ?>
</div>
</td>

The image is not displaying, i presume some variables need assigning? could you give me some pointers on how to achieve this?

The link to the site is: www.rock-a-bye-rosie.com/
If you add something to the cart and then click the "My Shopping Bag" text on the top right of the window you will see the cart in a pop-up.

Thanks in Advance
Sean R.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 2 months ago #62853

Hi reders,

The variable "$row->images" doesn't exist. The cart doesn't load any images.
You will need to edit the request in the view.html.php file to have the image path.

Please Log in or Create an account to join the conversation.

  • Posts: 100
  • Thank you received: 1
12 years 2 months ago #63028

Hi Thanks for your response.

I've been trying to edit the file /components/com_hikashop/views/product/view.html.php

However my PHP skills are not fantastic, i'm not really sure what code i need to add.
From looking at the checkout/view.html.php file i think i need to add:

function _getImagesName($type){
		$images_folder = HIKASHOP_MEDIA .'images'.DS.$type.DS;
		jimport('joomla.filesystem.folder');
		$files = JFolder::files($images_folder);
		$images = array();
		foreach($files as $file){
			$parts = explode('.',$file);
			array_pop($parts);
			$name = implode('.',$parts);
			$images[$name] = $file;
		}
		$this->assignRef('images_'.$type,$images);
	}

and
$show_image = $config->get('show_cart_image');
$this->params->set('show_cart_image',$show_image);
$currencyClass = hikashop_get('class.currency');
$this->assignRef('currencyHelper',$currencyClass);
$image = hikashop_get('helper.image');
$this->assignRef('image',$image);

within the function cart()

Is this correct or am i way off?

Thanks in advanced
Sean R.

Please Log in or Create an account to join the conversation.

  • Posts: 82819
  • Thank you received: 13366
  • MODERATOR
12 years 2 months ago #63143

You're way off.
As Xavier said, you need to load the images of each product from the database. So you need to have a SQL query.
Something like that:
$db =& JFactory::getDBO();
$d->setQuery('SELECT * FROM '.hikashop_table('file').' WHERE file_ref_id='.$row->product_id);
$row->images = $db->loadObjectList();

Please Log in or Create an account to join the conversation.

Time to create page: 0.074 seconds
Powered by Kunena Forum