Home » Developing » Developing in Litium Studio » Litium Studio ECommerce » Pricing rules plugin
This article will give you a deep understanding about the "Pricing Rules Plugin", its component parts, and its default implementation.
See also in other articles:
Introduction
When a end customer buy some items from the webshop, and proceed to checkout, a final total should be calculated for the order. This total will be the amount the end customer has to pay to buy the products he has in the order. In Litium Studio, we will call this final total as the "Grand Total" of the order. Usually the Grand Total is not just an addition of prices of items purchased. There can be discounts and special prices (such as from campaigns), additional costs such as delivery cost and fees, and also VAT.
Therefore, calculating Grand Total involves some calculation rules, which in Litium Studio is called "Pricing Rules".
The pricing rules are implemented in the "Pricing Rules Plugin".
Component Parts
- Order Total Calculator
- Fees Calculator
- Delivery Cost Calculator
- Vat Calculator
- Campaign Calculator
- Checkout Flow
Use the below diagram as a reference to identify the component parts of the pricing rules plugin.

The pricing rules implemented in the plugin are all related to each other, because it achieves the common goal of calculating the order grand total. This calculation is done by a method in order collection, OrderCollection::CalculateOrderTotals() . Please refer order grand total calculation to see the order of different rules being called.
Order Total Calculator
This component is the implementation of OrderTotalCalculatorBase. It has two methods, that you should implement.
- CalculateFromCarrier(OrderCarrier orderCarrier, SecurityToken token)
- CalculatePaymentInfoAmounts(OrderCarrier orderCarrier, SecurityToken token)
Calculate from carrier is responsible for calculating following calculated amounts in the order carrier. For the specific formula's used in doing this calculations, please refer to pricing fields of an order.
- TotalDiscountAmount and TotalPrice for each Order Row.
- TotalDeliveryCost of the order (without vat).
- TotalFee of the order (without vat).
- TotalDiscount of the order, this is only the order level discounts, this does not include campaign discounts or order row level discounts.
- TotalCampaignDiscount of the order. This is different from Total discount.
- Total, the order total without the vat information.
CalculatePaymentInfoAmounts is to set the amount field of PaymentInfo attached to order. this is a information copying process, where order grand total is coppied to PaymentInfo object, which intern will be used by the payment providers to collect money for the order.
Fees Calculator
Fees calculator is the implementation of FeesCalculatorBase class. It has the single method you should override, which is called,
CalculateFromCarrier(Litium.Foundation.Modules.ECommerce.Carriers.OrderCarrier orderCarrier, SecurityToken token)
In the implementation of this method, any fees applicable for the order should be added.
Delivery Cost Calculator
This is the implementation of the DeliveryCostCalculatorBase class. You have three methods that you should override and implement.
- CalculateFromCarrier(OrderCarrier orderCarrier, SecurityToken token)
- CalculateFromCarrier(DeliveryCarrier deliveryCarrier, SecurityToken token)
- CreateDeliveries(OrderCarrier orderCarrier, SecurityToken token)
The CalculateFromCarrier(OrderCarrier orderCarrier, SecurityToken token) method calculates the delivery cost for each delivery. Therefore, it should internally call the CalculateFromCarrier(DeliveryCarrier deliveryCarrier, SecurityToken token) method.
The CalculateFromCarrier(DeliveryCarrier deliveryCarrier, SecurityToken token) method calculates the delivery cost for a specific delivery.
The CreateDeliveries(OrderCarrier orderCarrier, SecurityToken token) method is responsible for creating deliveries for the order. This method should makesure that each order row is participating in atleast in one delivery row, and all items in the order rows are correctly represented in delivery rows.
The default implementation of the delivery cost calculator implements a simplified factory method design pattern, which make it easier for you to quickly implement your own custom delivery cost calculations. To see an example please refer custimizing the pricing rules.
Vat Calculator
This is the implementation of VatCalculatorBase class. You have to implement following methods.
- void CalculateFromCarrier(OrderCarrier orderCarrier, SecurityToken token);
- void CalculateTotalFeeVat(OrderCarrier orderCarrier);
- void CalculateTotalDeliveryVat(OrderCarrier orderCarrier);
- decimal GetOrderRowsVatAmount(OrderCarrier orderCarrier);
What the vat calculator does is pretty straight forward, it calculates VAT!.
Note that, its only the method void CalculateFromCarrier(OrderCarrier orderCarrier, SecurityToken token); is part of the order grand total calculation flow, and it is the last method call. Therefore, at the very end of this method you should calculate the GrandTotal of the order, according the grand total calculation formula.
Note that calculating fee vat and delivery vat is not implemented by default. This is due to the variety of ways these calculations are handled in different industries and situations. The percentage of delivery and fee vat that you should apply for a particular delivery should be assertained from the accounts department of your customer. You will see that, the percentage will differ based on what you have in the delivery or the order, and also their respective vat percentages.
In any case, do NOT reduce vat for ANY discount. This is because, when you do the discounts it is inclusive of VAT; that is amount of VAT reduction is part of the discount.
Campaign Calculator
The campaigns are special pricing rules. They are explained in detail seperately in Campaign articles. Please note that, campaigns may need a order grand total calculation to assertain the grand total amount before applying the campaign, and therefore would be initiating a grand total calculation of their own.
Checkout Flow
Checkout flow is rather the rules governing the usage of pricing rules implementations we have discussed above, when making a ECommerce order. This is dealt with seperately in Checkout flow.
Comments made
No comments are made
You need to be logged in to make a comment