Blog • Orders | Carts

How to calculate cart and order totals

Last updated: 05 Jul 2019

There are two methods that may be used to calculate cart and order totals. The method used depends on the calculation_method setting. The default is currently the simple method and this will continue to be the case for all stores currently using this method. In future, new stores will use the line method by default.

The simple calculation method

Taxes are calculated for each line and are rounded to the nearest penny for the unit.

The cart totals are calculated by summing each of the lines and then subtracting any discounts.

Example:

Unit price $9.99 $0.03 −$10.00  
Quantity 3 1 1
Line price $29.97 $0.03 −$10.00
Tax rate 0.20 0.00   Total tax $5.97
Unit tax $1.99 $0.00  
Line tax $5.97 $0.03  
Unit subtotal $9.99 $0.03   Total $25.97
Line subtotal $29.97 $0.03  
Total $35.94 $0.03 −$10.00

In summary, discounts are applied after tax and rounding occurs at the individual unit level.

The line calculation method

Any cart-level discount is distributed among the cart items such that the amount each line gets is in proportion to its value (before tax).

Discounts are calculated for each line by subtracting from the pre-tax value and the discount is rounded to the nearest penny for the line.

Taxes are calculated for each line based on the line value after discounts have been applied and are rounded to the nearest penny for the line.

The cart totals are calculated by summing each of the lines.

Example:

Unit price $9.99 $0.03  
Quantity 3 1
Line price $29.97 $0.03
Unit discount −$3.33 −$0.01
Line discount −$9.99 −$0.01
Tax rate 0.20 0.00 Total tax

$4.00

Unit tax $1.3333r $0.00
Line tax $4.00 $0.00
Unit subtotal $5.3266666667 $0.02 Total $23.99
Line subtotal $19.97 $0.02
Total $23.97 $0.02

In summary, discounts are applied before tax and rounding occurs for whole lines.

Further reading