Post by Ideavelop » Tue Mar 08, 2016 6:20 pm

Hello all,

After reading and trying a view day`s i cant seem to figure it out.
i made a simple custom module (in left column) that will only show when a product is viewed.

in this module i want to show manufacture name or id from the product that is viewed, i thought because it is on the same page as the product
i just could use

Code: Select all

<?php if($product['manufacturer']){
            echo ($product['manufacturer']);
        }?>
But then i get "Notice: Undefined variable: product in xxxx"

Is there any one so kindly that can tell me what to add to the controller to get the manufacturer name or id to display

Controller code

Code: Select all

<?php  
class ControllerModuleDidyouknow extends Controller {
	protected function index() {
	


		$this->language->load('module/didyouknow');
	
		$this->data['heading_title'] = $this->language->get('heading_title');
	
				
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/didyouknow.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/didyouknow.tpl';
		} else {
			$this->template = 'default/template/module/didyouknow.tpl';
		}
		
		$this->render();
	}
}
?>
i dont ask directly on the forum as a lazy guy , but after 8 day`s i`m just stuck. :crazy:

Kind Regards
Stefan

-= Make a friend every day =-


Newbie

Posts

Joined
Mon Dec 01, 2014 6:26 pm

Post by artcore » Tue Mar 08, 2016 7:28 pm

Modules have their own scope. They can't see variables from other controllers like product, same page or not.
Why don't you check how the product controller gets the manufacturer. The manufacturer id is in the product table. You need to get its name by joinin the manufacturer description table. Something to this effect is in the product controller. Look for the product array and see how it's populated then add the missing parts to your controller :)

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by Ideavelop » Tue Mar 08, 2016 11:01 pm

Hi Artcore, (en dank je wel voor je reactie)

thnx for your reply.

i only need the manufacturer_id (that`s in the same table)

after your post i start looking in to the product controller,
and the only thing that i can get to work is to show product id :P

In my controller i added:

Code: Select all

$this->load->model('catalog/product');
		$this->data['showinfo'] = $this->request->get['product_id'];

And on the tpl page:

Code: Select all

<?php echo $showinfo; ?>
if i change it to $this->data['showinfo'] = $this->request->get['manufacturer_id'];

i get an error again, i`m not a programmer as you can tell by now :laugh: but learning.

-= Make a friend every day =-


Newbie

Posts

Joined
Mon Dec 01, 2014 6:26 pm

Post by artcore » Tue Mar 08, 2016 11:37 pm

LOL.
So in your controller first load up the product model.

Code: Select all

$this->load->model('catalog/product');
Then

Code: Select all

$product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
(using the product_id from the request)

OC model function already does the heavy lifting so you can just do:

Code: Select all

$this->data['manufacturer'] = $product_info['manufacturer'];
In the tpl: echo $manufacturer;

Untested :)

(Graag gedaan)

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands

Post by Ideavelop » Tue Mar 08, 2016 11:59 pm

HELD! (Hero)

Thnx so much!!!

-= Make a friend every day =-


Newbie

Posts

Joined
Mon Dec 01, 2014 6:26 pm

Post by artcore » Wed Mar 09, 2016 12:37 am

Kleine moeite, groot plezier ;D

For others following this, OC2+ uses $data['manufacturer'] instead of $this->

Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+ ;D

Thanks!


User avatar
Active Member

Posts

Joined
Tue Jul 09, 2013 4:13 am
Location - The Netherlands
Who is online

Users browsing this forum: No registered users and 2 guests