Page 1 of 1

How to add product images to order emails of admin and customer on Opencart 2.x

Posted: Sun Sep 10, 2017 8:39 am
by gokaydemir86
Hi, I made some changes in

Code: Select all

 Model File :   \catalog\model\checkout\order.php
and

Code: Select all

 TPL File   :   \catalog\view\theme\journal2\template\mail\order.tpl
Here is my edits:
First, on order.php, around 548. line, under the code

Code: Select all

 foreach ($order_product_query->rows as $product) {
					$option_data = array();


I added:

Code: Select all

 foreach ($order_product_query->rows as $order_product) {
					$product_info = $this->model_catalog_product->getProduct($order_product['product_id']);
					if ($product_info['image']) {
						$thumbbuyuk = $this->model_tool_image->resize($product_info['image'], 130, 130);
					} else {
					$thumbbuyuk = '';
					}
					}
After that, around 581, under the code

Code: Select all

 $data['products'][] = array(
I added:

Code: Select all

'thumbbuyuk' => $thumbbuyuk,
'href' 	 => $this->url->link('product/product', 'product_id=' .$product_info['product_id']),
Finally, on order.tpl file, under the code

Code: Select all

<p style="margin-top: 0px; margin-bottom: 20px;"><?php echo $text_greeting; ?></p>
I added:

Code: Select all

<div style="text-align:center;">
		<?php foreach ($products as $product) { ?>
			<?php if ($product['thumbbuyuk']) { ?>
				<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumbbuyuk']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" /></a>
               <?php } ?>
		<?php } ?>
     </div>
Everything is looking good. And also images are shown exactly how I wanted. However, if there are more than one order,then there is a problem: When I click the images, links are always the same as the first image. That's, my edits fetch the images but links.. What is wrong in my edits? Any answer would be appreciated.

Re: How to add product images to order emails of admin and customer on Opencart 2.x

Posted: Tue Nov 14, 2017 10:26 am
by straightlight
From your addition code in the controller, replace:

Code: Select all

foreach ($order_product_query->rows as $order_product) {
					$product_info = $this->model_catalog_product->getProduct($order_product['product_id']);
					if ($product_info['image']) {
						$thumbbuyuk = $this->model_tool_image->resize($product_info['image'], 130, 130);
					} else {
					$thumbbuyuk = '';
					}
					}
					
with:

Code: Select all

foreach ($order_product_query->rows as $order_product) {
					$product_info = $this->model_catalog_product->getProduct($order_product['product_id']);
					if (!empty($product_info['image'])) {
						$thumbbuyuk = $this->model_tool_image->resize($product_info['image'], 130, 130);
						
						$images = array();

			$results = $this->model_catalog_product->getProductImages($product_info['product_id']);

			foreach ($results as $result) {
				$images[] = array(
					'thumb' => $this->model_tool_image->resize($result['image'], 130, 130)
				);
			}
					} else {
					$thumbbuyuk = '';
					}
					}
Then, below this line:

Code: Select all

'thumbbuyuk' => $thumbbuyuk,
you could add:

Code: Select all

'images' => $images,
Then, in your order.tpl file, replace:

Code: Select all

<div style="text-align:center;">
		<?php foreach ($products as $product) { ?>
			<?php if ($product['thumbbuyuk']) { ?>
				<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumbbuyuk']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" /></a>
               <?php } ?>
		<?php } ?>
     </div>
     
with:

Code: Select all

<div style="text-align:center;">
		<?php foreach ($products as $product) { ?>
			<?php if ($product['thumbbuyuk']) { ?>
				<a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumbbuyuk']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" /></a>
				<?php if ($product['images']) { ?><br />
				    <?php foreach ($product['images'] as $image) { ?>
				        <img src="<?php echo $image; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" />
				    <?php } ?>
				<?php } ?>
               <?php } ?>
		<?php } ?>
     </div>
This will show all the rest of the images along with your main image with each orders.

Re: How to add product images to order emails of admin and customer on Opencart 2.x

Posted: Wed Jan 13, 2021 7:06 am
by azonicdh
Does this code work on Opencart 3?

Re: How to add product images to order emails of admin and customer on Opencart 2.x

Posted: Wed Jan 13, 2021 12:18 pm
by straightlight
azonicdh wrote:
Wed Jan 13, 2021 7:06 am
Does this code work on Opencart 3?
If you use the Template Switcher extension, it could work. Otherwise, you'd need to convert it.