Calculation methods
A calculation method implements a piece of the calculation framework. Different calculation method classes are used for the different operations that are required to complete a calculation within the calculation framework.
Using a number of calculation methods instead of one large calculation method makes customizing calculations much simpler. Customizing a calculation often requires merely modifying or overriding one or two of the calculation methods.
Calculation methods use the information that is part of calculation usages, calculation codes, and calculation scales to determine monetary amounts for order items. Calculation methods are categorized by the task that they perform within the calculation framework and the part of the calculation framework to which the calculation method belongs. The following tasks are performed as part of the calculation framework:
Task | Description |
---|---|
Application | Application involves saving the calculated amounts to the WebSphere Commerce database for use in later calculations. |
Initialization | Initialization involves resetting any variables that are used in calculations and clearing any previously calculated results. |
Combination | Combination involves determining the relationships between order items and calculation codes, calculation rules, or calculation scales. Combination can also involve determining the order in which calculation codes are applied to order items. |
Qualification | Qualification involves restricting the set of applicable calculation codes, calculation rules, or calculation scales using some criterion that exists outside of the calculation framework. For example, certain calculation codes might apply only to customers belonging to a specific member group. Qualification is a subtask of combination. |
Calculation | Calculation involves the determination of a monetary amount that applies to order items. |
Look-up | Look-up involves using one value to determine another value. |
Summation | Summation involves determining totals of the monetary amounts for order items. An example of summation is producing the total taxes for an order by adding the taxes calculated for each order item in the order. |
Finalization | Finalization involves any processing that occurs after application. An example of finalization is marking any coupons that are used in an order to prevent the coupons from use in other orders. |
- InitializeCalculationUsage
- ApplyCalculationUsage
- CalculationCodeApply
- CalculationCodeCombine
- CalculationCodeQualify
- CalculationCodeCalculate
- CalculationRuleCombine
- CalculationRuleQualify
- CalculationRuleCalculate
- MonetaryCalculationScaleLookup
- QuantityCalculationScaleLookup
- CalculationRange
- SummarizeCalculationUsage
- FinalizeCalculationUsage
The subclass of a calculation method means the interface that its corresponding command extends. The Java classes that make up the calculation framework are part of the com.ibm.commerce.order.calculation package. The following table shows the calculation method subclasses and their related interfaces.
Calculation method subclass | Interface |
---|---|
InitializeCalculationUsage | com.ibm.commerce.order.calculation.InitializeCalculationUsageCmd |
ApplyCalculationUsage | com.ibm.commerce.order.calculation.ApplyCalculationUsageCmd |
CalculationCodeApply | com.ibm.commerce.order.calculation.CalculationCodeApplyCmd |
CalculationCodeCombine | com.ibm.commerce.order.calculation.CalculationCodeCombineCmd |
CalculationCodeQualify | com.ibm.commerce.order.calculation.CalculationCodeQualifyCmd |
CalculationCodeCalculate | com.ibm.commerce.order.calculation.CalculationCodeCalculateCmd |
CalculationRuleCombine | com.ibm.commerce.order.calculation.CalculationRuleCombineCmd |
CalculationRuleQualify | com.ibm.commerce.order.calculation.CalculationRuleQualifyCmd |
CalculationRuleCalculate | com.ibm.commerce.order.calculation.CalculationRuleCalculateCmd |
MonetaryCalculationScaleLookup | com.ibm.commerce.order.calculation.CalculationScaleLookupCmd |
QuantityCalculationScaleLookup | com.ibm.commerce.order.calculation.CalculationScaleLookupCmd |
CalculationRange | com.ibm.commerce.order.calculation.CalculationRangeCmd |
SummarizeCalculationUsage | com.ibm.commerce.order.calculation.SummarizeCalculationUsageCmd |
FinalizeCalculationUsage | com.ibm.commerce.order.calculation.FinalizeCalculationUsageCmd |
Database tables for calculation methods
Calculation methods are defined in the CALMETHOD database table.
Calculation method data model diagram
How calculation methods work
Various calculation methods are called when WebSphere Commerce calculates monetary amounts. Each subclass of calculation method is used for the other components of the calculation framework.
Calculation methods for calculation usages
Methods | Description |
---|---|
InitializeCalculationUsage | It can be called by the OrderPrepare command to initialize the calculation of monetary amounts. An example of initialization is removing previously calculated values. |
ApplyCalculationUsage | It can be called by the OrderPrepare command to calculate monetary amounts and apply them to an order. It can also be called by data beans to calculate monetary amounts for display purposes. Examples of calculated amounts include order adjustments, shipping charges, and taxes. The default implementations of this calculation method call the CalculationCodeCombine, CalculationCodeCalculate, and CalculationCodeApply calculation methods. |
SummarizeCalculationUsage | It can be called by the OrderPrepare command to summarize calculated values and apply them to an order. Examples include populating SubOrderAdjustments or SubOrder shipping charges or tax amounts. |
FinalizeCalculationUsage | It can be called by the OrderProcess command to mark consumed resources, such as coupons, as no longer available. |
CalculationCodeApply | It can be called by the ApplyCalculationUsage method to apply the calculated values for a list of items to an order. |
CalculationCodeCombine | It can be called by the ApplyCalculationUsage method to identify relationships between order items and calculation codes. The default implementations of the CalculationCodeCombine method use the CATENCALCD, CATGPCALCD, ORDICALCD, and ORDCALCD database tables, and call the CalculationCodeQualify method. |
CalculationCodeQualify | It can be called by the CalculationCodeCombine method to determine if a calculation code applies to a list of order items. |
CalculationCodeCalculate | It can be called by the ApplyCalculationUsage method to calculate values for a list of OrderItems for a particular CalculationCode. |
CalculationRuleCombine | It can be called by the CalculationCodeCalculate method to determine a list of calculation rules and associated OrderItems that should be applied for a calculation code. The default implementations of the CalculationRuleCombine method call the CalculationRuleQualify method and the CalculationRuleCalculate method to find the lowest values for each allowable combination of calculation rules. |
CalculationRuleQualify | It can be called by the CalculationRuleCombine method to determine to which of the items in a list a calculation rule applies. |
CalculationRuleCalculate | It can be called by the CalculationRuleCombine method to calculate values for a list of order items. |
MonetaryCalculationScaleLookup | It can be called by the CalculationRuleCalculate method to determine how a monetary-based calculation scale can be used to determine a calculation range for a list of order items. |
QuantityCalculationScaleLookup | It can be called by the CalculationRuleCalculate method to determine how a quantity-based calculation scale can be used to determine a calculation range for a list of order items. |
CalculationRange | It can be called by the CalculationRuleCalculate method to determine a calculated value from a calculation range look-up result. |
General flow of calculation methods
- InitializeCalculationUsage
- ApplyCalculationUsage calls:
- CalculationCodeCombine calls:
- CalculationCodeQualify
- CalculationCodeCalculate calls:
- CalculationRuleCombine calls:
- CalculationRuleQualify
- CalculationRuleCalculate calls:
- CalculationScaleLookup
- CalculationRange
- CalculationRuleCombine calls:
- CalculationCodeApply
- CalculationCodeCombine calls:
- SummarizeCalculationUsage
- FinalizeCalculationUsage
The ApplyCalculationUsage method can also be called by data beans to calculate monetary amounts used for display purposes outside of order processing.
The following figure illustrates the flow of calculation methods called by the ApplyCalculationUsage method: