drupal ::订单完成钩子并升级用户权限/角色 [英] drupal :: order complete hook and upgrade user permission/roles

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

问题描述

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

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

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

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希望这个挂钩在付款完成后立即被调用,订单完成。

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天全站免登陆