Fulfillment Constraints API reference
The Fulfillment Constraints API enables you to have a higher degree of customization when defining fulfillment and delivery strategies. The API includes two key objects: Input
and FunctionResult
.
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.Locations
: The locations that stock the items. This object includes metafields.FulfillmentConstraintRule
: A reference to the function owner, the Fulfillment Constraint Rule object. This object includes metafields.
The following example shows an input query:
The following example shows the resulting input to the query:
FunctionResult
Anchor link to section titled "FunctionResult"The FunctionResult
object is the shape of the function's output.
Output objects can return a value of 0
to n
fulfillment constraints. The following function result specifies that deliverable cart lines 1
and 2
must ship or fulfill from same location, and lines 3
and 4
must ship or fulfill from location 1
:
Constraints reducer
Anchor link to section titled "Constraints reducer"In scenarios where FunctionResult
returns constraints that can be further combined, a reducer logic runs to combine constraints before data is passed to Shopify.
In this scenario, the output contains two constraints with the same type MustFulfillFrom
and the same location ID 1
. These two constraints can be combined because DeliverableCartLine
1
, 2
, 3
and 4
should all fulfill from location 1
.
In this scenario, the output contains two constraints with the same type MustFulfillFromSameLocation
. Shopify combines them because DeliverableCartLine
2
must be fulfilled from the same location as DeliverableCartLine
1
, 3
and 4
.
In this scenario, the output contains two constraints with different types. DeliverableCartLine
2
, 3
and 4
must fulfill together and at the same time. DeliverableCartLine
2
must fulfill from location 2
. To meet both constraints, DeliverableCartLine
3
and 4
must fulfill from location 1
.
Constraints conflict
Anchor link to section titled "Constraints conflict"In scenarios where FunctionResult
returns constraints that are mutually exclusive, checkout won't return any shipping rates.
In the following example, DeliverableCartLine
1
and DeliverableCartLine
2
can't be fulfilled together because they must fulfill from Location
1
and 2
respectively.