Order discount - product variant target quantity does nothing

VitaDev
Shopify Partner
10 0 0

I am currently building an order discount function that should make specific line items free when a certain cart value is reached. Since I want to include line level discounts applied by some product discount functions in the cart value, I am using the order discount instead of a product discount function. In product discount functions, those line level discounts seem to be not reflected in the cart input.

The order discount function run result allows targeting product variants and also specifying a quantity. My function run result includes a product variant target with a quantity of 1, as you can see below:

 

{
  "discountApplicationStrategy": "FIRST",
  "discounts": [
    {
      "conditions": [
        {
          "orderMinimumSubtotal": {
            "excludedVariantIds": [
              "gid://shopify/ProductVariant/37732318707871"
            ],
            "minimumAmount": 100,
            "targetType": "ORDER_SUBTOTAL"
          }
        }
      ],
      "message": "Aktion",
      "targets": [
        {
          "productVariant": {
            "id": "gid://shopify/ProductVariant/37732318707871",
            "quantity": 1
          }
        }
      ],
      "value": {
        "percentage": {
          "value": 100
        }
      }
    }
  ]
}

But when I add more quantity of this product to my cart, they are discounted too. I only want a quantity of 1 to be discounted. This seems like a bug to me, or what does the quantity in the function run result do?

I am happy for any help on this, thanks in advance!

Replies 12 (12)

Liam
Shopify Staff
2724 289 743

 

Hi VitaDev,

 

Could there be another discount function or rule in your cart that is also applying a discount to the same product variant? You'll want to make sure to check all your discount functions and rules to ensure there are no conflicts.

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

VitaDev
Shopify Partner
10 0 0

Hey Liam,

 

Thanks for you quick reply. I had other discount functions active, but none of them applied discounts to the same line item / product variant. Deactivating them changes nothing, the problem remains the same.

Liam
Shopify Staff
2724 289 743

Hi VitaDev,

 

I've reached out to our product team on this to confirm that the use case you're trying to achieve is supported with order discount functions. Will update here when I learn more.

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

Ryoshin
Shopify Partner
40 3 7

I've been having problems with excludedVariantIds too. Actually, it seems like a lot of the functionalities don't work, are poorly exemplified, or I'm just getting them wrong.

 

conditions:[{
          orderMinimumSubtotal: {
            excludedVariantIds,
            minimumAmount,
            targetType: TargetType.OrderSubtotal
          }
        },
        {
          productMinimumQuantity: {
            ids,
            minimumQuantity,
            targetType: TargetType.ProductVariant
          }
        }]

 


There, for example. I have exlucedVariantIds both in targets and conditions, but it's still counting the excluded variants when comparing to the subtotal. So if the subtotal is over the minimum because of the excluded variants it applies the discount even though it shouldn't. Maybe I'm doing something wrong?

I can artificially raise the minimum value by adding the cost of the unwanted variants to it, but then what's the point of excludedVariantIds? The problem is usually me, but since I can't find more complete examples I don't know what I'm doing wrong.

Liam
Shopify Staff
2724 289 743

Hi Ryoshin & VitaDev,

 

Our devs have identified that there is a bug on our side which is causing this. We're working on a fix which will likely be shipped after BFCM. Thanks for flagging this!

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

Ryoshin
Shopify Partner
40 3 7

Ok, thanks. Another question, how do product discounts show the feedback that "discount code isn’t valid for the items in your cart" if there's no condition field, the target can't be empty, and EMPTY_DISCOUNT shows no feedback?

VitaDev
Shopify Partner
10 0 0

I agree, I always liked developer documentation of Shopify but regarding functions in many cases more examples and explanation would be beneficial. I also get the impression that there are quite many bugs with discount functions at the moment which makes it hard to migrate complex discount logic from scripts to functions.

 

Regarding the feedback if a discount is not valid for items in cart, I think there is no feedback wanted for those automatic app discounts, it can just apply discounts or not. Makes sense to me, since automatic discounts are not activated by a customer like discount codes and this kind of feedback would be more confusing than helpful.

Ryoshin
Shopify Partner
40 3 7

I'm creating discount codes. I think it's less confusing if it says "discount code isn’t valid for the items in your cart" instead of simply not applying anything. They might think the discount code isn't working instead of knowing the products don't fit the criteria. And I'm also talking specifically about product discounts since I've got it sort of figured out for order discounts with conditions. I agree they're not as necessary for automatic discounts though. 

Ryoshin
Shopify Partner
40 3 7

Also, what is message supposed to do? 

  • message (String)

    The discount message.

     

    I can't see the result of it anywhere

     
Ryoshin
Shopify Partner
40 3 7

Just ran into another error. I created a product discount, it applies correctly. I had 4 products in my cart, 2 fit the criteria and 2 didn't. It applied correctly. When I removed the 2 products that fit the criteria 1 of the products that didn't fit took the discount for itself. So a product that shouldn't be discounted was!

VitaDev
Shopify Partner
10 0 0

You should probably create new threads for those kinds of problems you encounter so that they eventually are seen be the right people and can get fixed.

sanjar
Shopify Partner
20 1 1

This still doesn't work properly....