Friday, November 11, 2016

Adding New Pricing Calculator

The below example shows on how to add a new item price precalculator to calculate the wholesale price.


  1. Create a new class ItemWholeSalePriceCalculator extending ItemPriceCalculator class similar to ItemListPriceCalculator to calculate the whole sale price of each commerceItem.

public class ItemWholeSalePriceCalculator extends ItemPriceCalculator{
  protected void priceItem(double pPrice, ItemPriceInfo pPriceQuote, CommerceItem pItem,
                           RepositoryItem pPricingModel, Locale pLocale,
                           RepositoryItem pProfile, Map pExtraParameters)
    throws PricingException{
      double totalPrice = NumberUtils.multiply(pPrice, pItem.getQuantityDerivedAsFloatingPoint()).doubleValue();
      pPriceQuote.setAmount(totalPrice);
  }
}

2. Create a new component ItemWholeSalePriceCalculator similar to ItemListPriceCalculator component to handle above class.
$class=atg.commerce.pricing.ItemWholeSalePriceCalculator

loggingIdentifier=ItemWholeSalePriceCalculator
pricePropertyName=wholeSalePrice
requirePriceValue=false
priceFromCatalogRef=true

pricingTools=/atg/commerce/pricing/PricingTools


3. Override the values of ItemPricingEngine component to add the new calculator ItemWholeSalePriceCalculator.

/atg/commerce/pricing/ItemPricingEngine.properties
preCalculators+=\
calculators/ItemWholeSalePriceCalculator


No comments:

Post a Comment