Page 1 of 1

[Solved ]2.3.0.2 - Simple conditional statement for footer

Posted: Wed May 31, 2017 3:38 pm
by GilesM
Hi all - stuck again - finding the OpenCart learning curve fairly steep! MVC-L causing me all sorts of headaches!!

I understand from reading around that you cannot use $this in template file now.

So I have read quite a few posts and worked out that I think I need to define the $data['customer_group_id'] in the footer controller.

catalog/controller/common/footer.php

Code: Select all

if ($this->customer->isLogged()) {
     $data['customer_group_id'] = $this->customer->getGroupId();
} else {
     $data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
Then I thought I would be able to use it in: catalog/view/theme/mytheme/template/common/footer.tpl

Code: Select all

if ($data['customer_group_id'] == 0) {
     // default customer
} else {
     // wholesale customer
}
I just get an undefined variable notice.

Sorry I am such a newb round here - making the leap from osCommerce is proving a bit of a shock to the system!

Re: 2.3.0.2 - Simple conditional statement for footer

Posted: Wed May 31, 2017 4:49 pm
by artcore
Hi Giles,
The $data array is 'extracted' using php's extract() function meaning that the variable will be available as $customer_group_id; in your tpl
http://php.net/manual/en/function.extract.php

Re: 2.3.0.2 - Simple conditional statement for footer

Posted: Wed May 31, 2017 5:47 pm
by GilesM
Thanks Artcore. ;D