Changing pricing rules
This section describes on how to change calculation of pricing fields.
Pricing rules are applied when calculating order grand total.
Main areas of price calculations in an order are:
- Calculating order totals
- Caculting VAT
- Fees
- Delivery costs
All these calculations are done in the pricing rules plugin, which consists of four sections.
- Calculating order totals is implemented in OrderTotalCalculator class, which implements IOrderTotalCalculator interface.
- Calculating VAT is implemented in VatCalculator class, which implements IVatCalculator interface.
- Calculating Fees is implemented in FeesCalculator class, which implments IFeesCalculator interface.
- Calculating Delivery costs is implmented in DeliveryCostCalculator class, which implements IDeliveryCostCalculator interface.
Each of above four implementations can be replaced by custom code.
To replace the default implementation, make your own class and implment the intended interface from above list or extend the default implementation (inherrit your class from the default implementation class), and copy the .dll which contain your class into webroot/bin folder.
For example, to introduce your own Fees, you would write your own class, which extends FeeCalculator default implementation of IFeeCalculator interface. If the class name is BasicFeeCalculator, and it is contained in the assembly Litium.Studio.Sample, then the corresponding implementation class BasicFeeCalculator would look as follows.
namespace Litium.Studio.Sample.ECommerce.PricingRules
{
/// <summary>
/// a basic fee calculator.
/// </summary>
public class BasicFeeCalculator : FeesCalculator
{
/// <summary>
/// Calculate Fees.
/// </summary>
/// <param name="orderCarrier">Carrier for which fees need to be calculted</param>
/// <param name="token">Security token.</param>
public override void CalculateFromCarrier(OrderCarrier orderCarrier, SecurityToken token)
{
//TODO: implement fee calculation.
}
}
}
When you have placed the .dll file into the bin directory, and Litium Studio will detect and start using the BasicFeeCalculator code instead of the default implementation.