Develop > Controller layer > Application developer
Calculation framework
Commerce systems need to calculate monetary amounts and apply them to business objects. Business rules and legal requirements specify how and when these monetary amounts should be calculated. When these rules and requirements change, a good commerce system can adapt to the changes with little or no programming changes.
WebSphere Commerce provides a flexible, generic framework that can be used to implement different kinds of calculations and apply them to the business objects. The framework can handle a wide variety of business and legal requirements without programming. WebSphere Commerce provides a number of method implementations from which you can select to do the calculations. If business or legal requirements require a programming change, you can make many such changes just by programming additional method implementations, without having to change existing programming. These implementations can be overridden.
The calculation framework is part of the WebSphere Commerce order subsystem. The order subsystem is a component of the WebSphere Commerce Server that provides shopping carts, order processing, and order management function support. The order system also includes related services, such as pricing, taxation, payment, inventory, and fulfillment.
WebSphere Commerce business objects and the calculation framework
The WebSphere Commerce calculation framework calculates monetary amounts associated with OrderItem business objects. An OrderItem represents something that a customer has selected for purchase. Each OrderItem has a reference to an offer, a contract, a shipping mode, and a fulfillment center. Monetary amounts that are determined by the calculation framework are stored with each OrderItem.
Each OrderItem also has a quantity attribute that is a unitless number. The quantity attribute can be multiplied by the nominal quantity attribute of the CatalogEntryShippingInformation object associated with the CatalogEntry object to arrive at the actual quantity represented by the OrderItem. The CatalogEntryShippingInformation object specifies the unit of measurement in which quantities are stated.
OrderItems can be grouped to make an Order. OrderItems that are part of an Order can be grouped to form SubOrders. OrderItems in a SubOrder object have the same shipping address, and can be used to display subtotals of their OrderItem amounts.
All OrderItems in an Order are associated with a single currency.
The total monetary amounts that are calculated for the discounts, shipping charges, and taxes for the OrderItems in the Order are stored with the Order.
Calculation framework overview
There are five major components to the WebSphere Commerce calculation framework:
- Calculation methods
- Calculation methods reference task commands to implement the parts of the calculation framework.
- Calculation usages
- Calculation usages are the categories of calculations that are performed using the calculation framework. These include discounts and sales tax.
- Calculation codes
- Calculation codes indicate the calculations to be performed for OrderItems.
- Calculation rules
- Calculation rules calculate the monetary amounts for the calculation codes associated with an OrderItem.
- Calculation scales and calculation ranges
- Calculation scales allow a calculation rule for determining monetary amounts in a manner that is similar to looking up a value from a table. Calculation ranges define the relationship between a look-up number and value to be located for a calculation scale.
Some of the major relationships between the calculation framework components are shown in the following unified modeling language (UML) diagram. Calculation methods have been omitted to make the illustration simpler.
Notes:
- StoreEntityCalculationUsageRel describes the high-level behavior of a calculation usage within a store or store group.
- The relationship between CalculationRule and TaxCategory applies only for sales tax and shipping tax calculation usages.
- Calculation methods
A calculation method implements a piece of the calculation framework. Different calculation method classes are used for the different operations required to complete a calculation within the calculation framework.
- Calculation usages
The WebSphere Commerce calculation framework is a generic framework for calculations. When implementing a calculation using this framework, first define the type of calculation to be performed. The types of calculations you can perform are called calculation usages. Calculation usages are assigned a calculation usage code.
- Calculation codes
Items for sale in a retail store often have attached price tags indicating information other than the price of the item. For example, if the item is on sale, the price tag indicates the percentage discount to apply to the price. Similarly, WebSphere Commerce attaches calculation codes to order items to indicate the calculations to be performed. The following figure shows a representation of price tags in a retail store compared with calculation codes in WebSphere Commerce.
- Calculation rules
The WebSphere Commerce calculation framework separates the object that indicates the calculation to be performed for an order item (calculation code) from the object or objects responsible for doing the calculation, called a calculation rule.
- Calculation scales and calculation ranges
Many calculations in WebSphere Commerce involve looking up a value from a table. For example, a store has shipping charges based on the number of items shipped in an order.
- Examples: Applying the calculation framework
Only the default calculation methods and calculation usages provided with WebSphere Commerce are used in these examples. They do not cover customization of the calculation framework.
Related concepts
Calculation scales and calculation ranges
Related reference
Example: Sales tax and shipping tax calculations