Post by scottyboyyy » Mon Sep 18, 2017 9:04 pm

Along with the thumb I want to display the first additional image of the product, does anyone know how to do this?

Here is the code in category.tpl for the thumb which is loaded from category.php in the controller

Code: Select all

<div class="product-thumb">
            <div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
            <div>
I know that the category.php needs modified to load the additional image so that it can be called onto category.tpl but my coding knowledge isn't good enough.

Any help would be appreciated!

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by DigitCart » Mon Sep 18, 2017 9:40 pm

Hi,
In category.php Find:

Code: Select all

$data['products'][] = array(
	'product_id'  => $result['product_id'],
	'thumb'       => $image,

Replace with:

Code: Select all

$image_results = $this->model_catalog_product->getProductImages($result['product_id']);

if ($image_results) {
	$image2 = $this->model_tool_image->resize($image_results[0]['image'], $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
} else {
	$image2 = false;
}

$data['products'][] = array(
	'product_id'  => $result['product_id'],
	'thumb'       => $image,
	'thumb2'       => $image2,

Then in category.tpl, inside the foreach use it:

Code: Select all

<?php if($product['thumb2']){ ?><img src="<?php echo $product['thumb2']; ?>"><?php } ?>
I tested this with OpenCart 2.3.0.2

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by scottyboyyy » Mon Sep 18, 2017 10:12 pm

Exactly what I was wanting to achieve thanks a lot for your help!

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by DigitCart » Mon Sep 18, 2017 10:15 pm

scottyboyyy wrote:
Mon Sep 18, 2017 10:12 pm
Exactly what I was wanting to achieve thanks a lot for your help!

You're welcome.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm

Who is online

Users browsing this forum: No registered users and 306 guests