November Happy Hour will be moved to Thursday December 5th.

Interface IReturnLineItemCalculator

NOTE: This is a pre-release API that is UNSTABLE and might not satisfy the compatibility requirements as denoted by its associated normal version.

Calculates the extended price for an IReturnLineItem

Namespace: EPiServer.Commerce.Order
Assembly: Mediachase.Commerce.dll
Version: 13.30.0
Syntax
public interface IReturnLineItemCalculator
Examples
    /// <summary>
/// Sample implementation of <see cref="IReturnLineItemCalculator"/>.
/// </summary>
public class ReturnLineItemCalculatorSample : IReturnLineItemCalculator
{
/// <summary>
/// The tax calculator needed for calculating sales tax of an <see cref="ILineItem"/>.
/// </summary>
private readonly ITaxCalculator _taxCalculator;

public ReturnLineItemCalculatorSample(ITaxCalculator taxCalculator)
{
_taxCalculator = taxCalculator;
}

public Money GetExtendedPrice(IReturnLineItem returnLineItem, Currency currency)
{
//The extended price of a return line item is the price that includes all discounts applied on the return line item, including entry level and order level discounts.
//Of course you might have different calculation here.
var rawExtendedPrice = returnLineItem.PlacedPrice * returnLineItem.Quantity - returnLineItem.GetDiscountTotal(currency).Amount;

return new Money(Math.Max(0, rawExtendedPrice), currency);
}

public Money GetDiscountedPrice(IReturnLineItem returnLineItem, Currency currency)
{
//The discounted price of a return line item is the price that includes all entry level discounts applied on the return line item. That does not take order level discounts into account.
//Of course you might have different calculation here.
var rawDiscountedPrice = returnLineItem.PlacedPrice * returnLineItem.Quantity - returnLineItem.GetEntryDiscount();

return new Money(Math.Max(0, rawDiscountedPrice), currency);
}

public Money GetSalesTax(IReturnLineItem returnLineItem, IMarket market, Currency currency, IOrderAddress shippingAddress)
{
return _taxCalculator.GetSalesTax(returnLineItem, market, shippingAddress, GetExtendedPrice(returnLineItem, currency));
}

public LineItemPrices GetLineItemPrices(IReturnLineItem returnLineItem, Currency currency)
{
return new LineItemPrices(GetExtendedPrice(returnLineItem, currency), GetDiscountedPrice(returnLineItem, currency));
}
}

Methods

GetDiscountedPrice(IReturnLineItem, Currency)

Gets the discounted price of an IReturnLineItem.

Declaration
Money GetDiscountedPrice(IReturnLineItem returnLineItem, Currency currency)
Parameters
Type Name Description
IReturnLineItem returnLineItem

The return line item.

Currency currency

The currency to be used in the calculations.

Returns
Type Description
Money

The discounted price of the return line item.

Examples
        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);
}

GetExtendedPrice(IReturnLineItem, Currency)

Gets the extended price of an IReturnLineItem.

Declaration
Money GetExtendedPrice(IReturnLineItem returnLineItem, Currency currency)
Parameters
Type Name Description
IReturnLineItem returnLineItem

The return line item.

Currency currency

The currency to be used in the calculations.

Returns
Type Description
Money

The rounded extended price of the return line item.

Examples
        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);
}

GetLineItemPrices(IReturnLineItem, Currency)

Gets the extended and discounted prices of an IReturnLineItem.

Declaration
LineItemPrices GetLineItemPrices(IReturnLineItem returnLineItem, Currency currency)
Parameters
Type Name Description
IReturnLineItem returnLineItem

The return line item to calculate the extended price for.

Currency currency

The currency to be used in the calculations.

Returns
Type Description
LineItemPrices

The prices for the return line item.

Examples
        public void GetReturnLineItemPrices(IReturnLineItem returnLineItem, Currency currency, IReturnLineItemCalculator returnLineItemCalculator)
{
var lineItemdPrices = returnLineItemCalculator.GetLineItemPrices(returnLineItem, currency);
Debug.WriteLine("Extended price for '{0}': {1}", returnLineItem.Code, lineItemdPrices.ExtendedPrice);
Debug.WriteLine("Discounted price for '{0}': {1}", returnLineItem.Code, lineItemdPrices.DiscountedPrice);
}

GetSalesTax(IReturnLineItem, IMarket, Currency, IOrderAddress)

Gets the sales tax of an IReturnLineItem.

Declaration
Money GetSalesTax(IReturnLineItem returnLineItem, IMarket market, Currency currency, IOrderAddress shippingAddress)
Parameters
Type Name Description
IReturnLineItem returnLineItem

The return line item.

IMarket market

The market to be used in the calculation.

Currency currency

The currency to be used in the calculations.

IOrderAddress shippingAddress

The shipping address to be used in the calculations.

Returns
Type Description
Money

The sales tax for the return line item.

Examples
        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);
}