The problem
A static cart total doesn't nudge anyone toward free shipping — a progress bar and the right upsell do. But "the right upsell" is the part most implementations get wrong: suggest the cheapest item in the catalog and it won't cross the threshold; suggest the most expensive one lying around and you've oversold and look greedy.
The heuristic
Pick the cheapest candidate that still crosses the remaining amount to free shipping. Nothing more, nothing less. If no candidate crosses it, fall back to the most expensive one available — still the best progress on offer, honestly presented.
Real Liquid, not a mockup
The snippets (cart-progress-bar.liquid, cart-upsell.liquid) are the actual templates a Shopify theme would ship — rendered and tested headlessly with liquidjs, a standalone Liquid engine, so the logic is verified without needing a live store or the Shopify CLI.
The same math runs twice, deliberately: server-side in Liquid math filters on first page load, then through a tested TypeScript module (cartMath.ts) on every AJAX add-to-cart afterward. One source of truth for the decision logic, not two copies that quietly drift apart over time.
A finding worth knowing if you're testing Shopify themes headlessly
Shopify's | money filter — used everywhere in real themes to format cents as currency — is provided by the Shopify platform itself, not by core Liquid. liquidjs doesn't ship it. The test suite registers a small shim to render these snippets outside of a store — deliberately simple (USD, two decimals), explicitly documented as a test shim, not a reimplementation of Shopify's real multi-currency formatting.
16 tests cover both the pure decision logic and the actual rendered HTML output of the real Liquid templates.
Stack
TypeScript, Liquid, Vitest, liquidjs.

