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 to Kristoffer Cancel reply