Product Discount Function extension can not handle multiple discount rules in the same cart

Hi guys,

I’m making a product discount extension to implement our volume discounts for our customers.

The extension is working properly if there is only 1 product in cart, in the other case, no discount is being applied to the customers’ cart.

Let me show the JSON of extension result here:

[
  {
    "targets": {
      "productVariant": {
        "id": "gid://shopify/ProductVariant/39525478039613"
      }
    },
    "value": {
      "percentage": {
        "value": "5.00"
      }
    },
    "message": "Spectra Precision Laser Offer"
  },
  {
    "targets": {
      "productVariant": {
        "id": "gid://shopify/ProductVariant/40434930679869"
      }
    },
    "value": {
      "percentage": {
        "value": "5.00"
      }
    }
  }
]

The extension is expected to apply 2 discounts on 2 different variants.

But no discount works at all, if I remove one of the product, there will be a discount applied then.

Screenshots:

  1. When a single product in cart

  1. Multiple products with multiple discounts returned from the extension

Please help to resolve the issue,

Thank you guys so much

Try setting the “targets” field to be an array of objects rather than a single object.

Also, what is your discountApplicationStrategy set to? Try “ALL” (make sure you’re using api version 2024-01)

oh, it’s so cool.

my app is still in an older version, from 2023.

Let me try to pull the schema and update the code.

I’m going to back on this thread and mark your answer as the solution if it works

The issue is now sorted out.

Special thank to @originmaster

What I did update:

  1. Update the API version to 2024-01

  2. npm run shopify app function schema pull

  3. Update the code to set the discountApplicationStrategy equal to ALL

  4. Build, and release a new app version.

Glad it helped!