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

Interface IReturnOrderFormCalculator

Calculates totals on an IReturnOrderForm.

Namespace: EPiServer.Commerce.Order
Assembly: Mediachase.Commerce.dll
Version: 12.17.2
Syntax
public interface IReturnOrderFormCalculator
Examples
    /// <summary>
/// Sample implementation of <see cref="IReturnOrderFormCalculator"/>.
/// </summary>
public class ReturnOrderFormCalculatorSample : IReturnOrderFormCalculator
{
private readonly IShippingCalculator _shippingCalculator;

public ReturnOrderFormCalculatorSample(IShippingCalculator shippingCalculator)
{
_shippingCalculator = shippingCalculator;
}

public Money GetTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
{
var total = GetSubTotal(returnOrderForm, currency) + GetHandlingTotal(returnOrderForm, currency) - GetOrderDiscountTotal(returnOrderForm, currency);

//If the prices in the order where the return order form belongs to already include tax, then it does not need to calculate tax.
if (returnOrderForm.PricesIncludeTax)
{
    return total;
}
//otherwise; the prices in the order exclude tax, it should calculate the tax total and include it to the return value.
total += GetReturnTaxTotal(returnOrderForm, market, currency);
return total;
}

public Money GetSubTotal(IReturnOrderForm returnOrderForm, Currency currency)
{
var result = returnOrderForm.Shipments.Sum(shipment => _shippingCalculator.GetShippingReturnItemsTotal(shipment, currency).Amount);
return new Money(result, currency);
}

public Money GetHandlingTotal(IReturnOrderForm returnOrderForm, Currency currency)
{
return new Money(returnOrderForm.HandlingTotal, currency);
}

[Obsolete("This is no longer used. The order discount total should be calculated at IOrderGroup level. See IOrderGroupCalculator.GetOrderDiscountTotal(orderGroup).")]
public Money GetOrderDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency)
{
return new Money(0, currency);
}

public Money GetDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency)
{
var result = returnOrderForm.Shipments
        .Sum(shipment => shipment.GetShipmentDiscountPrice(currency).Amount + shipment.LineItems.OfType<IReturnLineItem>()
        .Sum(item => item.GetDiscountTotal(currency).Amount));

return new Money(result, currency);
}

public Money GetReturnTaxTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
{
return new Money(returnOrderForm.Shipments.Sum(shipment => _shippingCalculator.GetReturnSalesTax(shipment, market, currency).Amount), currency);
}

public OrderFormTotals GetReturnOrderFormTotals(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
{
var formHandlingTotal = GetHandlingTotal(returnOrderForm, currency);
var formShippingTotal = new Money(0, currency);
var formSubTotal = GetSubTotal(returnOrderForm, currency);
var formTaxTotal = GetReturnTaxTotal(returnOrderForm, market, currency);
var formTotal = GetTotal(returnOrderForm, market, currency);
var formDiscountTotal = GetDiscountTotal(returnOrderForm, currency);
var shipmentTotalsDictionary = returnOrderForm.Shipments.ToDictionary(shipment => shipment, shipment => _shippingCalculator.GetShippingTotals(shipment, market, currency));

return new OrderFormTotals(formHandlingTotal, formShippingTotal, formSubTotal, formTaxTotal, formTotal, formDiscountTotal, shipmentTotalsDictionary);
}
}

Methods

GetDiscountTotal(IReturnOrderForm, Currency)

Gets the total of all discounts applied on an IReturnOrderForm.

Declaration
Money GetDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency)
Parameters
Type Name Description
IReturnOrderForm returnOrderForm

The return order form.

Currency currency

The currency.

Returns
Type Description
Money

The discount total of the return order form.

Remarks

There're three types of discount can be applied to an order: order level, shipment level (or shipping discount) and line item level discount.

Examples
        public void GetDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
{
var discountTotal = returnOrderFormCalculator.GetDiscountTotal(returnOrderForm, currency);
Debug.WriteLine("Discount total for return order form '{0}': {1}", returnOrderForm.OrderFormId, discountTotal);
}

GetHandlingTotal(IReturnOrderForm, Currency)

Gets the handling total of an IReturnOrderForm.

Declaration
Money GetHandlingTotal(IReturnOrderForm returnOrderForm, Currency currency)
Parameters
Type Name Description
IReturnOrderForm returnOrderForm

The return order form.

Currency currency

The currency to be used in the calculation.

Returns
Type Description
Money

The handling total for the return order form.

Examples
        public void GetHandlingTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
{
var handlingTotal = returnOrderFormCalculator.GetHandlingTotal(returnOrderForm, currency);
Debug.WriteLine("Handling total for return order form '{0}': {1}", returnOrderForm.OrderFormId, handlingTotal);
}

GetOrderDiscountTotal(IReturnOrderForm, Currency)

Gets the total of all order level discounts applied on IReturnOrderForm.

Declaration
Money GetOrderDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency)
Parameters
Type Name Description
IReturnOrderForm returnOrderForm

The return order form.

Currency currency

The currency.

Returns
Type Description
Money

The order level discount total of the return order form.

Remarks

There're three types of discount can be applied to an order: order level, shipment level (or shipping discount) and line item level discount. This only returns the order level discount.

Examples
        public void GetOrderDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
{
var orderDiscountTotal = returnOrderFormCalculator.GetOrderDiscountTotal(returnOrderForm, currency);
Debug.WriteLine("Order discount total for return order form '{0}': {1}", returnOrderForm.OrderFormId, orderDiscountTotal);
}

GetReturnOrderFormTotals(IReturnOrderForm, IMarket, Currency)

Gets the order form totals for an IReturnOrderForm.

Declaration
OrderFormTotals GetReturnOrderFormTotals(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
Parameters
Type Name Description
IReturnOrderForm returnOrderForm

The return order form.

IMarket market

The market to be used in the calculation.

Currency currency

The currency.

Returns
Type Description
OrderFormTotals

An order form totals.

GetReturnTaxTotal(IReturnOrderForm, IMarket, Currency)

Gets the tax total of an IReturnOrderForm.

Declaration
Money GetReturnTaxTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
Parameters
Type Name Description
IReturnOrderForm returnOrderForm

The return order form.

IMarket market

The market to be used in the calculation.

Currency currency

The currency to be used in the calculation.

Returns
Type Description
Money

The total tax amount of the return order form.

Examples
        public void GetReturnTaxTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
{
var returnTaxTotal = returnOrderFormCalculator.GetReturnTaxTotal(returnOrderForm, market, currency);
Debug.WriteLine("Tax total for return order form '{0}': {1}", returnOrderForm.OrderFormId, returnTaxTotal);
}

GetSubTotal(IReturnOrderForm, Currency)

Gets the subtotal of an IReturnOrderForm.

Declaration
Money GetSubTotal(IReturnOrderForm returnOrderForm, Currency currency)
Parameters
Type Name Description
IReturnOrderForm returnOrderForm

The return order form.

Currency currency

The currency to be used in the calculation.

Returns
Type Description
Money

The subtotal for the return order form.

Examples
        public void GetSubTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
{
var subTotal = returnOrderFormCalculator.GetSubTotal(returnOrderForm, currency);
Debug.WriteLine("Subtotal for return order form '{0}': {1}", returnOrderForm.OrderFormId, subTotal);
}

GetTotal(IReturnOrderForm, IMarket, Currency)

Gets the total for an IReturnOrderForm.

Declaration
Money GetTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
Parameters
Type Name Description
IReturnOrderForm returnOrderForm

The return order form.

IMarket market

The market to be used in the calculation.

Currency currency

The currency to be used in the calculation.

Returns
Type Description
Money

The total for the return order form.

Examples
        public void GetTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
{
var total = returnOrderFormCalculator.GetTotal(returnOrderForm, market, currency);
Debug.WriteLine("Total for return order form '{0}': {1}", returnOrderForm.OrderFormId, total);
}