Fulfillment Constraints API reference
The Fulfillment Constraints API enables you to have a higher degree of customization when defining fulfillment and delivery strategies.
Extension targets
Anchor link to section titled "Extension targets"The Fulfillment Constraints API exposes the following targets:
Target | Output type | Description |
---|---|---|
purchase.fulfillment-constraint-rule.run |
FunctionRunResult | Outputs a list of fulfillment constraints |
The Input
object is the complete schema that your function can receive as input.
For a list of fields that the Fulfillment Constraints API's Input
object accepts, refer to Input.
The following example shows an input query:
The following example shows the resulting input to the query:
FunctionRunResult
Anchor link to section titled "FunctionRunResult"The FunctionRunResult
object is the expected output for the purchase.fulfillment-constraint-rule.run
target.
Output objects can return a value of 0
to n
fulfillment constraints. The following function result specifies that DeliverableCartLine
1
and 2
must ship or fulfill from same location, and lines 3
and 4
must ship or fulfill from locations 1
or 2
:
Optionally, the deliverableLineIds
key can be omitted from the constraint operation to indicate that the fulfillment constraint should be applied to all deliverable lines within the cart.
Fulfillment constraints reducer
Anchor link to section titled "Fulfillment constraints reducer"In scenarios where FunctionRunResult
returns results that can be further combined, Shopify will automatically combine these fulfillment constraints before processing.
Scenario 1 - 1
Anchor link to section titled "Scenario 1 - 1"In this scenario, the output contains two constraints with the same type MustFulfillFrom
and the same location IDs 1
and 2
. These two constraints can be combined because DeliverableCartLine
1
, 2
, 3
and 4
should all fulfill from locations 1
or 2
.
Scenario 1 - 2
Anchor link to section titled "Scenario 1 - 2"In above scenario 1 - 1, if the second constraint has the location IDs 1
, 2
and 3
, the reducer won't combine the two constraints.
Scenario 1-3
Anchor link to section titled "Scenario 1-3"If the same DeliverableCartLine(s)
has multiple MustFulfillFrom
constraints, the reducer will take the intersection of location IDs.
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
1
and 2
must fulfill from location 1
. To meet both constraints, DeliverableCartLine
3
and 4
must fulfill from location 1
.
Scenario 3 - 1
Anchor link to section titled "Scenario 3 - 1"
Constraints conflict
Anchor link to section titled "Constraints conflict"In scenarios where FunctionRunResult
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.