Product Discount API reference
The Product Discount API enables you to create a new type of discount that is applied to particular product variants or cart lines.
Extension targets
Anchor link to section titled "Extension targets"The Product Discount API exposes the following targets:
Target | Output type | Description |
---|---|---|
purchase.product-discount.run |
FunctionRunResult | Outputs the product-level discount that should be applied to the cart |
The RunInput
object is the complete schema that your function can receive as input.
For a list of fields that the Product Discount API's Input
object accepts, refer to Input.
Input Example
Anchor link to section titled "Input Example"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.product-discount.run
target.
Each Discount
returned in the output can have a collection of either
ProductVariantTarget
s or CartLineTarget
s, but not both.
This collection of Target
objects declare the cart line(s) to which the Discount
will apply
its value. A CartLineTarget
specifies a specific cart line, whereas a
ProductVariantTarget
specifies a specific product variant, which could apply to one or more
cart lines for that product variant.
Additionally, each Target
has an optional quantity
field which, when provided, limits the number of units
to which the Discount
will apply its value.
Use CartLineTarget
s when you want fine-grained control on specifically which cart lines will get
discounted. Alternatively, use ProductVariantTarget
if your discounting strategy is based on
product variants, and you are not concerned which cart lines belonging to those product variants specifically get
discounted.
Output Example
Anchor link to section titled "Output Example"The following FunctionRunResult
includes a discount of 20% off for each cart line that has the
targeted product variant ID:
The following FunctionRunResult
includes a discount of $5 off for each cart line that has the
targeted product variant ID, up to a maximum of 2 items total among those cart lines (and $10 off):
If a discount should only apply to cart lines that have a particular attribute, then target the cart lines instead. In
the example function input, there were two cart
lines with the same product variant. For example, you can discount only the cart line with the Engraving Name
attribute with following function output: