'Opencart modification only for admins

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.



Solution 1:[1]

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 %}

Solution 2:[2]

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).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 focus.style
Solution 2 OSWorX