Problem/Motivation
With Commerce 2.x Condition groups apply AND/OR functionality to your entire list of conditions. This is helpful, but quite limited. If you want one condition to be mandatory, and one of two other conditions, it can't be accomplished through the UI.
Proposed resolution
Since we now have a drag and drop table, we should allow nesting conditions under AND and OR logic, similar to the Rules interface.
User interface changes
Rules UI AND/OR nesting can certainly be confusing to new-comers, but has proven to me at least to be very dependable once it's learned. We could make it a little more user friendly, and provide a brief video on how to properly nest conditions.
API changes
For this to work correctly, we will at least need to provide the option to disable the ConditionGroups options when the module is installed:
^^ These of course would create conflicting logic with a nested approach.
Remaining Tasks
Do it.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | Screenshot (269).png | 41.69 KB | tonytheferg |
| #10 | Screenshot (268).png | 54.88 KB | tonytheferg |
| #8 | Screenshot (263).png | 29.87 KB | tonytheferg |
| #7 | 3221291-7.patch | 8.44 KB | tonytheferg |
| #6 | 3221291-6.patch | 12.83 KB | tonytheferg |
Issue fork commerce_conditions_plus-3221291
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
mglamanComment #5
mglamanThis works allowing an OR

Comment #6
tonytheferg commentedHere's a patch of the MR.
Comment #7
tonytheferg commentedLooks like the class got removed in the merge request.
Here is a patch with the class.
Comment #8
tonytheferg commented2 conditions under an OR statement seem to work, but I am noticing this when I have one condition, then and OR, and 2 conditions under the OR.
TypeError: Argument 2 passed to Drupal\commerce_conditions_plus\ConditionsEvaluator::evaluateConditionGroup() must be of the type string, null given, called in /var/www/html/web/modules/contrib/commerce_conditions_plus/src/ConditionsEvaluator.php on line 51 in Drupal\commerce_conditions_plus\ConditionsEvaluator->evaluateConditionGroup() (line 66 of /var/www/html/web/modules/contrib/commerce_conditions_plus/src/ConditionsEvaluator.php)This condition should validate if the shipment weight is under 1 lb, and
EITHERthe category existsORthe total is over $75Comment #9
tonytheferg commentedHere is an example of a free first class shipping method to show how the nested conditions should work.
Because we are currently using
ANDas the default operator, if the table does not begin with anORoperator, then the nest begins withANDlogic.Important: When nesting conditions, the nested operator inherits it's parent operator logic.
(I will follow up with a condition set that starts with
ORand nests anANDin the near future.)Here is what the table will look like:
AND EITHERORSo the first condition must pass,
ANDone of the twoORconditions must also pass.ANDthe Order product categories contains the free first class shipping categoryANDthe Current order total is greater than $74.99A side note on the default operator logic
When considering how to make this cooperate with the existing conditions group logic, I think instead of setting the base logic to a default
- All conditions must pass
- Only one condition must pass
AND, we could potentially just pass the ConditionGroups options as default value.Either way the added operators will govern their nested conditions, so the default value only governs where the conditions aren't nested.
Comment #10
tonytheferg commentedOk, I actually have this working, starting with an AND condition.

ANDANDEITHEROrder product categories contains the free first class shipping categoryORCurrent order total is greater than $74.99Our
ORoperator is indeed receiving the parentANDoperator in the array, so I think we are moving in the right direction.Comment #11
tonytheferg commentedNoticing this in the logs upon saving the form:
Notice: Undefined index: configuration in Drupal\commerce\Plugin\Field\FieldWidget\ConditionsWidget->massageFormValues() (line 181 of /var/www/html/web/modules/contrib/commerce/src/Plugin/Field/FieldWidget/ConditionsWidget.php)Comment #12
tonytheferg commentedMore findings confirming #10 with nesting. The first operator needs a
[parent]operator set. The picture below works, but it required an initialANDoperator to provide a[parent]for theOR.It would not work without it.
This validates correctly if:
EITHERThe Shpping addres is US,ORBOTHthe Current order total is less than $200ANDthe product category does not exist in the order.Seeing that
[parent]is empty on the first operator introduced to the table, we should do one of the following:[parent]set tocommerce_conditions_plus_and_operator,commerce_conditions_plus_and_operatororcommerce_conditions_plus_or_operator. We could then hook into the description to clarify its purpose when using it with conditions plus.Comment #13
tonytheferg commentedActually #12 is not working, I don't think. It seems you can nest an
ORunder anAND, but you can't nest anANDunder anOR.Even when removing the 1st
ANDin the picture above, when you introduce a nestedAND, it seems to set the logic for the whole tree asAND.Comment #15
mglamanComment #16
tonytheferg commented