1

In drupal commerce I want the rules module to do some action when the order status changes to completed. In fact, after buying some product an order is added to order list. Then, what I need is that when the moderator comes and change the order status to completed the order owner get permission to see some content type.

I have tested these rules but none of them worked!!

  • Event: After updating an existing commerce order
  • Condition: Execute custom PHP code

    if([commerce-order:status] == 'completed') return TRUE;
    else return FALSE;
    

or this one:

  • Event: After updating an existing commerce order
  • Condition: Data comparison

    Parameter: Data to compare: [commerce-order:status], Data value: Completed
    

or this one:

  • Event: After updating an existing commerce order
  • Condition: Data comparison

    Parameter: Data to compare: [commerce-order:state], Data value: Completed
    

In fact, without adding any condition the reaction is done after adding an order by customers (do not wait for moderators to complete the order) and with any of these conditions, rules never fire and the is reaction never done.

  • In fact, without adding any condition the reaction is done after adding an order by customers That is to be expected, in that case the rule fires every time the order is updated. Both status and state checks look good. Strange they don't work. – Neograph734 Jun 6 '16 at 18:37
  • @Neograph734 yes that's strange. Any other idea? – shekoufeh Jun 6 '16 at 19:43
  • check recent log messages [admin/reports/dblog]. Maybe there is an issue with the action that you're trying to fire. You can add [Show a message on the site] as an action, to test if event with condition can trigger anything at all. – oksana-c Jun 6 '16 at 20:23
  • what do you mean by "test if event with condition can trigger anything at all" ? I add reaction of "show a message on the site" and printed the value of order state and order status. that was OK – shekoufeh Jun 6 '16 at 21:00
  • Did that also work combined with the data comparison condition? – Neograph734 Jun 6 '16 at 21:31
0

According to the details provided by you in comments, your rule is assigning new role to the user who is currently editing the order [site:current-cart-order:owner].

You need to use [commerce-order:owner] token in "Add User Role" action.

[commerce-order:owner] represents the user who created the order, and not the user who is editing it.

0

Given below is the example rule to update user role on order status update:

{ "rules_update_user_role_on_order_complete" : {
    "LABEL" : "Update user role on order complete",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "order" ],
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : { "commerce_order_update" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "completed" } }
    ],
    "DO" : [
      { "user_add_role" : {
          "account" : [ "commerce-order:owner" ],
          "roles" : { "value" : { "3" : "3" } }
        }
      }
    ]
  }
}

Here you need to change the user role of the order owner in action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.