Tags/topics: 
2
Answers
Vote up!
1
Vote down!

Create Rule to trigger an action for each status update of an order?

I have requirement of assigning points to the user when he places an order.

The points should be debited/credited to the user(order owner) based on the below condition.

1) The points should be credited to the user, when the user's order status changes to COMPLETED.
2) The points should be debited from the user, when the user's order status changed from COMPLTED to any other status.

Please provide me some suggestion on this.

thanks,
Sathishkumar V

Asked by: sathishdevan
on March 6, 2013

2 Answers

Vote up!
2
Vote down!

Have a look at the event "After updating an existing commerce order".
It fires when the users order is changed.

Then create 2 Rules based on that event:
the first to assign the userpoints:
add the event
add 2 conditions:
1 condition that checks if the OLD order state (commerce-order-unchanged:state) is NOT equal to 'completed' (use the negate checkbox)
1 condition that checks if the new state (commerce-order:state) equals 'completed'
add 1 action that assigns the userpoints to the user belonging to that order.

then add the second Rule
same event
1 condition that checks if the OLD order state is 'Completed'
1 condition that checks if the new order state is NOT 'Completed'
and an action that takes away the userpoints from the user that made that order

I hope this points you in the right direction. Make sure to test the Rule configuration thoroughly as I am doing most of this from the top of my head. I did not check if this actually works.

Answer by: S1L
Posted: Mar 6, 2013
Vote up!
1
Vote down!

Create field in account settings with hidden display( for points )
--------------------------------------------------
Name:Credits
machine name: field_credits

Create 2 Rules
-----------------------
For Crediting points
------------------------------

Event:
* After updating an existing commerce order

Conditions :
* Data comparison ( Parameter: Data to compare: [commerce-order:status], Data value: Completed )
* AND
* NOT Data comparison ( Parameter: Data to compare: [commerce-order-unchanged..., Data value: [commerce-order:status] )

Action:
* Calculate a value ( Parameter: Input value 1: [commerce-order:owner:field_credits, Input value 2: 5, operator: (+), Provides variables: Calculation result (result))
* Set a data value ( Parameter: Data: [commerce-order:owner:field_credits, Value: [result] )

For Debiting points
------------------------------

Event:
* After updating an existing commerce order

Conditions :
* Data comparison ( Parameter: Data to compare: [commerce-order-unchanged:status, Data value: Completed )
* AND
* NOT Data comparison ( Parameter: Data to compare: [commerce-order-unchanged:status, Data value: [commerce-order:status] )
Action:
* Calculate a value ( Parameter: Input value 1: [commerce-order:owner:field_credits, Input value 2: 5, operator: (-), Provides variables: Calculation result (result))
* Set a data value ( Parameter: Data: [commerce-order:owner:field_credis, Value: [result] )

points 5 to be added with credit & subtracted with debit while changing status of commerce order

Answer by: sathiakumar
Posted: Mar 7, 2013