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:
atg.commerce.pricing.ItemPricingCalculator
atg.commerce.pricing.OrderPricingCalculator
atg.commerce.pricing.ShippingPricingCalculator
atg.commerce.pricing.TaxPricingCalculator
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:
Consult the Qualifier class to determine the items to be discounted from among all the items in the environment.
Maintain an audit trail of the changes made to the price using the
PricingAdjustments
property in theAmountInfo
price object.Maintain flags on the items’ prices that state whether each item has acted as a qualifier for any discount (and therefore might not be usable as the qualifier for another discount).
Maintain
DetailedItemPriceInfo
objects.
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:
Add the calculator to an engine’s list of pre- or post-calculators. The configuration invokes the calculator on the price of every item that passes through the engine.
The pricing calculator can use a pricing model (a promotion) to alter an item’s price conditionally. You can set a pricing model’s
pricingCalculatorService
property to the Nucleus path of an instance of the new calculator. When the pricing model is passed to theItemPricingEngine
, the engine invokes the calculator and modifies the input item’s price. This option is appropriate for discount calculators.