Fixing “tax total” differences

Sometimes you will need / want to display the price including tax on the line items of your cart. When you do this, you may see differences in the totals, using the calculators in Commerce, between the sum of the prices in your cart as they are displayed and the sum from the calculator.

This is caused by the fact that the DefaultTaxCalculator rounds the sum after all line items are processed. To prevent this round the tax value of the line item before adding it to the total.

The only line that needed to be changed is located in the CalculateTaxTotal method :

amount1 += GetTaxes(taxValues, TaxType.SalesTax, num3);

amount1 += currency.Round(GetTaxes(taxValues, TaxType.SalesTax, num3));

See full code for the calculator in this gist

You may want to have a look at Son Do’s post as well on how to integrate the calculator with Commerce Manager as well.

2 thoughts on “Fixing “tax total” differences

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s