Page 1 of 1

Display Manufacturer Images on Product.tpl

Posted: Tue Jul 26, 2011 12:45 pm
by xc0n
hey i have a problem, Im trying to display the Manufacturer Image on each Product, example if the product is a sony, and the admin has sony as a manufacturer and an image it will display on the product.tpl page.

I found a thread to display it in the category listing but that method doesnt work when i try to call the image on the product page.

Im using opencart version 1.4.9.3

thanks

Re: Display Manufacturer Images on Product.tpl - PLEASE HELP

Posted: Tue Jul 26, 2011 1:25 pm
by amdev
Note*** FOR 148x149x ONLY.

there r 3 steps.(Backup your system before.)

1. edit this file

Code: Select all

\catalog\model\catalog\product.php


find public function getProduct($product_id) {.........} and replace to this code.

Code: Select all

	public function getProduct($product_id) {
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer,m.image AS mimage, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
	
		return $query->row;
	}

or manually add m.image AS mimage to select command.

SAVE.

2.Edit

Code: Select all

\catalog\controller\product\product.php


find this line

Code: Select all

			$this->data['popup'] = $this->model_tool_image->resize($image, $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
Add this code before.

Code: Select all

			if ($product_info['mimage']) {
				$mimage = $product_info['mimage'];
			} else {
				$mimage = 'no_image.jpg';
			}
			$this->data['mthumb'] = $this->model_tool_image->resize($mimage, 120, 120);

SAVE.
3.edit your product.tpl and put this code to anywhere that u want to dispaly a image.

Code: Select all

<img src="<?php echo $mthumb;?>" title="<?php echo $manufacturer; ?>" alt="<?php echo $manufacturer; ?>" />
Good luck guy.

Re: Display Manufacturer Images on Product.tpl

Posted: Tue Jul 26, 2011 2:41 pm
by xc0n
YES!! thanks so much it worked first go!

Re: Display Manufacturer Images on Product.tpl

Posted: Thu Jul 28, 2011 2:11 am
by DKeff
This is exactly what I've been trying to do today! ;D

But I'm not sure I know what code to replace in step 1.
find public function getProduct($product_id) {.........} and replace to this code.
My code looks in this file looks like so...

Code: Select all

public function getProduct($product_id) {
		if ($this->customer->isLogged()) {
			$customer_group_id = $this->customer->getCustomerGroupId();
		} else {
			$customer_group_id = $this->config->get('config_customer_group_id');
		}	
				
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
		if ($query->num_rows) {
			return array(
				...
So which part do I replace to do this?

Re: Display Manufacturer Images on Product.tpl

Posted: Thu Jul 28, 2011 11:06 pm
by DKeff
Can anyone give me a hand with this.

I am using 1.5 and the coding seems quite different but this is exactly what I need to accomplish.

If I replace the code with what amdev posted in 1.5. The manufacturer image shows up, but I get a whole other wack of problems & errors.

I am trying to replace

Code: Select all

public function getProduct($product_id) {
		if ($this->customer->isLogged()) {
			$customer_group_id = $this->customer->getCustomerGroupId();
		} else {
			$customer_group_id = $this->config->get('config_customer_group_id');
		}	
			
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, m.image AS mimage, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
with this

Code: Select all

[quote]public function getProduct($product_id) {
      $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer,m.image AS mimage, ss.name AS stock FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");
   
      return $query->row;[/quote]
Which I knew right away wouldn't work as I'm eliminating a lot of the code - but it actually does load the image I need, but I get the following errors.

Notice: Undefined index: reward in /Applications/MAMP/htdocs/loco-wholesale/catalog/controller/product/product.php on line 182Notice: Undefined index: special in /Applications/MAMP/htdocs/loco-wholesale/catalog/controller/product/product.php on line 235Notice: Undefined index: special in /Applications/MAMP/htdocs/loco-wholesale/catalog/controller/product/product.php on line 242Notice: Undefined index: reviews in /Applications/MAMP/htdocs/loco-wholesale/catalog/controller/product/product.php on line 303Notice: Undefined index: rating in /Applications/MAMP/htdocs/loco-wholesale/catalog/controller/product/product.php on line 304

Re: Display Manufacturer Images on Product.tpl

Posted: Fri Jul 29, 2011 9:26 am
by amdev
Hi DKeff, above of my code for 14x only.

for 15x(I'm tested with 1.5.1.2 SVN At revision: 515 it's work fine.)

1. edit \catalog\model\catalog\product.php
add m.image AS mimage to SELECT command.

Code: Select all

	public function getProduct($product_id) {
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer,m.image AS mimage,....
In the same function add this code.

Code: Select all

				'mimage'           => $query->row['mimage'],
after.

Code: Select all

				'manufacturer'     => $query->row['manufacturer'],
2.edit \catalog\controller\product\product.php

find this line(about line 193).

Code: Select all

			$this->load->model('tool/image');
add this code after.

Code: Select all

			$this->data['mimage'] = $this->model_tool_image->resize($product_info['mimage'],150,150);
3.edit your product.tpl and put this code to anywhere that u want to dispaly a image.

Code: Select all

 <img src="<?php echo $mimage; ?>" alt="blah blah blah" />

Goodluck guys.

Re: Display Manufacturer Images on Product.tpl

Posted: Fri Jul 29, 2011 4:23 pm
by alin
Hi,
This is what i need, I don't know if it worked on 1.5.0.5, I'll try and report the result,
Thanks...

Re: Display Manufacturer Images on Product.tpl

Posted: Fri Jul 29, 2011 5:22 pm
by alin
Hey,
It worked fine on 1.5.0.5,
I have tried to do this for some some hour but can not make it work, now thanks to this topic, it worked
I applied this for latest and product detail also,
This is result http://www.goleo.vn

Thanks so much.

Re: Display Manufacturer Images on Product.tpl

Posted: Sat Jul 30, 2011 2:14 am
by DKeff
Awesome amdev!

Thanks SO MUCH!

Working with 1.5.0

Thanks again amdev,

- Dave

Re: Display Manufacturer Images on Product.tpl

Posted: Tue Nov 22, 2011 4:38 am
by emmetje
Thanks, exactly what I was looking for. Works also for 1.5.1.3, just skip the second part of step 1

Re: Display Manufacturer Images on Product.tpl

Posted: Fri Dec 02, 2011 5:33 pm
by makingtrails
Does anyone know if a mod has been created for this? I'm not overly happy about editing core files and also can't get this to work?

Exactly where do I put this within the function?
In the same function add this code.

Code: Select all
'mimage' => $query->row['mimage'],



after.

Code: Select all
'manufacturer' => $query->row['manufacturer'],

Code: Select all

public function getProduct($product_id) {
		if ($this->customer->isLogged()) {
			$customer_group_id = $this->customer->getCustomerGroupId();
		} else {
			$customer_group_id = $this->config->get('config_customer_group_id');
		}	
				
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, m.image AS mimage, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
		
		if ($query->num_rows) {
			$query->row['price'] = ($query->row['discount'] ? $query->row['discount'] : $query->row['price']);
			$query->row['rating'] = (int)$query->row['rating'];
			
			return $query->row;
		} else {
			return false;
		}
	}
Cheers

J

Version 1.5.1.3

Re: Display Manufacturer Images on Product.tpl

Posted: Mon Dec 19, 2011 9:41 pm
by stuh
Hi, I have also tried this in 1.5.1.3 but the image is not pulled in.
I get

Code: Select all

<img src alt >
in the code

I did miss out the second part of Step 1 as suggested but it appears that makes it not work.

Anyone any ideas

Re: Display Manufacturer Images on Product.tpl

Posted: Fri Nov 08, 2013 2:40 am
by dynozor
Works perfect for me in 1.5.5.1
thank you

I would like to use it to the modules if it is possible?
(bestseller, featured etc...)

can you tell me how?
thanks
amdev wrote: ...

1. edit \catalog\model\catalog\product.php
add m.image AS mimage to SELECT command.

Code: Select all

	public function getProduct($product_id) {
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer,m.image AS mimage,....
In the same function add this code.

Code: Select all

				'mimage'           => $query->row['mimage'],
after.

Code: Select all

				'manufacturer'     => $query->row['manufacturer'],
2.edit \catalog\controller\product\product.php

find this line(about line 193).

Code: Select all

			$this->load->model('tool/image');
add this code after.

Code: Select all

			$this->data['mimage'] = $this->model_tool_image->resize($product_info['mimage'],150,150);
3.edit your product.tpl and put this code to anywhere that u want to dispaly a image.

Code: Select all

 <img src="<?php echo $mimage; ?>" alt="<?php echo $manufacturer; ?>" align="right" border="1px"/>

Re: Display Manufacturer Images on Product.tpl

Posted: Sat Jul 28, 2018 1:04 pm
by CCITS
This topic is great! May i know if i kindly ask on how can we add another extra field for image in product_form.tpl? and show the image it on product page?

Thank you