Discussing Shopify Functions development, deployment, and usage in Shopify apps.
I'm noticing some strange behavior when multiple discounts are returned using order_discount api with DiscountApplicationStrategy::MAXIMUM. Curious if anyone else has seen something like this..
I'm porting a standard 3-tier discount from a Ruby script for a client. When the cart total is $100+ in $10 discount, $200+, $20 discount, $300+, $30 discount. About as simple as it gets.
Wrote & deployed the script and testing on the default 'Test Data' theme ( Dawn 11.0.0). The environment is a dev store w/extensibility preview build. In checkout, everything works fine, but on the online storefront I'm noticing the discount is sometimes dropped from the section api response when using the <cart-drawer> component from Dawn
Specifically, whenever I increase the quantity in cart from 1 to 2, the order discount disappears from the cart drawer. However, it appears again when I change the quantity of 1, 3, and 4. if I refresh, the discount is rendered, and if I check /cart.json before refreshing I see the discount as it should be.
It's just weird, like, no matter what the quantity is in the initial cart state, whenever I change the quantity to 2 the discount is not returned from the section api. It's happening every single time and only at that specific quantity.
As a test, I changed my function so that only one discount is returned in the output array, and changed the discountApplicationStrategy to "FIRST" for this discount - this resolved the issue and the function works at each quantity. However, when implementing a percentage discount instead of fixed, I noticed the same issue at a different price point.
For reference here is the input and output that gives me this behavior. Issue occurs in preview mode as well as with a deployed version.
INPUT
{
"cart": {
"cost": {
"totalAmount": {
"amount": "1200.0"
},
"subtotalAmount": {
"amount": "1200.0"
},
"totalDutyAmount": null,
"totalTaxAmount": null
}
},
"discountNode": {
"metafield": {
"value": {
"tiers": [
{
"value": "10.00",
"minTotal": "100.00",
"maxTotal": "-1.00",
"message": "$10 off"
},
{
"value": "20.00",
"minTotal": "200.00",
"maxTotal": "-1.00",
"message": "$20 off"
},
{
"value": "30.00",
"minTotal": "300.00",
"maxTotal": "-1.00",
"message": "$30 off"
}
]
}
}
}
}
OUTPUT
{
"discountApplicationStrategy": "MAXIMUM",
"discounts": [
{
"conditions": [
{
"orderMinimumSubtotal": {
"excludedVariantIds": [],
"minimumAmount": "100",
"targetType": "ORDER_SUBTOTAL"
}
}
],
"message": "$10 off",
"targets": [
{
"orderSubtotal": {
"excludedVariantIds": []
}
}
],
"value": {
"fixedAmount": {
"amount": "10"
}
}
},
{
"conditions": [
{
"orderMinimumSubtotal": {
"excludedVariantIds": [],
"minimumAmount": "200",
"targetType": "ORDER_SUBTOTAL"
}
}
],
"message": "$20 off",
"targets": [
{
"orderSubtotal": {
"excludedVariantIds": []
}
}
],
"value": {
"fixedAmount": {
"amount": "20"
}
}
},
{
"conditions": [
{
"orderMinimumSubtotal": {
"excludedVariantIds": [],
"minimumAmount": "300",
"targetType": "ORDER_SUBTOTAL"
}
}
],
"message": "$30 off",
"targets": [
{
"orderSubtotal": {
"excludedVariantIds": []
}
}
],
"value": {
"fixedAmount": {
"amount": "30"
}
}
}
]
}