Discussing Shopify Functions development, deployment, and usage in Shopify apps.
I am using the discount function API to reduce different prices for different products, but only one product is displayed on the shopping cart or checkout with a discount price applied, and other products are not effective.
I think the corresponding Discounts type for the API is an array, which means that multiple discount information can be output, but the result only takes effect on one, which is far from what I expected.
FunctionRunResult:
{ "discounts": [ { "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/46835603702067" } } ], "value": { "fixedAmount": { "amount": 629.9499999999999 } } }, { "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/46835603800371" } } ], "value": { "fixedAmount": { "amount": 749.95 } } }, { "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/46835603341619" } } ], "value": { "fixedAmount": { "amount": 699.9499999999999 } } } ], "discountApplicationStrategy": "MAXIMUM" }
Checkout:
Hi Luoooofei,
The issue you're encountering may be due to the "discountApplicationStrategy" set as "MAXIMUM". The "MAXIMUM" strategy applies the highest possible discount to the cart. If you have multiple discounts, it won't apply all of them, but only the one with the maximum value.
If you want to apply multiple discounts to different products, you should consider changing the "discountApplicationStrategy" to "ALL". This applies all discounts to the cart. Note that the order of discounts in the array can affect the final price, as discounts are applied in the order they appear in the array.
You might also want to double-check your product variant IDs to ensure they are correct. Hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi Liam,
On the API Documentation there is only FIRST or MAXIMUM as allowed options, is this something recently implemented? If so, how can we access this new schema, it doenst work if we just manually add it. thanks!
I also have such doubts.
Hello @Liam!
Strategy `ALL` is available in the unstable API version, but this feature is requested by many people, can you help us to escalate this issue?
Hi @Liam ,
We are facing the same issue, and the "DiscountApplicationStrategy.All" looks good to me. May I ask a dumb question? How to use the unstable API?
I updated my `shopify.extension.toml` with `api_version = "unstable"`, and I changed to `discountApplicationStrategy: DiscountApplicationStrategy.All` in my order discount JS function. However, it shows a bunch of `InvalidOutputError` in the log, and there are no details on each error.
Oh, I found the reason. The All strategy is only supported in product discount, but not in order discount even in the unstable version. Is there any ways to apply both `orderSubtotal` discount and `productVariant` discount together?
Product discounts also do not support ‘ALL’
It works in Unstable version of API so probably will be live next year.