Skip to main content

Overview

A calculator works out an amount. “Charge $5 per item.” “Take 15% off.” “Free over $50, otherwise $7.” They exist because the rule and the number are different questions. A promotion decides whether a discount applies; a calculator decides how much. Keeping them apart means a merchant can change “10% off” to “$10 off” without touching the conditions that decide who qualifies. Two things use calculators:
Tax does not use calculators. Tax is worked out by a tax provider, which can be Spree’s own rate tables or an external service.

Choosing a calculator

Each calculator takes a few settings — the amount, the percentage, the threshold. A merchant picks one and fills in the settings when setting up a delivery method or a promotion.

For delivery charges

For promotion discounts

Worked examples

Price sack, with minimal_amount: 50, discount_amount: 0, normal_amount: 7.A $60 basket pays nothing. A $20 basket pays $7.
Flexi rate, with first_item: 3, additional_item: 1.Four items cost $3 + (3 × $1) = $6. Set max_items to stop charging beyond a point.
Percent of item total, with flat_percent: 10.A $31 order gets $3.10 off.
Tiered percent — 5% over $100, 10% over $250, 15% over $500.The order total picks the tier. One promotion covers the whole ladder instead of three competing ones.

Setting one up

Calculators are configured as part of the thing that uses them. The available calculators for each are discoverable, so a dashboard or a script can present the real list rather than a hardcoded one:
Each calculator declares which settings it takes, so a form can be built for it without knowing the calculator in advance — which is how the dashboard renders these.
A calculator with an amount also has a currency. If it doesn’t match the order’s currency, the calculator contributes nothing rather than converting. Set up one calculator per currency you sell in, or a promotion will silently do nothing for some customers.

Writing your own

When none of the built-in calculators expresses your pricing — dimensional weight, a contract rate card, a rule your finance team invented — you can add one. A calculator is a small class with a name and a method that returns an amount, registered so it appears alongside the built-in options. For delivery specifically, consider whether you want a calculator or a delivery rate provider. A calculator computes a number from what’s in the parcel. A provider asks a carrier for real, live rates. If you want what UPS would actually charge today, that’s a provider. See Custom promotions and Providers.
  • Fulfillments — delivery methods and rates
  • Promotions — the rules that decide when a discount applies
  • Discounts — the rows a promotion produces
  • Taxes — worked out by providers, not calculators