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');
        die('jch_send_quote running here')

What am I missing?

  • Added Rule and php to question. Any ideas?
    – jchwebdev
    Jun 10 '14 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
    Oct 28 '20 at 2:40

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.

  • 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
    Jun 10 '14 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 Jun 10 '14 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
    Jun 10 '14 at 4:45
  • You would need to post your code / rule and relevant conf there, else is just guesswork. Jun 10 '14 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
    Jun 10 '14 at 18:00

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.