1

I am using Rules to get the price in Drupal Commerce and I have three different rules to apply when I am calculating product price. The problem is that if the first one is executed I don't want to execute neither second nor third. Second one is executed if first one is not executed and the third one shouldn't be executed neither. The third one is only executed if first one and second one are not executed.

Summing up, I would like prevent the execution of subsequent rules if a previous rule is executed. How can I do that in Rules?

2

As far as your question title says "Execution Order", rules have weight which you can set in the settings tab which you will find on rule manage page.

Order rules that react on the same event. Rules with a higher weight are evaluated after rules with less weight.

As far as your query concern, it seems you need to pick up he right condition while setting up those three rules,you can also use php in the condition if your condition is quite specific.The rules automatically execute their actions based on if condition get satisfied.

  • 1
    Yeah, you basically create a complex set of conditions for each rule, so only one rule will pass the test in every possible scenario. The only thing I'd like to add is that you can use Rules Components to share conditions' building blocks between rules, so you don't have to punch it all from scratch for each of your three rules. – Gleb Varenov Oct 7 '14 at 17:34
  • What you wrote about "execution order" is correct, but I don't understand how that part helps to eventually "prevent the execution of subsequent rules". Am I missing something? Also, to use PHP in the condition, that requires the (dangerous) PHP filter to be enabled, maybe you want to add that to your answer also? – Pierre.Vriens Feb 14 '17 at 14:10
0

As a variation to the prior answer, you could also try to combine the three rules in a single rule, by using the Conditional Rules module, which allows to include the equivalent of a Rules Condition within a Rules Action. Have a look at part 2 of the answer to "How to correct my rule to prevent duplicate taxonomy terms to be created?" for a pretty advanced Rules example that uses this technique.

By using this technique, you can implement pretty complicated Rules Logic in a single rule, which possibly prevents the need for multiple rules. Moreover, it makes it possible to group related business logic in a single rule (instead of having to look at 3 different places in the admin UI to get the big picture of those rules).

Be aware however that by using this alternative solution, you better also pay attention to the correct usage of AND and OR constructs inside such custom rules (to prevent Rules from not behaving as you would expect). If you're struggling with these constructs, you may want to look at the answer to "Which is the difference of combining rules with AND or just leave them follow one each other?"

PS: I'm assuming this question is about D7 ...

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.