Try our conversational search powered by Generative AI!

Calculating and adding taxes to prices on product pages

Vote:
 

I am working on an e-commerce solution that needs to go to new markets.

All prices are to be listed including taxes on pages. The current implementation is using the OrderContext.Current.GetTaxes method, which does not read through the cache. This hits the database really hard.

I know that taxes are supposed to be calculated in the cart. But how would you guys usually calculate and add taxes to prices in product lists and product detail pages?

For our commerce platform, the tax jurisdiction will always be tied to the current market of the session.

We are currently using Commerce version 11.2.6.

#192641
Edited, May 22, 2018 7:31
Vote:
 

If you upgrade to Commerce 12.2, then the tax handling will be improved, including caching. If upgrading is not an option, you can always implement a wrapper around OrderContext.Current.GetTaxes which use cache to reduce db calls.

#192650
May 22, 2018 10:03
Vote:
 

Thanks, Quan.

I did not know about the improvements in version 12. We might upgrade in near future.

I have considered wrapping the GetTaxes method to add caching around it. However, I was wondering if there is another approach than using the order system (OrderContext) to calculate prices with tax for listing purposes? Is there a best practice using just the pricing system?

#192656
May 22, 2018 11:45
Vote:
 

It's also one part of Commerce 12. Previously the pricing system always assumed that the prices does not include taxes. In Commerce 12 you have new property in IMarket (PricesIncludeTax) to control if the prices in that market already include taxes or not. 

#192657
May 22, 2018 12:03
Vote:
 

Cool, thanks for the info.

#192658
May 22, 2018 12:04
Vote:
 

We have upgraded to Commerce 12.2 and are experiencing some trouble with tax. 

I have in 2 separate browsers (one in incognito) added the same product to the cart. When i go to checkout page and list my cart and prices for the cart i get different values?

In one window i get with tax and one without? Calling _orderGroupCalculator.GetOrderGroupTotals(_cart) when debugging gives me different result even though i'm on the same site, same market, added the same product?

_orderGroupCalculator.GetOrderGroupTotals(cart)
{EPiServer.Commerce.Order.OrderGroupTotals}
HandlingTotal: {0,00 kr}
ShippingTotal: {0,00 kr}
SubTotal: {956,80 kr}
TaxTotal: {0,00 kr}
Total: {956,80 kr}
_orderFormModels: Count = 1


_orderGroupCalculator.GetOrderGroupTotals(cart)
{EPiServer.Commerce.Order.OrderGroupTotals}
HandlingTotal: {0,00 kr}
ShippingTotal: {0,00 kr}
SubTotal: {956,80 kr}
TaxTotal: {239,20 kr}
Total: {1.196,00 kr}
_orderFormModels: Count = 1

Also when changing Shipping Country tax doesnt seem to be updated. E.g. shipping to Sweden i get 25% tax, but switching to a country without tax I still receive 25% tax? Or sometimes no tax at all? Is there any problem with caching tax too much now?

#194198
Jun 15, 2018 15:00
Vote:
 

@Daniel: Tax is calculated via shipping address of the shipment. If the shipment has invalid shipping address then tax won't be calculated for it as it can't find the matching tax settings. I suspect that the cart in incognito mode has no valid shipping address set?

#194258
Edited, Jun 18, 2018 9:43
Vote:
 

Quan, yes that was the problem. But then i have another question regarding presentation of the price.

We have prices excluding tax in episerver commerce. But want to display it with tax on the product page. We can not change it in commerce, we need to have it excluding tax.

Initally there is no Shipping on the cart, so there won't be any shipping country to calculate tax from.

From what i have found Shipping is added to the cart first when you add a LineItem. So how can i set a Shipping Country so Episerver can calculate the tax so i can get the price including tax.

Since the customer hasn't choosed shipping country initially, we want to set it based on the customers ip-address.

#196332
Aug 27, 2018 10:52
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.