Page 1 of 1

Get Customer Group ID in 2.x

Posted: Mon May 11, 2015 11:24 pm
by faulksandcox
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

Re: Get Customer Group ID

Posted: Wed May 13, 2015 3:57 pm
by faulksandcox
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! :)

Re: Get Customer Group ID in 2.x

Posted: Wed May 13, 2015 5:24 pm
by faulksandcox
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

Re: Get Customer Group ID in 2.x

Posted: Sat Jul 25, 2015 4:17 am
by Qphoria
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.