Order Routing Location Rule API reference
Order routing is the process of determining the location that's used to fulfill each cart line item. The Order Routing Location Rule API allows developers to provide their own ranking of location, for each item, during order routing. The API includes two key objects:
The Input object is the complete schema that your function can receive as input. The input includes the following objects:
- Cart: The context of the current purchase proposal.
- FulfillmentGroups: A list of groups representing the items to be fulfilled.
- InventoryLocations: A list of available locations for this fulfillment group.
- Locations: The locations that stock the items. This object includes metafields.
- DeliveryMarkets: The store's markets that the delivery address is in.
- LocationRule: A reference to the owner of the function, the Location Rule object. This object includes metafields.
The following example shows an input query:
The following example shows the resulting input to the query:
FunctionResultAnchor link to section titled "FunctionResult"
The FunctionResult object is the shape of the function's output.
The following function result ranks locations:
Combining fulfillment groups ranked locations from multiple functionsAnchor link to section titled "Combining fulfillment groups ranked locations from multiple functions"
For each fulfillment group, Shopify first sorts the output of each function based on the
locationRule priority. Shopify then takes the first output, and sorts the locations of the fulfillment group based on the rank. If there are ties between the rankings, then Shopify breaks them using the ranks from the second output, and so on. If there are no ties, then only the output of the first
locationRule is considered.