drupal :: 订购完整的挂钩并升级用户权限/角色

发布于 2024-09-10 17:23:39 字数 159 浏览 3 评论 0原文

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

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

我希望在付款和订单完成后立即调用此钩子。

任何指示都会很有价值。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活泼老夫 2024-09-17 17:23:39

hook_order中,传递了3个参数。第三个参数取决于第一个参数。当第一个参数是“更新”时,第三个参数是订单将要进入的状态。

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

$order->uid 将为您提供创建订单的用户。您可以执行如下操作。

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文