user7837718
user7837718

Reputation:

Opencart 2.1.3 | Display one additional image along with thumb on category.tpl

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

I know that the category.php in the Controller needs modified to load the additional image so that it can be called onto View category.tpl but my coding knowledge isn't good enough. I have tried using the code from the product but I am not entirely sure how the additional images are being called there either.

Any help would be appreciated!

Upvotes: 0

Views: 541

Answers (1)

DigitCart
DigitCart

Reputation: 3000

Although there is no OpenCart version 2.1.3, Here is the way you can show first additional image in category page.

In category.php Find:

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

Replace with:

$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:

<?php if($product['thumb2']){ ?><img src="<?php echo $product['thumb2']; ?>"><?php } ?>

I tested this with OpenCart 2.3.0.2

Source

Upvotes: 1

Related Questions