Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Tax calculator

Describes TaxCalculator in Optimizely Commerce Connect 13, which calculates a line item's tax value and tax amount.

  • Sales tax – Calculates sales tax for a single line item based on market, shipping address, and base price. [New in 13.0.0.]

    public Money CalculateSalesTax(ILineItem lineItem, IMarket market, IOrderAddress shippingAddress, Money basePrice, ITaxcalculator taxCalculator)
           {
             return taxCalculator.GetSalesTax(ILineItem lineItem, 
                                              IMarket market, 
                                              IOrderAddress shippingAddress, 
                                              Money basePrice);
           }
    
  • Sales tax – Calculates sales tax for line items based on market, shipping address and currency. [New in 13.0.0]

    public Money CalculateSalesTax(IEnumerable<ILineItem> lineItems, 
                                        IMarket market, 
                                        IOrderAddress shippingAddress, 
                                        Currency currency, 
                                        ITaxCalculator taxCalculator)
           {
             return taxCalculator.GetSalesTax(lineItems, market, shippingAddress, currency);
           }
    

Change the default calculation

By inheriting from the default implementation of the interface, DefaultTaxCalculator, you can override the calculation of get tax value and get tax category name. Just override one or several methods in the DefaultTaxCalculator.

public class TaxCalculatorOverridingDefault : DefaultTaxCalculator
      {
        public TaxCalculatorOverridingDefault(IContentRepository contentRepository, ReferenceConverter referenceConverter)
          : base(contentRepository, referenceConverter)
          { }
        protected override string GetTaxCategoryNameById(int taxCategoryId)
          {
            return string.Empty;
          }
        protected override IEnumerable<ITaxValue> GetTaxValues(string taxCategory, string languageCode, IOrderAddress orderAddress)
          {
            return new List<ITaxValue>() { new TaxValue(10, "SalesTax", "clothing", TaxType.SalesTax) };
          }
      }