This article describes the use of quantifiers in PackageBee order rules.
In order to create rules that do not apply to the whole order but only to some items in the order, PackageBee rule language includes quantifiers
no. Using quantified conditions will allow you to create more specific or granular order rules, and in this way further streamline your order fulfillment workflow.
For example, you may want to require that if any of the items in an order is oversize, then the whole order is shipped via FedEx Ground.
Quantifiers have the following meanings in PackageBee:
all order_items match conditions- universal quantifier; the rule containing it applies if all items in the order meet the condition.
- E.g. If all items have SKUs that contain the word promo then apply 15% discount to the order.
any order_items match conditions- existential quantifier; the rule containing it applies if at least one item in the order meets the condition.
- E.g. if any of the items in the order is oversize then ship the whole order via FedEx Ground.
no order_items match conditions- negative quantifier; the rule containing it applies if none of the items in the order meet the condition.
- E.g. if the order contains no items that should not be gift-wrapped, then add the shipping description "Fragile"to the order.
We demonstrate the use of quantifiers by creating a rule for the second example above that contains an existential quantifier (if at least one order item is oversize, ship the order via FedEx Ground).
- Open the desired store.
- Go to the Rules tab.
- Click +Add rule.
- Give your rule a descriptive name and click +Add Action.
- Select an action to perform from the dropdown, e.g. Condition.
- Select a quantified order item list from the dropdown next to IF. For this example we will be using any (any_order items match the condition).
- In the dropdown menus next to your operator, select Compare Order Item Attribute.
- Then determine the condition that you want to have met. In this case we want to check if the size description of any order item contains the word "oversize".
- 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 Ground.
- To finish, first click OK and then click Save changes.
Notes on use
In PackageBee, quantifiers can only be applied to order items, not to orders because PackageBee's rule engine applies rules to each order separately. Because of that, quantified conditions can only reference attributes of order items, not attributes of orders.
Quantified conditions can be combined with logical operators to form complex conditions. Such conjuncts behave like other complex, boolean statements, and can reference both the attributes of order items and the attributes of orders, although quantifiers can still be used with order items only.
Quantified conditions cannot contain other quantified conditions, so "nested quantification" is not allowed in PackageBee. This is also not needed because quantifiers in PackageBee can only be applied to order items, not to attributes or attribute values, and repeating quantifiers for the same object results either in a tautology (if the same quantifiers are used) or in a contradiction (if different quantifiers are used).
In the rule source code used in the Advanced Editor, quantifiers are represented in infix notation as follows:
all order_items match conditions→
order has all order_items with (order_item.attribute comparison_operator value)
any order_items match conditions→
order has any order_items with (order_item.attribute comparison_operator value)
no order_items match conditions→
order has none order_items with (order_item.attribute comparison_operator value)
Here is a example rule that encodes the quantifier examples presented above.
rule "Quantified condition"
order has all order_items with (order_item.sku contains "promo")
set order.discount_amount to 15.0
order has any order_items with (order_item.size_description contains "oversize")
set order.shipping_carrier_name to "FDX"
set order.shipping_warehouse_code to "FDX G"
set order.shipping_carrier_service_level to "Fedex Ground"
order has none order_items with (order_item.gift_wrap blank)
set order.external_shipping_description to "Fragile"
Finally, we include a rule example that contains both quantifiers and boolean operators.
In the first statement, the quantifier any has scope over the disjunction (OR). In the second statement, the disjunction has scope over the two quantifiers. The rule rejects orders where at least one of the order items is named the same as the shipping companies DHL or FedEx.
rule "Coordinated quantifiers"
order has any order_items with (order_item.name is "DHL" or order_item.name is "Fedex")
order has any order_items with (order_item.name is "DHL") or order has any order_items with (order_item.name is "FedEx")