Order Routing Rules
Order routing rules are declarative manifests that match cart lines to fulfillment locations. Unlikefulfillment_constraints
functions (which run WASM and can block order placement), routing rules
are pure JSON matchers evaluated by the platform at order placement.
Use routing rules when the assignment is data-driven (SKU prefix,
tag, country, line attribute) and fulfillment_constraints when you
need code (call your inventory service, look up real-time stock,
hit a 3PL API).
When to use rules vs constraints
The two are complementary. A typical setup:
fulfillment_constraintsnarrows the set of locations a line can ship from (block if zero, otherwise narrow to the eligible set).- Routing rules pick the preferred location from that narrowed set (West Coast → Oakland; everything else → New Jersey).
Where rules live
Each rule is one entry inextensions.orderRoutingRules on your
app.json. After install, each entry is persisted as a single schema
file at:
type: 'fulfillment_location_rule', exposing a single union of
all routing rules across all installed apps. There is no per-shop cap
on the number of rules — install as many as you need.
Manifest
Fields
Match operators
Paths use dotted notation against the cart input. A path can be a literal field name or include[] to project across an array.
Full operator list
Boolean composition
Multiple keys in the samematch block are ANDed. For explicit
boolean logic, use any (OR) or all (AND) lists at the top level:
(country == US OR country == CA) AND totalPrice >= 50.
Common paths
Array projections (
[]) match if any line satisfies the inner
predicate. To require all lines to match, wrap in all:
Assignment
When several rules match, the platform picks the one with the highest
priority. Ties are broken by declaration order across apps — there
is no defined cross-app ordering today, so prefer unambiguous priorities
when two apps might match the same line.
Fallback
A catch-all rule:match: {} matches anything. The fallback: true flag tells
the evaluator to only consider this rule when nothing else matched. With
fallbacks, you don’t need to enumerate every possible region — write the
specifics, then catch the rest.
Worked examples
West Coast US → Oakland; everything else → Newark
us-west has
priority: 10 and wins. An Idaho order only matches us-default and
ships from Newark.
Hazmat → licensed hub regardless of region
priority: 100 outranks the regional rules above. Any cart containing a
hazmat line is routed to the hazmat hub, ignoring shipping address.
International → 3PL
Backorder → drop-shipper
inventory_state attribute is "backorder" (typically
populated by your inventory app via a cart_transform function) is sent
straight to the drop-shipper, bypassing all other routing.
High-value orders → expedited centre
Inspection
Once the runtime evaluator is wired, the result of routing will be persisted on the order’sadditionalFields.orderRouting:
us-west matched at priority 10”.
A line that has no matching rule is omitted from the array — the
merchant’s manual fulfilment workflow handles it.
Interaction with fulfillment_constraints
When both routing rules and a fulfillment_constraints function are
installed for the same store, the platform runs them in this order:
The rule evaluator respects the narrowed set: a rule that assigns
oakland-dc to a line whose constraint allows only [newark-dc] is
ignored for that line. Use fulfillment_constraints to enforce
hard physical limits (a location is the only one with stock) and use
routing rules to express preferences within the feasible set.
Per-shop cap
Becausefulfillment_location_rule has no backend function-limit entry
yet, there is currently no active-install cap enforced for routing
rules — the manifest is accepted and persisted, but nothing rejects or
counts them at install. A cap will be introduced when the runtime
evaluator ships.
See also
- Fulfillment Constraints — the WASM-backed counterpart that can block orders.
- Cart Transform — populate
cart.lines[].merchandise.attributesso routing rules have something to match on. - App Manifest — full top-level manifest schema.