Approved wholesale customers get 10% off at 12+ units, 15% at 24+ and 20% at 48+, applied automatically at checkout. A progress bar shows how many more units unlock the next tier. The merchant approves customers in the admin; tiers live in one config read by both the Function and the checkout block.
Change quantities and the customer's approval. The page builds the exact input the Function receives at checkout, runs the real Function code from the repo, and applies its output. The progress block uses the same logic as the checkout extension.
customer.$app:wholesale_approved == "true"? no → no discount eligible lines = product variants without the "no-wholesale" tag units = sum of eligible quantities tier = highest tier in shop.$app:wholesale_tiers with minQuantity ≤ units → one product discount on every eligible line: "Wholesale 15% (24+ units)"
shopify.app.toml, so they appear in the admin on install.Built with Claude Code (Opus 5.5), Shopify's AI Toolkit (docs search + validators), Shopify CLI 5.1 and Shopify's own extension templates. The spec was mine; the code was the agent's; every row below is a check that ran.
| Step | Result |
|---|---|
| Input query validated against the Discount Function schema 2026-07 | ✓ |
| Function + 10 fixtures (guest, not approved, below tier, each tier, mixed cart with excluded and custom items, wrong discount class, missing / broken config) | 12/12 unit tests |
First shopify app function build | ✗ [auth]: Required in the app config → added |
| Second build | ✗ GraphQL codegen had no config — the agent had trimmed the template's codegen block → restored |
| Third build | ✓ function.wasm, 3.2 KB |
| All 10 fixtures through the compiled wasm with Shopify's test harness (also validates fixtures against the schema) | 10/10 |
| Checkout extension, first validation | ✗ s-progress got string | any[] as its accessibility label — i18n.translate() can return an array. A real screen-reader bug → fixed |
| Checkout extension, second validation | ✓ s-banner, s-stack, s-text, s-progress |
shopify app build (both extensions) | ✓ checkout bundle ≈ 7.8 KB compressed |
Setup mutations (discountAutomaticAppCreate, metafieldsSet) validated against Admin API 2026-07 | ✓ |
Three of the ten steps failed first time. That is the normal ratio — and why the checks are part of the service, not an extra.
no-wholesale product tag. With an excluded product in the cart it can promise a tier the Function will not give — try it in the simulator. Fix: a product metafield the extension can read.