4

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.

Nikhil
  • 1,268
  • 2
  • 13
  • 29

1 Answers1

3

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.

abhaga
  • 5,455
  • 2
  • 21
  • 20
  • but how can I know if the order status has become 'completed', I want the hook to be called only when the orders completes. – Nikhil Jul 19 '10 at 10:12
  • I have edited the answer to show how to identify the case when a order is being marked complete. – abhaga Jul 19 '10 at 15:06
  • Ok, I get it. Now I just have to write another function to update user roles and add it in the hook_order function. – Nikhil Jul 20 '10 at 03:25