Best way to add Tariff to products

Andy Bochmann asked on February 19, 2019 01:09

Hello.

What's the best way to calculate tariffs for certain products in Kentico? This cost will be added in addition to the already existing taxes.

I was trying to write my own ITaxCalculationService implementation. However, I don't think this is the best solution. I would also like to keep the default service to calculate sales tax. As far as I understand, writing my own ITaxCalculationService would disable the build-in tax calculation. The TaxCalculationResult also only includes ItemsTax and ShippingTax. I could use ShippingTax to store the tariff, but this would prevent me from using this field in the future.

Writing my own IShoppingCartCalculator implementation might be another good option. This allows me to add the extra charge to the Total amount. However, I'm not sure if there's a clean way to store the extra cost as metadata in the shopping cart, to show it on the website and in invoices.

Is there any better solution to calculate, save, and show tariff information in a shopping cart? Thanks

Correct Answer

Andy Bochmann answered on February 19, 2019 01:37

I was able to use the IShoppingCartCalculator. In there, I retrieve the current shopping cart and save the tariff information as custom data.

public class TariffChargeShoppingCartCalculator : IShoppingCartCalculator
{
    /// <summary>
    /// Runs shopping cart calculation based on specified calculation data.
    /// </summary>
    public void Calculate(CalculatorData calculationData)
    {
        decimal extraCharge = 0;

        // ...

        var shoppingService = Service.Resolve<IShoppingService>();
        var cart = shoppingService.GetCurrentShoppingCart();
        cart.ShoppingCartCustomData["Section301Tariffs"] = extraCharge;

        calculationData.Result.Total += extraCharge;
        calculationData.Result.GrandTotal += extraCharge;
    }
}

Hope this helps others. It would still be good to know, if there's a better solution.

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.