What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Discount Function API

Discount Function API

luoooofei
Shopify Partner
4 0 0

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:

luoooofei_0-1696902948451.png

 

 

 

 

Replies 8 (8)

Liam
Community Manager
3108 344 895

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

jbriceno
Shopify Partner
3 0 4

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!

luoooofei
Shopify Partner
4 0 0

I also have such doubts.

Greg_P
Shopify Partner
41 4 34

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?

Shopify Developer
If I have solved your issue, please mark my post as accepted solution 🙂
franky_lau
Visitor
2 0 0

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.

Screenshot 2023-11-22 at 5.57.20 PM.png

franky_lau
Visitor
2 0 0

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?

luoooofei
Shopify Partner
4 0 0

Product discounts also do not support ‘ALL’

Greg_P
Shopify Partner
41 4 34

It works in Unstable version of API so probably will be live next year.

Shopify Developer
If I have solved your issue, please mark my post as accepted solution 🙂