Logical Operators (And, Or, Not) in Order Rules

This article explains the use of logical operators in DropStream order rules.

Contents

Overview

DropStream rule language includes logical operators (also known as boolean operators) AND, OR and NOT that you can use to create more complex rules, and in this way exert greater control over your order fulfillment workflow.

For example, if orders that are being shipped to Canada and require a signature need to be shipped via FedEx International Priority, you can set up a rule that checks that both these conditions hold.

Logical operators have the following meanings in DropStream:

  • AND - both conditions need to hold for the rule to apply.
    • E.g. use a particular shipping company if the shipping address is Canada AND a signature is required.
  • OR - only one of the conditions needs to hold for the rule to apply.
    • E.g. reject orders if the shipping destination country OR the billing address country is Great Britain.
  • NOT - the rule will apply to anything that is not the value that you set.
    • E.g. filter out all order items that do not match certain SKUs.

Example

We demonstrate the use of logical operators by creating a rule for the first example above that contains a conjunction / AND (if the shipping address of an order is Canada AND a signature is required then ship the order via FedEx International Priority). 

  1. Open the desired store.
  2. Go to the Rules tab. 

    DropStream - Rules
  3. Click +Add rule

    DropStream - Add a rule
  4. Give your rule a descriptive name. Then click +Add action.

    DropStream - Add an action
  5. Select an action to perform from the dropdown, e.g. Condition.

    DropStream - Add a condition
  6. Select your logical operator from the dropdown next to IF. For this example we will be using AND because we want the order to meet BOTH conditions.

    DropStream - Add a conjuction
  7. In the dropdown menus next to your operator, select Compare Order Attribute to determine the conditions that you want to have met. In this case we want the Shipping Address to be Canada AND a signature is required.

    DropStream - Add a shipping address
  8. Click the blue +Add action  button in the active rule window.

    DropStream - Add an action
  9. Select the action to perform from the dropdown menu. For our example, we will select Shipping Transformer.

    DropStream - Shipping transformer
  10. From the dropdown menu, select the Ship via value that meets your needs. For our example, we will select FedEx International Priority.

    DropStream - Ship via
  11. To finish, first click OK and then click Save changes.

    DropStream - Save a rule

Notes on use

In the example above, both elements of the conjunction were simple conditions. Instead of simple conditions, we could also use conjunctions of conditions, so the total statement will consist of multiple "nested" conjunctions, or conjunctions of conjunctions.

Disjunctions (OR) and negations (NOT), simple or complex, can be constructed analogously.

In complex conditions, the sub-conditions do not need to be of the same type. They can be formed by mixing conjunctions, disjunctions and negations, and by mixing the attributes of orders with the attributes of order items. You can even add quantified conditions that apply only to some items in the order. 

The usual properties of logical operators hold, such as double negation (NOT (NOT AA))  and distributivity (NOT (A AND B) ≡ (NOT A OR NOT B).

The negation

  • NOT(A is x) is equivalent to (A is_not x) if A is a textual attribute.
  • NOT(A = x) is equivalent to (A <> x) if A is a numeric or a date/time attribute.
  • NOT(A is blank) is equivalent to (A is not blank) if A is an attribute that is evaluated for any non-empty value.

These constructs use built-in comparison operators that are available from dropdowns.

A sequence of order rules with the same conclusion (THEN part) is equivalent to a conjunction with a shared conclusion, and may sometimes be preferable to keep rules simple. If the rules do not immediately follow each other, the equivalence may not hold because the rules in-between may affect the rules that follow.

Source code

In the rule source code used in the Advanced Editor, infix notation is used for the logical operators AND and OR and prefix notation for NOT. Parentheses are added, where needed, for scope disambiguation:

rule "Boolean condition"
when
not (order.shipping_country is "Canada" or order.shipping_country is "US" and (not (order.shipping_state is "AK" or order.shipping_state is "HI")))
then
reject order
end
end

This rule accepts only orders that are to be shipped to either Canada or the US, except the states of Alaska and Hawaii.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.