views:

30

answers:

2

Hello,

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.

A: 

Can you use Conditional Actions?

Kevin
No, CA cannot be used for this purpose.
Nikhil
+1  A: 

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
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
I have edited the answer to show how to identify the case when a order is being marked complete.
abhaga
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
If it solved your problem, please accept this as the right answer so that others who come looking will also know :)
abhaga
ok, I did that !!
Nikhil

related questions