Opencart modification only for admins

150 Views Asked by At

I'm trying to create an ocmod for the admin panel. Basically, I want to add 2 buttons in the dashboard sidebar but only visible for users with administrator permissions.

How can I achieve that?

Note the custom views and controllers are ready.

2

There are 2 best solutions below

0
On BEST ANSWER

If you want to change anything in client page via login in admin panel as admin - can use this solution

In any controller you need add following:

if (isset($this->session->data['user_id']) && $this->session->data['user_id']) {
    $data['admin'] = true;
}   else {
    $data['admin'] = false;
}

Than in same controller's twig:

{% if admin %}
buttons on client side if admin is logged in in panel on the same browser
{% endif %}
0
On

for users with administrator permissions

What do you mean with that? In the backend you can define for each user the permissions easily. So, no checks for any session variables are needed, simply define the correct permission.

btw: if you intent to use that in future versions of OpenCart, you should use an event instead OCMod (which should be always the preferred method).