Search code examples
mysqlcs-cart

mysql query in cs-cart


I am working on CS-Cart CMS. I would like to grab the usergroup_id value of the current user that made an order. Thus, all I have for now is this code:

So, I have this line of code inside usergroup.tpl file:

{include file="common/usergroup.tpl" id=$order_info.user_id}

usergroup.tpl is a custom file that I have already create. Now, in this file I would like to create a mysql query in order to take the usergroup id of current user ($order_info.usergroup_id) for example 54.. So, I have this query

$_usergroup = db_query('SELECT usergroup_id FROM cscart_usergroup_links WHERE user_id=$id');

{if $_usergroup == 3}
    hello!
{/if}

How can I do this query to work?

thanks in advance!


Solution

  • You should consider to start using CS-Cart's built-in flexible permissions system, otherwise your modifications will become a hell after some time.

    Each usergroup may have many attached privileges that will be inherited by usergroup members. A privilege is an allowance to perform any specific action, for example "Manage payments" or "Edit files". There are built-in default privileges that you can use. You may assign them to the specific usergroup by going to Customers->Usergroups->Click on any usergroup->"Privileges" tab.

    Each privilege has its own identifier that can be used in the PHP/Smarty code to check whether the user belongs to the usergroup that has that privilege.

    For example, if you want to check whether the user that have created the order can edit any order, the code will look like:

    {if $order_info.user_id|fn_check_user_access:"edit_order"}
        <h3>The user that posted this order can also edit other orders!</h3> 
    {/if}
    

    The full list of built-in privilege identifiers can be found at the "privileges" table.

    You can also add your own privileges by inserting them into the "privileges" table when installing your add-on.