At a high-level, my app has two extensions:
1.A UI extension that exposes the surface to create a discount code, rendered in admin.discount-details.function-settings.render.
2.A function that validates and applies/rejects the discount code created by 1.
As mentioned, this is working. I updated my .graphql to include enteredDiscountCodes, and the logs show that this is correctly picked up and is available as the input to the function.
PROBLEM: The rejectable property of the code is false, even though this is a code that is created by my app. Is this a bug, or am I missing something ? Because of this issue, I am unable to return a custom rejection message for the rejected discount code.
Discount Functions can only reject codes when the rejectableproperty of true. This property will be always be false for code discount Functions (only automatic discounts can perform code rejection) and for codes that have already been applied to the cart.
@Samih Thank you for your response! Can you please elaborate on why an automatic discount can perform code rejection but not a discount code ? I have a custom discount app which allows merchants to define precise conditions under which the discount code is eligible, and it would be great if the customer were able to see the exact reason why the code is not applicable for their cart.
That is still doable with an automatic discount Function. The code rejection tutorial provides a good example for that; create the Function with the validation logic and custom messages, it gets installed as an automatic app discount (so it runs automatically in checkout/cart), perform its rejection logic and the buyer will see the rejection reasons.
Any reason you want your rejection Function to be triggered by a code instead of automatically?
@Samih I followed the tutorial closely but I am unable to get the custom rejection message working. I have an app with two extensions:
1.Admin UI Extension that allows the merchant to create discount codes
2.A Function that processes the discount and applies/rejects it if certain conditions are met
The above is working fine.
So now, lets say the merchant creates a discount code called “SPARK” from my app.
The customer will need to have a min cart value of $85 to qualify for this discount.
When the customer with $50 cart value tries to apply it to their cart, my function correctly rejects it and the following notification is shown, (note that this is the default rejection message by Shopify).
I want to set a custom rejection message, but I am unable to do so because the rejectable property is always false.
Here is a snippet from input.graphql that is passed as an input to my function:
enteredDiscountCodes { code rejectable }
And here is the value of this object: "enteredDiscountCodes": [ { "code": "SPARK", "rejectable": false }
This discount code was created by my app, and it was NOT applied to the cart, so I am not sure why the rejectable property is false. Can you please advise ?
@Samih Do you have any suggestions ? I feel like this is a bug in Shopify’s interface because the discount code created by my app always has the value of rejectable set to false. Thank you so much for your help!