Rules for Imported Orders

Karl Falconer · Updated

The Order Import hook fires every time a new order arrives from a sales channel. It’s where most rule activity happens — preparing orders for fulfillment, filtering out what shouldn’t ship, routing to the right warehouse. This article collects the recipes you’ll reach for most often.

Each recipe is a complete, working rule. Drop it into the code editor (or the visual editor if you prefer) and adapt the field names and values to your setup. Always test in the Test tab before activating.

Map shipping methods

The most common rule. Your sales channel sends free-form text like “Free Shipping” or “Express”; your warehouse expects specific carrier codes like “USPS Priority”. Translate them.

rule "Map shipping methods"
  when
    order.shipping_carrier_service_level is "Free Shipping"
  then
    set order.shipping_carrier_name to "USPS"
    set order.shipping_warehouse_code to "USPS_PRIORITY"
    set order.shipping_carrier_service_level to "Priority Mail"
  end

  when
    order.shipping_carrier_service_level is "Express"
  then
    set order.shipping_carrier_name to "FedEx"
    set order.shipping_warehouse_code to "FEDEX_2DAY"
    set order.shipping_carrier_service_level to "2-Day"
  end
end

This is one of the few rules that’s effectively required for fulfillment — without it, your warehouse won’t know what carrier to use. Add a when block for every shipping method your channels offer.

Tag wholesale customers

rule "Tag wholesale orders"
  when
    order.customer_email ends_with "@wholesale-customer.com"
    or order.custom.customer_tier is "wholesale"
  then
    set order.custom.tag to "wholesale"
  end
end

Tags can drive downstream rules. “If tagged wholesale, apply discount and route to wholesale warehouse” — split into two rules so the tagging logic is isolated and reusable.

Route by country

Build this in the visual editor. Warehouses are picked from a named dropdown there. The code below shows the shape the editor produces — the warehouse numbers refer to specific warehouses in your account.

rule "Route by country"
  when
    order.shipping_address.country is "CA"
  then
    route order to warehouse 2   # your Canadian warehouse
  end

  when
    order.shipping_address.country is "MX"
  then
    route order to warehouse 3   # your Mexican warehouse
  end

  when
    order.shipping_address.country is "US"
    or order.shipping_address.country is blank
  then
    route order to warehouse 1   # your default US warehouse
  end
end

The fallback to a default warehouse (with is blank to handle orders that lack a country) keeps the rule from leaving orders unrouted.

Filter out test orders

rule "Filter test orders"
  when
    order.notes contains "TEST"
    or order.notes contains "DO NOT FULFILL"
    or order.customer_email ends_with "@example.com"
  then
    archive order
  end
end

Use archive rather than reject for test orders — archived records stay in the system for reference, but don’t go to the warehouse and don’t fill the error queue.

Reject restricted SKUs

rule "Reject restricted line items"
  for order_lines in order
    when
      order_line.sku starts_with "BANNED-"
      or order_line.custom.is_restricted
    then
      reject order_line
    end
  end
end

This rejects individual lines without rejecting the whole order. The remaining lines on the order continue normally.

To reject the whole order if any line is restricted:

rule "Reject orders with restricted items"
  when
    order has any order_lines with (
      order_line.sku starts_with "BANNED-"
      or order_line.custom.is_restricted
    )
  then
    fail order with "Order contains restricted items: " & order.id
  end
end

Include only specific SKUs

The inverse of Reject restricted SKUs — drop every line that doesn’t match an allowlist. Use this when only a subset of your catalog should ever ship through DropStream.

rule "Allow only specific SKUs"
  for order_lines in order
    when
      not (
        order_line.sku is "SKU-FOO"
        or order_line.sku is "SKU-BAR"
        or order_line.sku starts_with "SKU-ALLOWED-"
      )
    then
      reject order_line
    end
  end
end

To skip the whole order when none of its lines match the allowlist:

rule "Skip orders without an allowed SKU"
  when
    not (
      order has any order_lines with (
        order_line.sku is "SKU-FOO"
        or order_line.sku is "SKU-BAR"
        or order_line.sku starts_with "SKU-ALLOWED-"
      )
    )
  then
    archive order
  end
end

archive is the right action here — the order stays in DropStream for reference but isn’t sent to the warehouse and won’t be re-imported. Use reject order instead if you want the order discarded entirely.

Apply free shipping over a threshold

rule "Free shipping over $100"
  when
    order.subtotal > 100.0
  then
    set order.shipping_amount to 0.0
  end
end

This is one of the example rules the AI generator produces — a good warm-up for trying the AI feature.

Add gift wrap

rule "Add gift wrap to gift orders"
  when
    order.notes contains "GIFT"
    or order.custom.is_gift
  then
    add 1 item to order_lines in order
      set item.sku to "GIFT-WRAP"
      set item.name to "Gift Wrapping"
      set item.unit_price to 0.0
      set item.quantity to 1
    end
  end
end

See Adding Line Items for the full pattern.

Expand a kit SKU into components

rule "Expand starter kit"
  for order_lines in order
    when order_line.sku is "KIT-STARTER" then
      add 1 * order_line.qty_ordered items to order_lines in order
        set item.sku to "KIT-COMPONENT-A"
        set item.name to "Component A"
        set item.unit_price to 0.0
      end

      add 2 * order_line.qty_ordered items to order_lines in order
        set item.sku to "KIT-COMPONENT-B"
        set item.name to "Component B"
        set item.unit_price to 0.0
      end

      reject order_line
    end
  end
end

For each kit ordered, expand into the components and remove the kit line itself.

Hold weekend orders until Monday

rule "Hold Friday standard orders until Monday"
  timezone "Eastern Time (US & Canada)"

  when
    order.ordered_at is_on @friday
    and order.shipping_carrier_service_level is "Standard"
  then
    hold order until @monday at @T08:00:00
  end

  when
    order.ordered_at is_on @saturday
    or order.ordered_at is_on @sunday
  then
    hold order until @monday at @T08:00:00
  end
end

Note the timezone option — without it, “Friday” is interpreted in UTC, which may not match your operations timezone.

Categorize orders for downstream rules

rule "Categorize orders by total"
  set $tier to "standard"

  when order.subtotal > 100.0 then
    set $tier to "premium"
  end

  when order.subtotal > 1000.0 then
    set $tier to "vip"
  end

  set order.custom.tier to $tier
end

The default-then-override pattern with a session variable. The $tier variable gets refined as when blocks fire in order, and the final value is written to a custom field for other rules to use.

Combine: high-value priority routing

A more complete example combining several techniques:

rule "Premium US routing"
  accumulate order_lines in order
    total: sum order_line.unit_price * order_line.qty_ordered
    item_count: count order_line.id
  end

  when
    total > 500.0
    and item_count > 2
    and order.shipping_address.country is "US"
  then
    set order.custom.tag to "premium-us"
    route order to warehouse 7   # your premium US warehouse
    set order.notes to "Premium routing: $" & total as text & " across " & item_count as text & " items"
  end
end

Tips

  • One concern per rule. It’s tempting to write one giant rule that does everything. Resist. Splitting concerns into separate rules makes each one easier to test and modify.
  • Order matters. Rules in the same hook run top-to-bottom. Categorization rules should run before routing rules; tagging before filtering.
  • Test against real orders. The Suggest mode finds real orders the rule applies to — use it to confirm production behavior matches your expectations.
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.