What is the correct syntax to check if a user has permission? In my plugin, I am checking to see if the current logged in user has permission to save a commerce product.

$user = craft()-&gt;userSession-&gt;getUser();
if (craft()-&gt;userPermissions-&gt;doesUserHavePermission($user-&gt;id, 'ManageClothingProducts')) {
    // yes permission
} else {
  // no permission
};


However, it seems I'm always getting into the else.

The commerce docs mention this:


  Manage [type] products


Maybe I'm not using the correct syntax? I'm only using the clothing products as an example. Ultimately I'll be checking for my own products.

Thank you for any suggestions!
The correct permission key is:

commerce-manageProductType:ID_OF_PRODUCT_TYPE_HERE

for example:

commerce-manageProductType:2

Your code would therefore be:



$user = craft()-&gt;userSession-&gt;getUser();
if (craft()-&gt;userPermissions-&gt;doesUserHavePermission($user-&gt;id, 'commerce-manageProductType:2')) {
    // yes permission
} else {
  // no permission
};


Or you could use UserSessionService::checkPermission(), which is a shortcut for checking permissions for the currently logged-in user:

if (craft()-&gt;userSession-&gt;checkPermission('commerce-manageProductType:2')