Volume discount, decided by a Shopify Function. This page is ready

Volume discount, decided by a Shopify Function

The bulk editor writes custom.volume_tiers; this reads it at checkout. Same parser on both sides.

A json metafield on the product. Edit it, or pick a case below.

What the editor should be writing.

1 · The bulk editor, before it sends the write

SuccessWould be written

Accepted as 6+ → 10%, 12+ → 15%.

Shopify would accept most of what this rejects — the metafield is typed json, so the shop checks that it parses and nothing more. A write that never leaves the app also spends no points against the cost limit.

2 · The Function, at checkout

Cart lineQuantityDiscountWhy
Product A (the one you are editing)1215%Buy 12+, save 15%
Product B (always valid tiers)2015%Buy 12+, save 15%

A product whose metafield cannot be read loses its own discount and nothing else. Throwing instead would mean one mis-edited product turns the promotion off for the whole cart — and a Function that throws applies no discount at all, with no way to tell the merchant.

3 · What Shopify receives

{
  "discountApplicationStrategy": "FIRST",
  "discounts": [
    {
      "targets": [
        {
          "cartLine": {
            "id": "gid://shopify/CartLine/1"
          }
        }
      ],
      "value": {
        "percentage": {
          "value": 15
        }
      },
      "message": "Buy 12+, save 15%"
    },
    {
      "targets": [
        {
          "cartLine": {
            "id": "gid://shopify/CartLine/2"
          }
        }
      ],
      "value": {
        "percentage": {
          "value": 15
        }
      },
      "message": "Buy 12+, save 15%"
    }
  ]
}

A percentage, not a computed amount. The Function does not know the currency’s rounding rules, what tax treatment applies, or which discounts Shopify has already allocated — a money figure worked out without those is wrong in a way that is very hard to notice.