0

How do I change the order in which completion rules fire?

There is a default Completition reaction rule. I wanted to add a second rule which executes some custom PHP but it's never executed.

I see no way to change the weight as in other rules. I also tried adding what I need as an action in that default rule, but it also doesn't seem to fire.

This is the reaction rule that fires on order completion.

{ "rules_completion" : {
    "LABEL" : "completion",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "php", "rules", "commerce_checkout" ],
    "ON" : [ "commerce_checkout_complete" ],
    "DO" : [
      { "php_eval" : { "code" : "jch_send_quote()" } },
      { "commerce_checkout_complete" : { "commerce_order" : [ "commerce_order" ] } }
    ]
  }

This is the code for jch_send_quote() which doesn't seem to fire.

function jch_send_quote(){ 
    global $user;
    watchdog('dev', 'jch_send_quote running here');
    drupal_set_message($user->uid);
        die('jch_send_quote running here')
}

What am I missing?

2
  • Added Rule and php to question. Any ideas?
    – jchwebdev
    Commented Jun 10, 2014 at 16:36
  • This really doesn't seem to have anything to do with the Rules module. If the commerce_checkout_complete event is not firing, that's a problem with Commerce or with your expectations. Commerce defines that event and decides when to fire it. You can test this event by using a rule which just has that event and a "Show a message on the site" action - if you don't see this message on the site when you expect that means the event is not firing, and you need to investigate what circumstances that event is supposed to fire to determine what you should expect here.
    – anonymous
    Commented Oct 28, 2020 at 2:40

1 Answer 1

0

You should be able to edit the rule and set it's weight:

Set weight of reaction rule

Screenshot, showing reaction rule with weight of "2"

Lastly, your rule should still fire, even with a different weight. If it's not firing, it's probably an issue with that rule itself.

5
  • First, I can change the Weight inside the Reaction Rule edit form, but when I save and return to the Rules View, every Rule appears with a Weight of 0... at least those in 'Completion' for Commerce. Second, I -thought- that all the Reaction Rules should fire. I simply added a die() message and it never 'dies' or displays. Is there a fool-proof way to see if/when my code is firing? I'm on a shared host without Devel. Thanks again. ---JC
    – jchwebdev
    Commented Jun 10, 2014 at 3:26
  • 1
    The weight should save and be non-zero if set as such. If that's not the case, something else is broken there. In regards to debug, you could try watchdog. e.g watchdog('dev', 'code running here'); then check in admin > reports > recent log entries Commented Jun 10, 2014 at 3:29
  • Thanks. I tried watchdog() and nothing is appearing in the recent log entries. Any other ideas on what could be going on?
    – jchwebdev
    Commented Jun 10, 2014 at 4:45
  • You would need to post your code / rule and relevant conf there, else is just guesswork. Commented Jun 10, 2014 at 5:44
  • I added code and rule above. Although I think now this is a conceptual issue. The completion rule is -never- firing... which I don't understand. Can you recommend a tutorial or doc which explains this process?
    – jchwebdev
    Commented Jun 10, 2014 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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