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.

Shopify Functions Product Discount API multiple discounts

adkhamllama
Shopify Partner
27 1 50

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?

Replies 27 (27)

Sam-Rise-ai
Shopify Partner
3 0 3

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?

adkhamllama
Shopify Partner
27 1 50

No solutions yet. Also waiting.

colin89
Shopify Partner
1 0 0

I have the same problem.When will this setting be supported?

charanpahari_ap
Shopify Partner
1 0 0

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.

cmoriarty83
Shopify Partner
8 2 2

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!

abdul81
Shopify Partner
20 1 3

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?

Product Manager at Developer's Capital

  • Creator of App Quantity & Volume Discounts
  • Was my reply helpful? Click Like to let me know!
  • Was your question answered? Mark it as an Accepted Solution
,new value=Product Manager at Developer's Capital
  • Creator of App Quantity & Volume Discounts
  • Was my reply helpful? Click Like to let me know!
  • Was your question answered? Mark it as an Accepted Solution

MattiaM
Shopify Partner
3 0 4

Has there been any news? I also have the same problem

nbfusion
Shopify Partner
3 0 3

We need this also. Has Shopify support responded?

Masad
Shopify Partner
7 0 6

@Shopify Any update on this ? 

rm_mrkb
Shopify Partner
3 0 1

 I also have the same problem, is there any news ?

Masad
Shopify Partner
7 0 6

@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 

edvinaskilbausk
Shopify Partner
8 0 3

Maybe you know if there's any news?

Masad
Shopify Partner
7 0 6

I have not heard anything yet! 

Masad
Shopify Partner
7 0 6
I have not heard anything yet!

edvinaskilbausk
Shopify Partner
8 0 3

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)

Nico4
Shopify Partner
25 0 12

@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)

Groon
Shopify Partner
15 0 17

+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.

jason_chenwei
Shopify Partner
1 0 1

@Shopify Any update on that? we need it!!!

gabrielvictoria
Shopify Partner
13 0 2

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).

 

gabrielvictoria_0-1691603560544.png

 

JaysDev_06
Shopify Partner
3 0 1

Is it okay to share your function result output?

MirunaAndriesei
Shopify Partner
1 0 0

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. 

MirunaAndriesei_0-1708000727256.png

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"
}

peepers-rick
Shopify Partner
10 0 5

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`

 

SGSdev
Shopify Partner
18 2 7

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.

JaysDev_06
Shopify Partner
3 0 1

@Shopify Any update on this? I have the same issue.

Marco_Dittrich
Shopify Partner
3 0 1

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

adkhamllama
Shopify Partner
27 1 50

Recently Shopify introduced in API 2024-01

DiscountApplicationStrategy.All

Haven't checked if that resolves the issue yet. But sharing it with you.

PedroMendoza
Shopify Partner
1 0 0

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.