This article explains the use of logical operators in PackageBee order rules.
PackageBee 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 PackageBee:
- 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.
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).
- Open the desired store.
- Go to the Rules tab.
- Click +Add rule.
- Give your rule a descriptive name. Then click +Add action.
- Select an action to perform from the dropdown, e.g. Condition.
- 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.
- 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.
- Click the blue +Add action button in the active rule window.
- Select the action to perform from the dropdown menu. For our example, we will select Shipping Transformer.
- From the dropdown menu, select the Ship via value that meets your needs. For our example, we will select FedEx International Priority.
- To finish, first click OK and then click Save changes.
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 A ≡ A)) and distributivity (NOT (A AND B) ≡ (NOT A OR NOT B).
- 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.
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"
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")))
This rule accepts only orders that are to be shipped to either Canada or the US, except the states of Alaska and Hawaii.