Post by cableintel » Tue Feb 26, 2019 10:55 pm

Hello.

How do i hide a category from users that are not logged in or aren't in a certain user group?

I've tried hiding the category from the top menu and side categories from non-logged in users using the following code in the header & category template files:

Code: Select all

<?php if (!$logged) { ?>
    <?php if ($category['category_id'] == 836) continue; ?> 
<?php } ?>
This hides the category from the side menu when the user isn't logged in, but when logged in it fails to re-appear, and it has no effect on the category in the top menu.

Any ideas?

Not looking for extensions that i need to pay for at the moment.

Newbie

Posts

Joined
Tue Feb 26, 2019 10:50 pm

Post by straightlight » Wed Feb 27, 2019 2:40 am

You first need to define the $logged variable in the catalog/controller/product/category.php file from the index() method:

Code: Select all

$data['logged'] = ($this->customer->isLogged() ? true : false);

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by cableintel » Wed Feb 27, 2019 6:23 pm

straightlight wrote:
Wed Feb 27, 2019 2:40 am
You first need to define the $logged variable in the catalog/controller/product/category.php file from the index() method:

Code: Select all

$data['logged'] = ($this->customer->isLogged() ? true : false);
Thanks for the reply. I've tried this and it appears to be quite unpredictable. Returning true and false on different pages when the user is logged in or out. :-\ Any ideas?

Newbie

Posts

Joined
Tue Feb 26, 2019 10:50 pm

Post by OSWorX » Wed Feb 27, 2019 6:56 pm

cableintel wrote:
Wed Feb 27, 2019 6:23 pm
I've tried this and it appears to be quite unpredictable. Returning true and false on different pages when the user is logged in or out.
And why is that 'quite unpredictable' ??
Maybe you know more than we?

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by straightlight » Wed Feb 27, 2019 8:18 pm

cableintel wrote:
Wed Feb 27, 2019 6:23 pm
straightlight wrote:
Wed Feb 27, 2019 2:40 am
You first need to define the $logged variable in the catalog/controller/product/category.php file from the index() method:

Code: Select all

$data['logged'] = ($this->customer->isLogged() ? true : false);
Thanks for the reply. I've tried this and it appears to be quite unpredictable. Returning true and false on different pages when the user is logged in or out. :-\ Any ideas?
This method is the definite way to validate logged in customers since the $this->customer->isLogged() method is linked with the customer's session through the database and the browser.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 5 guests