Post by faulksandcox » Mon May 11, 2015 11:24 pm

When I was using OC 1.5.6.1 I could do some modifications to the template depending on the customer group ID using the following:

Code: Select all

<?php $id = $this->customer->getCustomerGroupId(); ?>
When I try this in 2.0.2.0 I get the following error:

Code: Select all

Notice: Undefined property: Loader::$customer in /var/www/vhosts/domain.co.uk/catalog/view/theme/themename/template/product/product.tpl on line 3
Does anyone know what the updated code for this would be?

Thanks!

FCL
Last edited by faulksandcox on Wed May 13, 2015 5:18 pm, edited 1 time in total.

Newbie

Posts

Joined
Fri Jul 18, 2014 9:39 pm

Post by faulksandcox » Wed May 13, 2015 3:57 pm

I'm making a change to product.tpl - after doing a bit of digging yesterday I found the following:

Code: Select all

$this->customer->getCustomerGroupId();
has been changed to

Code: Select all

$this->customer->getGroupId();
I then found that to edit the product.tpl file I first have to declare the following in catalog->controller->product->product.php under the index function

Code: Select all

$data['groupId'] = $this->customer->getGroupId();
I should then be able to call the group ID in product.tpl with

Code: Select all

echo $groupId;
Whilst my research suggests this should work, I get the following error:

Code: Select all

Notice: Undefined variable: groupId in /var/www/vhosts/domain.co.uk/public/dev/vqmod/vqcache/vq2-catalog_view_theme_themename_template_product_product.tpl
Anything further on this?

Thanks! :)

Newbie

Posts

Joined
Fri Jul 18, 2014 9:39 pm

Post by faulksandcox » Wed May 13, 2015 5:24 pm

OK guys I have fixed it! (WooHoo!)

First you need to define the following in the this file:

catalog/controller/product/product.php (in the index function)

Code: Select all

$data['groupId'] = $this->customer->getGroupId();
You can then call the variable

Code: Select all

echo $groupId;
I've attached a VQMod that adds the ability to display the customer group id on the product page if anyone else should need it, you will need to alter it for your template though!

- Lea

Attachments

Get Group ID VQMod


Newbie

Posts

Joined
Fri Jul 18, 2014 9:39 pm

Post by Qphoria » Sat Jul 25, 2015 4:17 am

FYI, you don't need that extra bit in the catalog/model/catalog/product.php file

And just to explain the reasoning for why this works in 1.5 but not 2.x....
In 1.5.x, the view could directly access library calls because template was a descendant of the controller.
In 2.x, there is a layer of abstraction that prevents direct calls and requires you to set variables for anything called from the view.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 89 guests