开发者

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

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜