Post by xc0n » Tue Jul 26, 2011 12:45 pm

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

Newbie

Posts

Joined
Tue Jul 26, 2011 12:40 pm

Post by amdev » Tue Jul 26, 2011 1:25 pm

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.
Last edited by amdev on Fri Jul 29, 2011 9:27 am, edited 1 time in total.

ร้านค้าออนไลน์
OpenCart Thailand Support Forum
How to Upgrade oc1.5 to 2.0.1.1
Upgrading OpenCart From v.1.4 or v.1.5 to V.2.2 Step by step


User avatar
Active Member

Posts

Joined
Fri Nov 27, 2009 3:40 pm
Location - Bangkok - Thailand

Post by xc0n » Tue Jul 26, 2011 2:41 pm

YES!! thanks so much it worked first go!

Newbie

Posts

Joined
Tue Jul 26, 2011 12:40 pm

Post by DKeff » Thu Jul 28, 2011 2:11 am

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?

Newbie

Posts

Joined
Thu Jul 28, 2011 2:06 am

Post by DKeff » Thu Jul 28, 2011 11:06 pm

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

Newbie

Posts

Joined
Thu Jul 28, 2011 2:06 am

Post by amdev » Fri Jul 29, 2011 9:26 am

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.

ร้านค้าออนไลน์
OpenCart Thailand Support Forum
How to Upgrade oc1.5 to 2.0.1.1
Upgrading OpenCart From v.1.4 or v.1.5 to V.2.2 Step by step


User avatar
Active Member

Posts

Joined
Fri Nov 27, 2009 3:40 pm
Location - Bangkok - Thailand

Post by alin » Fri Jul 29, 2011 4:23 pm

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...

GOLDEN LEOPARD SYSTEM SOLUTION
An ICT System Solution Company in Vietnam
Website: Store: http://shopcartplus.com or http://www.opencart.com/index.php?route ... rname=alin


User avatar
Active Member

Posts

Joined
Fri Jun 10, 2011 8:16 pm


Post by alin » Fri Jul 29, 2011 5:22 pm

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.

GOLDEN LEOPARD SYSTEM SOLUTION
An ICT System Solution Company in Vietnam
Website: Store: http://shopcartplus.com or http://www.opencart.com/index.php?route ... rname=alin


User avatar
Active Member

Posts

Joined
Fri Jun 10, 2011 8:16 pm


Post by DKeff » Sat Jul 30, 2011 2:14 am

Awesome amdev!

Thanks SO MUCH!

Working with 1.5.0

Thanks again amdev,

- Dave

Newbie

Posts

Joined
Thu Jul 28, 2011 2:06 am

Post by emmetje » Tue Nov 22, 2011 4:38 am

Thanks, exactly what I was looking for. Works also for 1.5.1.3, just skip the second part of step 1

User avatar
New member

Posts

Joined
Wed Jun 22, 2011 2:18 am

Post by makingtrails » Fri Dec 02, 2011 5:33 pm

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

User avatar
New member

Posts

Joined
Fri Nov 25, 2011 7:11 pm

Post by stuh » Mon Dec 19, 2011 9:41 pm

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

Newbie

Posts

Joined
Mon Dec 19, 2011 9:38 pm

Post by dynozor » Fri Nov 08, 2013 2:40 am

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"/>

  • OpenCart : Version 1.5.5.1
  • Hébergeur : OVH
  • Template installé : green_electronic (modifié)
  • PHP : ....
  • vqmod : 2.3.2
  • Site : http://moto-dynozor.com


User avatar
New member

Posts

Joined
Thu Oct 25, 2012 7:39 pm

Post by CCITS » Sat Jul 28, 2018 1:04 pm

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

Newbie

Posts

Joined
Wed Jul 25, 2018 11:54 am
Who is online

Users browsing this forum: No registered users and 6 guests