Tax not getting added to cart total

Vote:
 

Hi,

I am using Commerce version 12.2, this is wrt Tax Calculation. We have our custom tax cacluator which was using ITaxCalculator previously, but now it implements IOrderGroupCalculator. We are able to calculate the tax correctly, but now I see that the total does not add the tax which was not the case previously.

I wrote the below code to overcome this issue:

var TotalAmount = ServiceLocator.Current.GetInstance().GetTotal(Cart).Amount + ServiceLocator.Current.GetInstance().GetTaxTotal(Cart).Amount;

Also, wouldnt it call both GetTotal and GetTaxTotal everytime even if there is no change (which is an unwanted back and forth)

Is there a better way to implement this?

Regards,

Siddharth

#194470
Jun 21, 2018 19:28
Vote:
 

Hi Siddharth, 

I guess you just want to get the total of order with tax, then you only need to use IOrderGroupCalculator.GetTotal(Cart). This method will includes GetTaxTotal(Cart) as well, and it doesn't calculate the tax if there's no change. 

That means your code should be: 

var TotalAmount = ServiceLocator.Current.GetInstance<IOrderGroupCalculator>().GetTotal(Cart).Amount

/Tuan

#194483
Jun 22, 2018 9:48
Vote:
 

Hi,

I just want to add up more information. In Commerce 12, we've introduced a new setting on IMarket, PricesIncludeTax, indicating whether the prices of the market includes tax or not. In the order we have that setting as well, got from the market when order was created. So if it is true, it means the prices (item prices, shipping costs,..) already include tax, therefore the tax total got from the tax calculator was not added up to the order total, since the order already includes tax. So please check that setting as well.

/Bien Nguyen

#194486
Jun 22, 2018 10:04
Vote:
 

@Tuan: I actually tried that first but it doesnt return me the correct value (cart total + tax), hence I manually added the tax myself. Also, I can see that in the Orderform table in SQL the TaxTotal column is 0.00 for all orders. 

#194508
Jun 22, 2018 15:59
Vote:
 

Hi @Bien, the PricesIncludeTax is false for the market. Below is the code:Submit

bool taxIncluded = ServiceLocator.Current.GetInstance<ICurrentMarket>().GetCurrentMarket().PricesIncludeTax;

#194511
Jun 22, 2018 16:21
Vote:
 

Hi,

You said that your custom tax calculator was using ITaxCalculator but now it implements IOrderGroupCaclculator. Could you show us your custome codes? Not need the detail implementation but I want to know what methods that you customized, so that I could have a better guess.

/Bien Nguyen

#194544
Jun 25, 2018 10:42
Vote:
 

@Bein Nguyen: Below is the code snippet for your reference:

public class CustomTaxCalculator : DefaultOrderGroupCalculator, IOrderGroupCalculator
{
public readonly IOrderFormCalculator _orderFormCalculator;
public readonly IReturnOrderFormCalculator _returnOrderFormCalculator;
public readonly IMarketService _marketservice;

public CustomTaxCalculator(IOrderFormCalculator orderFormCalculator, IReturnOrderFormCalculator returnOrderFormCalculator, IMarketService marketservice) 
: base(orderFormCalculator, returnOrderFormCalculator, marketservice)
{
this._orderFormCalculator = orderFormCalculator;
this._returnOrderFormCalculator = returnOrderFormCalculator;
this._marketservice = marketservice;
}

public new Money GetTaxTotal(IOrderGroup orderGroup)
{
return CalculateTaxTotal(orderGroup);

}

public new Money GetTotal(IOrderGroup orderGroup)
{
Money total = this.CalculateTotal(orderGroup);
this.ValidateTotal(total);
return total;
}

protected override Money CalculateTaxTotal(IOrderGroup orderGroup)
{
decimal taxTotal = 0.0M;
var orderGroupObj = orderGroup as OrderGroup;
if (orderGroupObj == null)
return new Money(0, Currency.USD);
orderGroupObj.TaxTotal = 0;
if (orderGroup.GetFirstForm().Shipments.Count > 0)
{ 
foreach (IShipment shipment in orderGroup.GetFirstForm().Shipments)
{
IOrderAddress address = shipment.ShippingAddress;
if (address != null)
{
taxTotal = CalculateTaxUsingCustomService(orderGroup);
}
}
}
return new Money(taxTotal, Currency.USD);
}

protected override Money CalculateTotal(IOrderGroup orderGroup)
{
Currency currency = orderGroup.Currency;
Money money = this.GetSubTotal(orderGroup) + this.GetHandlingTotal(orderGroup) + this.GetShippingSubTotal(orderGroup) - this.GetOrderDiscountTotal(orderGroup) - orderGroup.GetShippingDiscountTotal();
if (!orderGroup.PricesIncludeTax)
money += this.GetTaxTotal(orderGroup);
return money;
}
}

Also, now is see the tax total being computed, but it is not getting stored in the database. For example: The tax total is being displayed on the UI, but the TaxTotal columns in the database is always 0.00 (OrderForm, OrderGroup).

#194554
Edited, Jun 25, 2018 13:28
Vote:
 

Hi,

I would suggest you to override the following method as well, and update the tax total and order total values with your custom tax calculation:

public new OrderGroupTotals GetOrderGroupTotals(IOrderGroup orderGroup)
{
    // your custom code here...
}

/Bien Nguyen

#194581
Edited, Jun 26, 2018 4:49
Vote:
 

@Bien: That did the trick for me, thank you!

#194751
Edited, Jun 29, 2018 20:03
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.