Quantifiers in Order Rules

This article describes how to use quantifiers in DropStream order rules.

Overview

In order to create rules that do not apply to the whole order but only to some items in the order, DropStream rule language includes quantifiers all, any and 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 DropStream:

  • 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."

Example

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).

  1. In your DropStream Dashboard, click Stores.

In your DropStream Dashboard, click Stores.

  1. Click the name of your store, then click the Rules tab.

Click the Rules tab.

  1. Click +Add rule.

Click +Add Rule.

  1. Give your rule a descriptive Name, and click +Add Action.

Name the rule, and click +Add Action.

  1. Select an action to perform from the dropdown, e.g. Condition.

In the dropdown, select an action to perform, e.g., Condition.

  1. Select a quantified order item list from the dropdown next to IF. For this example we will be using any by selecting any_order items match conditions.

In the dropdown next to IF, select a quantified order item list.

  1. In the dropdown menu next to your operator, select Compare Order Item Attribute.

In the dropdown next to your operator, select Compare Order Item Attribute.

  1. Then determine the condition to be met. In this case we want to check if the size description of any order item contains the word "oversize".

Choose a condition.

  1. Click the +Add Action button in the active rule window.

Click +Add Action.

  1. Select the action to perform from the dropdown menu. For our example, we will select Shipping Transformer.

In the dropdown, select the action to perform, i.e., Shipping Transformer.

  1. From the dropdown menu, select the Ship via value that meets your needs. For our example, we will select FedEx Ground.

In the Ship Via dropdown, select the shipping method.

  1. To finish, first click OK and then click Save changes.

Click OK, then click Save Changes.

Notes on use

In DropStream, quantifiers can only be applied to order items, not to orders because DropStream'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 DropStream. This is also not needed because quantifiers in DropStream 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).

Source code

In the rule source code used in the Advanced Editor, quantifiers are represented in infix notation as follows:

  • all order_items match conditionsorder has all order_items with (order_item.attribute comparison_operator value)
  • any order_items match conditionsorder has any order_items with (order_item.attribute comparison_operator value)
  • no order_items match conditionsorder has none order_items with (order_item.attribute comparison_operator value)

Here is an example rule that encodes the quantifier examples presented above.

rule "Quantified condition" 
  when
    order has all order_items with (order_item.sku contains "promo")
    then
      set order.discount_amount to 15.0
  end
  when
    order has any order_items with (order_item.size_description contains "oversize")
    then
      set order.shipping_carrier_name to "FDX"
      set order.shipping_warehouse_code to "FDX G"
      set order.shipping_carrier_service_level to "Fedex Ground"
  end
  when
    order has none order_items with (order_item.gift_wrap blank)
    then
      set order.external_shipping_description to "Fragile"
  end
end

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"
  when
    order has any order_items with (order_item.name is "DHL" or order_item.name is "Fedex")
    then
      reject order
  end
  when
    order has any order_items with (order_item.name is "DHL") or order has any order_items with (order_item.name is "FedEx")
    then
      reject order
  end
end
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.