Help with GWP Shopify Discount API

I have a GWP discount using the Discount API which works well, however, I can’t seem to find a way to calculate the new subtotal when an order discount code is applied where the new subtotal may not meet the GWP threshold which would result the cart to not qualify for the FREE GWP.

I have the following for my CartInput query:

query CartInput {
  cart {
    discountApplications {
      targetType
      totalAllocatedAmount {
        amount
      }
    }
    lines {
      id
      quantity
      merchandise {
        __typename
        ... on ProductVariant {
          id
        }
      }
      cost {
        subtotalAmount {
          amount
        }
        totalAmount {
          amount
        }
      }
    }
    cost {
      subtotalAmount {
        amount
      }
      totalAmount {
        amount
      }
      totalDutyAmount {
        amount
      }
      totalTaxAmount {
        amount
      }
    }
  }
  discount {
    discountClasses
    metafield(namespace: "$app", key: "gwp-discount-config") {
      value
    }
  }
}

and then the Input (STDIN) that is logged from the function returns as:

 {
  "cart": {
    "discountApplications": [],
    "lines": [
      {
        "id": "gid:\/\/shopify\/CartLine\/0",
        "quantity": 1,
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid:\/\/shopify\/ProductVariant\/43120043786440"
        },
        "cost": {
          "subtotalAmount": {
            "amount": "89.0"
          },
          "totalAmount": {
            "amount": "89.0"
          }
        }
      },
      {
        "id": "gid:\/\/shopify\/CartLine\/1",
        "quantity": 1,
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid:\/\/shopify\/ProductVariant\/43118909194440"
        },
        "cost": {
          "subtotalAmount": {
            "amount": "89.0"
          },
          "totalAmount": {
            "amount": "89.0"
          }
        }
      }
    ],
    "cost": {
      "subtotalAmount": {
        "amount": "178.0"
      },
      "totalAmount": {
        "amount": "178.0"
      },
      "totalDutyAmount": null,
      "totalTaxAmount": null
    }
  },
  "discount": {
    "discountClasses": [
      "PRODUCT",
      "ORDER"
    ],
    "metafield": {
      "value": "{\"tiers\":[{\"priceThreshold\":89,\"gwpVariantId\":\"gid:\/\/shopify\/ProductVariant\/43118909194440\",\"maxUnitsToApply\":1}]}"
    }
  }
}

The input log above show’s that even when a discount code is applied, the subtotalAmount and totalAmount are the same. Is there a way for functions to read order discount values? Or is this a known limitation where order discounts are executed after Discount API functions run?

It’s not possible as all discount functions run in parallel. You can achieve the other way around (knowledge of product discounts in order runs), by using the provided ‘conditions’.

1 Like

@bkspace thanks for the response. That’s what I was thinking after reading the docs more. So it sounds like knowing ahead of time of what the discount is would be the way to go. Not really ideal since there are app generated unique discounts.

As an alternate solution, I’ve decided to just write a cart and checkout validation to block checkout if the new subtotal doesn’t meet the GWP threshold when a discount code is entered.