Cart calculation and totals

Thor recalculates a cart when a mutation changes commercial inputs. The returned cart is the authoritative result; storefronts should not reproduce the pricing engine from reference data.

Inputs to calculation

  • Managed line quantity and the price selected for the cart’s store, currency, country, price channel, customer groups, and current time.
  • Product and cart discount eligibility, target allocation, codes, priorities, and combination policy.
  • Selected shipping lines and their eligible fixed or relative rates.
  • Line and shipping tax behavior, address-derived rates, and store rounding modes.

Changing a line, customer, country, address, discount code, shipping line, or price channel can affect more than one output. Request the fields the UI needs from every mutation response.

Annotated total

Suppose the returned cart contains two units at EUR 25.00, a EUR 5.00 allocated discount, EUR 4.00 shipping, and EUR 10.80 tax under an exclusive-tax configuration:

Code in text

This example explains the relationship, not a client formula. Read the actual subtotal, line and shipping discount applications, taxedPrice, taxPortions, and total that Thor returns. Tax behavior and rounding can change intermediate results.

Persisted and requested context

Product queries receive context as arguments. A cart persists its context. When a market selection changes, update or replace the cart deliberately; changing only the product query arguments does not rewrite an existing cart.

If a mutation reports a price, stock, shipping, or discount error, fetch the latest cart and let the buyer respond to the new state. Do not retain a locally calculated total through recovery.