drupal :: order complete hook and upgrade user permission/roles

梦想的初衷 提交于 2019-12-12 11:58:06

问题


I want to be able to upgrade user's permission after the order status shows complete.

I figured out that I should use hook_order hook in order to achieve that. But how do I get to know which user has created that order and how do go about updating the permissions as well as setting up the expire time for that role automatically.

I want this hook to be called as soon as the payment is made and the order is completed.

Any pointers will be valuable.


回答1:


In the hook_order, 3 parameters are passed. Third parameter depends on the first one. When the first parameter is 'update', third parameter is the status to which the order is going.

hook_order($op, &$order, $arg2){
    switch($op){
        case 'update':
            if($arg2 === 'completed'){
                // This order got marked completed
            }
    }
}

$order->uid will give you the user that created the order. You can do something like the following

$user = user_load(array('uid' => $order->uid));
// update the roles assigned to user
user_save($user);

For expiring the role, you will need to write a module that will keep track of the duration and will do something like above when the time expires. Or you can use role_expire module and see if that helps.



来源:https://stackoverflow.com/questions/3270059/drupal-order-complete-hook-and-upgrade-user-permission-roles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!