drupal :: 订购完整的挂钩并升级用户权限/角色 [英] drupal :: order complete hook and upgrade user permission/roles

查看:17
本文介绍了drupal :: 订购完整的挂钩并升级用户权限/角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在订单状态显示完成后升级用户的权限.

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

我发现我应该使用 hook_order 钩子来实现这一点.但是我如何知道哪个用户创建了该订单,以及如何更新权限以及自动设置该角色的过期时间.

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.

推荐答案

hook_order中,传递了3个参数.第三个参数取决于第一个.当第一个参数是'update'时,第三个参数是订单的状态.

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 会给你创建订单的用户.您可以执行以下操作

$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);

为了使角色到期,您需要编写一个模块来跟踪持续时间,并在时间到期时执行上述操作.或者您可以使用 role_expire 模块,看看是否有帮助.

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.

这篇关于drupal :: 订购完整的挂钩并升级用户权限/角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆