Discussing Shopify Functions development, deployment, and usage in Shopify apps.
I am creating app with Shopify Functions for applying discounts with Product Discount API .
The project template was taken from https://github.com/Shopify/function-examples/tree/main/sample-apps/discounts-tutorial (Code I am talking about is placed in /extentions/volume/src/main.rs)
Ok(FunctionResult {
discounts: several_discounts,
discount_application_strategy: DiscountApplicationStrategy::Maximum,
})
I have faced crucial limitation that it does not allow to apply more than 1 discount.
As FunctionResult I am returning vec of discounts (list of 2 discounts, for example), and want 2 discounts to be applied at the same time. However, it does not happen probably because of DiscountApplicationStrategy which chooses only between First and Maximum discount.
Is there any way to apply all discounts?
We are having the exact same issue! The DiscountApplicationStrategy is limiting us as we want to apply multiple different discounts on multiple products in the same checkout. Are there any solutions here yet?
No solutions yet. Also waiting.
I have the same problem.When will this setting be supported?
Even I am facing the same issue
My function result
{ "discountApplicationStrategy": "FIRST", "discounts": [ { "value": { "percentage": { "value": 4 } }, "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/39279386525760", "quantity": 1 } } ] }, { "value": { "percentage": { "value": 4 } }, "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/39279386492992", "quantity": 1 } } ] }, { "value": { "percentage": { "value": 4 } }, "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/39279386460224", "quantity": 1 } } ] }, { "value": { "percentage": { "value": 4 } }, "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/39279386427456", "quantity": 1 } } ] } ] }
Just applying a single discount to the cart line even all four variants are there in the cart. Not sure If I am doing something wrong.
I wish I could be of help but would you be willing to share your query that's providing more than one discount? I can only pull one with
discountNode {
metafield(namespace: "$app:volume-discount", key: "function-configuration") {
value
}
}
Thanks!
Hi @adkhamllama have you found any work around for that? It's a very critical Limitation and we are also facing it. have you had any luck with that?
Has there been any news? I also have the same problem
We need this also. Has Shopify support responded?
I also have the same problem, is there any news ?
@rm_mrkb
Shopify has confirmed stacking discounts on line items is a current merchant frustration with Functions, but there's an active project being worked on by the Discounts product team on it. Which means the team is aware and is working towards fixing this limitation, unfortunately, they do not have any timelines on this
Maybe you know if there's any news?
I have not heard anything yet!
Same problem for me. I'm trying to apply 2 different discounts to 2 different products and it only applies to one product. It seems that there's no way to add multiple different product discounts neither using shopify functions, neither by applying it in the frontend using /discount/CODE endpoint. Actually it used to work using the /discount/CODE method, and I had managed to add 2 different discounts to cart, but after few weeks shopify decided to change that and it no longer works, although their documentation states otherwise (cart permalinks)
@Shopify Any update on that?
How can we replace Shopify Scripts with the new Functions if half the features are not available in Shopify Functions API? (Merchants are really not pleased at the moment)
+1 on this, this limitation + the limitation of the number of Automatic App Discounts makes impossible for my app to be updated with Shopify Functions.
I can apply 2 discount in 2 differents products, like the print below.
But I want to apply discount if the product has attribute "_x" for exemple, it works partially but if I apply the discount to the product that has this attribute and I add the same product without this attribute on cart the discount will be added to the product without attribute too (if I only add to cart the product without the attribute, discount is not applied).
I think it might be because the target for discount can be only product variant, so the discount is added to this variant id, not the line id. That's why the discount is applied to all products that has the same variant id, but not same attribute I guess (sorry for my english, I hope you understand it).
Is it okay to share your function result output?
If you send propriety, and then in js before you count how many variants have that propriety you can apply the disocunt to that specific quantity. Let's say you have 3 products, two with prop, 1 without. If you send with the variant id the quantity, only 2 variants with that id will have the discount applied.
I've tested it and is working. But I am not able to apply different discounts as you did in the picture. Can you help me with that part? My disocunt strategy is set to all, I allow combinations with products disocunt and my input is looking like this:
{ "discounts": [ { "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/47036824256794", "quantity": 1 } }, { "productVariant": { "id": "gid://shopify/ProductVariant/47033225511194", "quantity": 1 } } ], "value": { "percentage": { "value": 20 } } }, { "targets": [ { "productVariant": { "id": "gid://shopify/ProductVariant/47033225511194", "quantity": 1 } }, { "productVariant": { "id": "gid://shopify/ProductVariant/47036824256794", "quantity": 1 } }, { "productVariant": { "id": "gid://shopify/ProductVariant/45609454534938", "quantity": 1 } } ], "value": { "percentage": { "value": 30 } } } ], "discountApplicationStrategy": "ALL" }
Same issue. Kind of insane considering discounts is an array. The output of my function pretends it accepted an array, but it only applies the second one.
{
"discountApplicationStrategy": "MAXIMUM",
"discounts": [
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/45993501688108"
}
}
],
"value": {
"percentage": {
"value": 30
}
},
"message": "30% off readers"
},
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/45993407512876"
}
},
{
"productVariant": {
"id": "gid://shopify/ProductVariant/45993407447340"
}
}
],
"value": {
"percentage": {
"value": 20
}
},
"message": "20% off polarized sun"
}
]
}
seems like we desperately need a `discountApplicationStrategy: ALL`
Bump +1. @Shopify
This is also an issue for us. We need to be able to apply different discount amounts on different line items. This should be based on the line item, not the variant ID. We need the same capabilities that the Script Editor currently has.
I ran into the same Issue. We have a Ruby script discounting products based on the purchased quantity. They are either bXgY (buy 4 get 1 free and similar) or just quantity based (3 or more -1,50€ each e.g.). I've found a way to get DiscountApplicationStrategy.ALL working but it reapplies the first discount message to all discounted lines. This is sadly not sufficient for our purposes. A workaround could be to create an App + Extension for each Product but having over 90 apps that do nothing but this seems very bulky and overall bad. Nevertheless I want to help you guys out with my findings.
I first changed the api_version in the shopify.extension.toml to 'unstable' and then searched for DiscountApplicationStrategy in the schema.graphql and inserted ALL.
Now it does not throw an error anymore 😃 .
Using the 'unstable' branch on anything else than development stroes is not advised!
@Shopify Please include this feature in 2024-01! A lot of people would really appreciate it!
PS.: and please include the corresponding message for each line and not always the first.
Best regards,
Marco
Recently Shopify introduced in API 2024-01
DiscountApplicationStrategy.All
Haven't checked if that resolves the issue yet. But sharing it with you.
I get this working using the
DiscountApplicationStrategy.All
Here is my function result output:
{
"discounts": [
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927689801903"
}
}
],
"value": {
"percentage": {
"value": 15
}
},
"message": "15% off for 3+"
},
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927683149999"
}
}
],
"value": {
"percentage": {
"value": 10
}
},
"message": "10% off for 2"
},
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927683084463"
}
}
],
"value": {
"percentage": {
"value": 10
}
},
"message": "10% off for 2"
},
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927689703599"
}
}
],
"value": {
"percentage": {
"value": 15
}
},
"message": "15% off for 3+"
}
],
"discountApplicationStrategy": "ALL"
}
And here is the array with the discounts that I am sending to the discount field in the return of the run function,
[
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927689801903"
}
}
],
"value": {
"percentage": {
"value": 15
}
},
"message": "15% off for 3+"
},
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927683149999"
}
}
],
"value": {
"percentage": {
"value": 10
}
},
"message": "10% off for 2"
},
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927683084463"
}
}
],
"value": {
"percentage": {
"value": 10
}
},
"message": "10% off for 2"
},
{
"targets": [
{
"productVariant": {
"id": "gid://shopify/ProductVariant/40927689703599"
}
}
],
"value": {
"percentage": {
"value": 15
}
},
"message": "15% off for 3+"
}
]
This is for a tiered quantity discount offer.
1. Group By ProductID and Sum Quantities
2. Apply discount to variants based on the grouped quantities by product.