Popular Posts

Calculation framework

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.

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. WebSphere Commerce provides a number of method implementations from which we can select to do the calculations. If business or legal requirements require a change, this can be achieved just by customizing some of the existing implementations without much change. These implementations can be overridden.

Working

The calculation framework is used by the order subsystem for taxation, ship charge calculation etc.

The 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.

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
Indicates the task commands to implement the parts of the calculation framework to complete a calculation.
Using a number of calculation methods instead of one large calculation method makes customizing calculations much simpler. Calculation methods are defined in the CALMETHOD database table.
     
General flow of calculation methods
  • InitializeCalculationUsage
  • ApplyCalculationUsage calls:
    • CalculationCodeCombine calls:
      • CalculationCodeQualify
    • CalculationCodeCalculate calls:
      • CalculationRuleCombine calls:
        • CalculationRuleQualify
        • CalculationRuleCalculate calls:
          • CalculationScaleLookup
          • CalculationRange
    • CalculationCodeApply
  • SummarizeCalculationUsage
  • FinalizeCalculationUsage


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. The default implementations of this calculation method call the CalculationCodeCombine, CalculationCodeCalculate, and CalculationCodeApply calculation methods.
ApplyCalculationUsage calculation methods are used for both order processing and product display purposes. During order processing, an ApplyCalculationUsage calculation method is called by the OrderPrepare command to calculate the monetary amounts for a list of OrderItems. A monetary amount is applied to each OrderItem so the monetary amount is available for later calculations.
For display purposes, ApplyCalculationUsage calculation methods are called by data beans to calculate monetary amounts.
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.


Calculation usages
Indicates the categories of calculations that are performed using the calculation framework. The types of calculations we can perform are called calculation usages. Calculation usages are assigned a calculation usage code.


Calculation usage code
Calculation usage
-1
Discount
-2
Shipping
-3
Sales tax
-4
Shipping tax
-5
Coupon
-6
Surcharge
-7
Shipping Adjustment

STENCALUSG.SEQUENCE column stores the order of calculation usage to be applied. The entries in this table are initially populated with information from the language-independent bootstrap file:  wcs.bootstrap.xml.
 Default order in which calculation usages are defined in the bootstrap is as follows:
  1. Coupon
  2. Discount
  3. Shipping
  4. Sales tax
  5. Shipping tax
  6. Surcharge (final process)
  7. Shipping adjustment (processed after the shipping calculation usage)
Database tables for calculation usage
CALUSAGE
Maps the calculation usage id and the description of the calculation usage. Values in this table are defined in the language-dependent bootstrap file.
STENCALUSG
This table defines the high-level behavior of a calculation usage for a store or group of stores. If the implementation for a store is not defined, the implementation for the store group is used. If different implementations are defined for the store and the store group, the implementation for the store is used. This database table is initially populated from the language-independent bootstrap file.

Calmethods for each calculation usages provided by WebSphere Commerce

STENCALUSG.USAGEFLAGS holds the value value of the calmethod for the calusage
  • InitializeCalculationUsage: Used do any processing that is required before monetary amounts for OrderItems are calculated
    • InitializeAdjustmentCmdImpl
    • InitializeCouponUsageCmdImpl
    • InitializeSalesTaxCmdImpl
    • InitializeShippingCmdImpl
    • InitializeShippingTaxCmdImpl
  • ApplyCalculationUsage: Used for both order processing and product display purposes
    • ApplyCalculationUsageCmdImpl
    • ApplyCalculationUsageTIKCmdImpl
    • ApplyCouponUsageCmdImpl
    • ApplyShippingCmdImpl
  • SummarizeCalculationUsage: Summarizes the results of calculations for display purposes.
    • SummarizeAdjustmentCmdImpl
    • SummarizeCouponUsageCmdImpl
    • SummarizeSalesTaxCmdImpl
    • SummarizeShippingCmdImpl
    • SummarizeShippingTaxCmdImpl
  •  FinalizeCalculationUsage: Does any processing required after the Order has been processed by the ProcessOrder task command
    • FinalizeCouponUsageCmdImpl
Calculation codes
Indicates the calculations to be performed for OrderItems.
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 calculation code attachment can be direct or indirect.

Direct attachment: A calculation code is specified as part of an order, it is attached to all of the items that make up the order. ORDCALCD table relates calculation code to an order. ORDCALCD table relates calculation code to an orderitem

Indirect attachment: The calculation code is specified as part of a catalog entry or catalog group. CATENCALCD table relates a calculation code to a catalog entry. CATGPCALCD table a calculation code to a catalog group. 

Implicit attachment: The calculation codes can be implicitly attached to order items by specifying the default calculation code for a calculation usage in the STENCALUSG database table. The default calculation code is used for those items in an order that do not have any directly or indirectly attached calculation codes of a particular calculation usage. It can be done at the store level and at the store group level. Default calculation code at the store group level can be specified only when the store level default calculation code is not specified.


Database tables for calculation codes
CALCODE: Defines calculation codes
CALCODEDSC: Associates descriptions of a calculation code in multiple languages
CALCODEMGP: Associates a calculation code with a member group
CALCODTXEX: Associates a calculation code with a tax category
CATGPCALCD: Associates a calculation code to a catalog group in a specific store and, optionally, for a specific trading agreement
CATENCALCD: Associates a calculation code with catalog entries in a specific store and, optionally, for a specific trading agreement
ORDCALCD: Associates a calculation code to an order. This table allows you to specify whether calculations should ignore indirectly attached calculation codes.
ORDICALCD: Associates a calculation code to an order item. This table allows you to specify whether calculations should ignore indirectly attached calculation codes.
STENCALUSG:Defines the default calculation code for a calculation usage in a store or group of stores.


Calculation rules
Indicates the rules to calculate the monetary amounts for the calculation codes associated with an OrderItem. These objects are responsible for doing the calculation. There can be many calculation rules for one calculation code. These can be combined/restricted/ordered to perform calculations.

Calculation methods for calculation rules
  • CalculationRuleCombine
  • CalculationRuleQualify
    • DiscountCalculationRuleQualifyCmdImpl
    • ShippingCalculationRuleQualifyCmdImpl
    • TaxCalculationRuleQualifyCmdImpl
  •  CalculationRuleCalculate
Database tables for calculation rules
  
CALRULE: Defines calculation rules.
CALRULEMGP: Associates a calculation rule with a member group.
SHPJCRULE: Can be used to choose a calculation rule based on the shipping mode and fulfillment center.
STENCALUSG: Helps to determine how to combine multiple calculation rules for an order item.
TAXJCRULE: Helps to choose a calculation rule when shipping from a fulfillment center to a shipping address that matches one of the tax jurisdictions in a particular tax jurisdiction group.


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.

Database tables for calculation scales and calculation ranges
CALSCALE: Defines calculation scales.
CALSCALEDS: Associates descriptions of a calculation scale in multiple languages.
CRULESCALE: Relates a calculation scale to a calculation rule. A calculation rule can have multiple calculation scales and a calculation scale can be used by multiple calculation rules.
CALRANGE: Defines the calculation ranges that make up a calculation scale.
CALRLOOKUP: Contains the look-up results for calculation ranges
Calculation methods for calculation scales
  • MonetaryCalculationScaleLookup
    • NetPriceCalculationScaleLookupCmdImpl
    • NetPriceWithQuantityAsResultMultiplierCalculationScaleLookupCmdImpl
    • NetShippingCalculationScaleLookupCmdImpl
    • NonDiscountedPriceCalculationScaleLookupCmdImpl
    • TaxableNetPriceCalculationScaleLookupCmdImpl
    • TaxableNetPriceTaxOnTaxCalculationScaleLookupCmdImpl
    • TaxableNetPricePlusNetShippingCalculationScaleLookupCmdImpl
    • TaxableUnitPriceCalculationScaleLookupCmdImpl
    • TaxableUnitPricePlusUnitShippingCalculationScaleLookupCmdImpl
    • UnitPriceCalculationScaleLookupCmdImpl
    • UnitShippingCalculationScaleLookupCmdImpl
  • QuantityCalculationScaleLookup
    • QuantityCalculationScaleLookupCmdImpl
    • QuantitySpreadByNetPriceCalculationScaleLookupCmdImpl
    • WeightCalculationScaleLookupCmdImpl
    • WeightSpreadByNetPriceCalculationScaleLookupCmdImpl
  •  CalculationRange
    • PercentageCalculationRangeCmdImpl
    • PerUnitAmountCalculationRangeCmdImpl
    • FixedAmountCalculationRangeCmdImpl
   

Click the below know the tables involved in fetching the shipping charge.

http://wcs-tips.blogspot.in/p/calculation-of-shipping-charge.html
   
   




2 comments: