Loading...

Last updated: Mar 09 2018

Area: Episerver Commerce Applies to versions: 12 and higher
Other versions:

Line item calculator

The LineItemCalculator calculates a line item's extended price, discounted price, line item price and sales tax.

  • Extended price. Calculates the price including order-level discount amount (spread over all line items in the shipment) and any line item discount amount.
    public void GetExtendedPrice(ILineItem lineItem, Currency currency, ILineItemCalculator lineItemCalculator)
    {
        var extendedPrice = lineItemCalculator.GetExtendedPrice(lineItem, currency);
        Debug.WriteLine("Extended price for '{0}': {1}", lineItem.Code, extendedPrice);
    }
  • Discounted price. Only calculates the price with the "line item discount amount," that is, the discount for a specific line item.
    public void GetDiscountedPrice(ILineItem lineItem, Currency currency, ILineItemCalculator lineItemCalculator)
    {
        var discoutedPrice = lineItemCalculator.GetDiscountedPrice(lineItem, currency);
        Debug.WriteLine("Discounted price for '{0}': {1}", lineItem.Code, discountedPrice);
    }
  • Line item price. Calculates the line item price, which includes a line item's extended price and discounted price.
    public void GetLineItemPrices(ILineItem lineItem, Currency currency, ILineItemCalculator lineItemCalculator)
    {
        var lineItemdPrices = lineItemCalculator.GetLineItemPrices(lineItem, currency);
        Debug.WriteLine("Extended price for '{0}': {1}", lineItem.Code, lineItemdPrices.ExtendedPrice);
        Debug.WriteLine("Discounted price for '{0}': {1}", lineItem.Code, lineItemdPrices.DiscountedPrice);
    }
  • Sales tax. Calculates a line item's sales tax.
    public void GetSalesTax(ILineItem lineItem, IMarket market, Currency currency, IOrderAddress shippingAddress, ILineItemCalculator lineItemCalculator)
    {
        var salesTax = lineItemCalculator.GetSalesTax(lineItem, market, currency, shippingAddress);
        Debug.WriteLine("Sales tax for '{0}': {1}", lineItem.Code, salesTax);
    }

Change the default calculation

By inheriting from the default implementation of the interface, DefaultLineItemCalculator, you can override the extended price and sales tax calculations. To change the calculation of a line item's extended price, override the CalculateExtendedPrice method. To change the calculation of line item's sales tax, override the CalculateSalesTax method.

Change the default validation

The default implementation validates that the extended price and sales tax are not negative after the calculation. To change the behavior, override the ValidateExtendedPrice and ValidateSalesTax methods.


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/