This section explains how to create a new implementation of a pricing calculator interface and how to use the new calculator.

Creating a New Pricing Calculator

Use the following interfaces to create a new pricing calculator that fits into the existing ATG Commerce pricing architecture:

Implement the interface that corresponds to the type of price you want to calculate. For example, if you want to make calculations on order prices, implement OrderPricingCalculator.

In the following example, assume you have identified a need for a calculator that sets an item’s price to half its current price plus one. The existing ATG Commerce tools include an ItemDiscountCalculator that discounts items. It can give a percent off a price or an amount off, or it can set an item’s price to a fixed amount. None of these three options, however, easily gives a “half off plus one” discount. To achieve that result, you would have to use two different discounts: one to give 50 percent off, and another to add 1 to that total. A better alternative would be to create a new calculator that discounts an item’s price to half its current price plus one.

To create the new calculator, you create a class called HalfPlusOneItemDiscountCalculator that implements the ItemPricingCalculator interface. The HalfPlusOneDiscountCalculator is an example of a discount calculator that leverages existing ATG Commerce functionality to perform its own unique task.

In addition to modifying an item’s price, the ATG Commerce item discount calculators also do the following:

The HalfPlusOneDiscountCalculator leverages all the above functionality from the ItemDiscountCalculator. The only method it overrides is the findAdjustedPrice method, which modifies an input DetailedItemPriceInfo to be the right amount. In this case, the class modifies the price of the detail to half its current price plus one. The overridden findAdjustedPrice method is shown below:

   * Override the findAdjustedPrice to allow us to always compute the
   * new price of the input DetailedItemPriceInfo to be half its current
   * price plus one.
   * @param pDetailedItemPriceInfo the details on the item being priced
   * @param pPriceQuotes list of itemPriceInfo
   * @param pItems list of commerceItems
   * @param pPricingModel pricing model being used to calculate price
   * @param pProfile users profile, not used here
   * @param pLocale users locale, not used here
   * @param pOrder users order, not used here
   * @param pExtraParameters map of extra params, not used here
   * @return a value of type 'double'
   * @exception PricingException if an error occurs
  public double findAdjustedPrice(DetailedItemPriceInfo pDetailedItemPriceInfo,
      List pPriceQuotes,
      List pItems,
      RepositoryItem pPricingModel,
      RepositoryItem pProfile,
      Locale pLocale,
      Order pOrder,
      Map pExtraParameters) throws PricingException {

      // current price of an item
      double currentAmount = pDetailedItemPriceInfo.getAmount();

      return ( currentAmount / 2) + 1;

  } // end findAdjustedPrice
Using a New Pricing Calculator

After you have created a new calculator, you must associate it with its corresponding pricing engine. You can do this in either of two ways:

loading table of contents...