Disclaimer: This website requires JavaScript to function properly. Some features may not work as expected. 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

Return line item calculator

Describes ReturnLineItemCalculator, which calculates a return line item's extended price, discounted price, and sales tax in Optimizely Customized Commerce.

ExtendedPrice

Calculates the price including order-level discount amount (spread over all return line items in the shipment) and any return line item discount amounts.

public void GetExtendedPrice(IReturnLineItem returnLineItem, Currency currency, IReturnLineItemCalculator returnLineItemCalculator)
          {
            var extendedPrice = returnLineItemCalculator.GetExtendedPrice(returnLineItem, currency);
            Debug.WriteLine("Extended price for '{0}': {1}", returnLineItem.Code, extendedPrice);
          }

DiscountedPrice

Only calculates the price with the "line item discount amount," that is, the discount for a specific return line item.

public void GetDiscountedPrice(IReturnLineItem returnLineItem, Currency currency, IReturnLineItemCalculator returnLineItemCalculator)
          {
            var discountedPrice = returnLineItemCalculator.GetDiscountedPrice(returnLineItem, currency);
            Debug.WriteLine("Discounted price for '{0}': {1}", returnLineItem.Code, discountedPrice);
          }

SalesTax

Calculates sales tax for a return line item.

public void GetSalesTax(IReturnLineItem returnLineItem, IMarket market, Currency currency, IOrderAddress shippingAddress, IReturnLineItemCalculator returnLineItemCalculator)
          {
            var salesTax = returnLineItemCalculator.GetSalesTax(returnLineItem, market, currency, shippingAddress);
            Debug.WriteLine("Sales tax for '{0}': {1}", returnLineItem.Code, salesTax);
          }

Change the default calculation

By inheriting from the default implementation of the interface, DefaultReturnLineItemCalculator, you override the calculations. Just override one or more methods in DefaultReturnLineItemCalculator.

public class ReturnLineItemCalculatorOverridingDefault : DefaultReturnLineItemCalculator
      {
        public ReturnLineItemCalculatorOverridingDefault(ITaxCalculator taxCalculator) : base(taxCalculator)
          { }
        protected override Money CalculateExtendedPrice(IReturnLineItem lineItem, Currency currency)
          {
            return new Money(0, currency);
          }
        protected override Money CalculateDiscountedPrice(IReturnLineItem returnLineItem, Currency currency)
          {
            return new Money(0, currency);
          }
        protected override Money CalculateSalesTax(IReturnLineItem returnLineItem, IMarket market, Currency currency, IOrderAddress shippingAddress)
          {
            return new Money(0, currency);
          }
      }

Change the default validation

The default implementation validates that the return values are not negative after the calculation. To change the behavior, override the validation methods, depending on which validation you should override.

public class ReturnLineItemCalculatorOverridingDefault : DefaultReturnLineItemCalculator
      {
        public ReturnLineItemCalculatorOverridingDefault(ITaxCalculator taxCalculator) : base(taxCalculator)
          { }
        protected override void ValidateExtendedPrice(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Extended price must be greater than 0");
              }
          }
        protected override void ValidateDiscountedPrice(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Discounted price must be greater than 0");
              }
          }
        protected override void ValidateSalesTax(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Sales tax must be greater than 0");
              }
          }
      }