I'm having some issues using rules to create a role for users upon checking out with certain items in their cart. I have items of a certain type, if ANY of those items, any combination of them, or combination of them and other products, are present at checkout, I need to add a role to that user. Unfortunately, I've tried to create this rule with a high degree of failure over and over again. Attached is a breakdown of the current rule in its ineffective form. I once had these nested, one after another, after another, but this would lead to some roles being created, while others were still failing. Trying to wrap my head around this; any help is greatly appreciated.

CommentFileSizeAuthor
#7 rules-01.png9.06 KBrob de koter
rules.jpg574.04 KBthreadsniper

Comments

drstuey’s picture

Title: How to effectively use rules with multiple conditions? » Rules don't work with multiple OR conditions?
Category: support » bug

I am having this problem as well, also with multiple instances of the check products condition. What are you using for shopping cart, we are using ubercart. I wonder if this is happening for all conditions or just for the check products condition using ubercart.

I think that OR doesn't work in this case and that this should be a bug report rather than a support request. I think that it is treating the OR as an AND.

I have found that if my rule contains a single condition (Check an order's products. Parameter: Order: [order], Products: SKU12, Require selected products: true, Forbid other products: false) then it executes successfully when I make a test order containing the product with that SKU number.

If I add a second identical condition as an OR with a different product SKU number, i.e.

Check an order's products
Parameter: Order: [order], Products: SKU12, Require selected products: true, Forbid other products: false
OR
Check an order's products
Parameter: Order: [order], Products: SKU47, Require selected products: true, Forbid other products: false

then if I make a test order containing only product SKU12 then it doesn't work any more.

But if I make a test order containing both product SKU12 and SKU47 then the condition executes again.

threadsniper’s picture

We're using Drupal Commerce, and I eventually gave up and created rules for each specific product. Although tedious and sort of in direct opposition to the very concept of rules, it solved our problem short term.

However, we did find out how to eventually achieve the desired functionality in one rule. Referencing my image above, which was structured like this

Order Contains Particular Product
or
-Order Contains Particular Product
or
-Order Contains Particular Product

The rule to achieve the desired effect should read like this

Order Contains Particular Product
or
--Order Contains Particular Product
--Order Contains Particular Product
--Order Contains Particular Product

I hope this makes sense. We are still wrapping our heads around improving our usage of rules on this store. It has been a learning process. There is a lot of great resources over at the Commerce Guys site as well.

threadsniper’s picture

We're using Drupal Commerce, and I eventually gave up and created rules for each specific product. Although tedious and sort of in direct opposition to the very concept of rules, it solved our problem short term.

However, we did find out how to eventually achieve the desired functionality in one rule. Referencing my image above, which was structured like this

Order Contains Particular Product
or
-Order Contains Particular Product
or
-Order Contains Particular Product

The rule to achieve the desired effect should read like this

Order Contains Particular Product
or
--Order Contains Particular Product
--Order Contains Particular Product
--Order Contains Particular Product

I hope this makes sense. We are still wrapping our heads around improving our usage of rules on this store. It has been a learning process. There is a lot of great resources over at the Commerce Guys site as well.

tobiasb’s picture

Rules also does not work with a single OR. In my test with the condition "Promoted to frontpage".

EDIT: Ok I believe I know how to use OR/ANDs.

OR (All conditions below this or between the lines are OR-Conditions)
- condition1 (OR)
- AND  (All conditions below this or between the lines are AND-Conditions, default condition)
-- condition2 (AND)
-- condition3

This means:

condition1 OR (condition2 AND condition3)
CleopatraJ’s picture

Thanks, tobiasb, this was very helpful. At first I didn't understand, but then it clicked in my brain. To clarify for others like me--the OR needs to be at the top of the list and then the conditions are listed underneath. Woo hoo!

JAScarb’s picture

Issue summary: View changes

OK, yes, Cleopatraj, also the [add condition] button you hit has to be the one on the 'OR' condition, not the one at the bottom. Seriously unusable. I want to question (if I've got this right) the storage of the resulting data in an uneditable blob, too. So we have an interface that doesn't work, and a design that blocks us getting to the data to fix it. Great.

rob de koter’s picture

StatusFileSize
new9.06 KB

This is how it is done: ( file rules_01.png)
See this video: https://drupalize.me/videos/combining-conditions?p=1157

tr’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

Comment #2/#3 explained how this is done, and comments #4, #5, #6, and #7 confirmed that solution.

kevster’s picture

I tried the above and still having issues with commerce shipping rules (drupal 7.69, rules 7.2.12) - I was able to get my rule working by removing the OR statement and just having 4 negated conditions. If you export the rule it may expose more info that will help debug the problem.

My rule ended up allowing two shipping options when it should have only allowed one.

I need to try adding individual or statements and see if this makes a difference.

So this didnt work for me:

condition
condition
OR
- condition
- condition
- condition
- condition
(the above conditions added correctly not using the bottom add condition but the or add condition higher up)

but this did
condition
condition
OR
- condition
OR
- condition
OR
- condition
OR
- condition