The atg.commerce.pricing.PricingTools
class performs a variety of pricing functions for different types of pricing engines. It also has a number of static, currency-related methods for use by all pricing engines.
The PricingTools
class is the main way that business-layer logic interacts with the pricing engines and the other classes in the atg.commerce.pricing
package. In ATG Commerce, the classes that extend the ItemPricingDroplet
class (PriceItemDroplet
and PriceEachItemDroplet
) use PricingTools
to interface with all the ATG Commerce pricing engines.
When a store using ATG Commerce needs a price for items, orders, shipping, or tax, PricingTools
can be consulted to return the price. In addition, PricingTools
contains translation functions that identify which currencyCode
goes with which locale.
The properties of PricingTools
are as follows:
itemPricingEngine
: The pricing engine that calculates prices for items, both individually and in groups. An item is identified as a set quantity of a SKU or product.orderPricingEngine
: The pricing engine that calculates prices for orders. Typically, the price is just the sum of the prices of the items in the order. However, the order might be discounted separately from the constituent items.shippingPricingEngine
: The pricing engine that calculates prices for shipping groups. An order contains one or more shipping groups when the contents of the order require shipping for delivery. An order has no shipping groups when it is delivered online, and shipping is therefore not calculated for this type of order.taxPricingEngine
: The pricing engine that calculates tax for orders. Tax is calculated on the order total.roundingDecimalPlaces
: Specifies the number of decimal places to which the an input price is rounded . This property is used by theround
,roundDown
andneedsRounding
methods (see below).
PricingTools
includes methods that can be called to produce prices. These methods consult the configured pricing engines.
void priceEachItem(List pCommerceItems, Collection pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Prices each item as if it were in the order all by itself. This method calls through to the
priceEachItem
call ofItemPricingEngine
, and sets each item’spriceInfo
property to be the proper price result.void priceItem(CommerceItem pCommerceItem, Collection pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Prices the item outside the context of an order, and with no other items present. This method calls through to the
priceEachItem
call of theItemPricingEngine
. It sets each item’spriceInfo
property to be the proper price result.double priceItemsForOrderTotal(Order pOrder, Collection pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Returns the double value of the total price for all items in the order. This price can then be used as the price for the order containing all these items.
double priceOrderForOrderTotal(Order pOrder, Collection pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Returns the double value of the sum of the prices for all of the items in the order, additionally taking any order level discounts into account.
OrderPriceInfo priceOrderTotal(Order pOrder, Collection pItemPricingModels, Collection pShippingPricingModels, Collection pOrderPricingModels, Collection, pTaxPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Returns the
AmountInfo
object representing the order’s price, which is the sum total of prices of the constituent items, as well as any item or order level discounts. TheAmountInfo
returned also maintains an audit trail of the adjustments made to the price by each order-level promotion. In addition, the shipping costs for the order are computed, taking into account any shipping promotions. Lastly, the tax for the order is computed. All input promotions are factored into the price, in addition to the promotions derived from the input profile.OrderPriceInfo priceOrderTotal(Order pOrder, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Computes item prices, order total, order tax, and shipping costs for the input order. Unlike in the above method, the only discounts this method takes into account are those derived from the input profile.
OrderPriceInfo priceOrderTotal(Order pOrder, PricingModelHolder pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Computes tax, shipping, item, and order prices for the input order. Uses the promotions already stored in the
pricingModelHolder
as factors in the prices.double priceShippingForOrderTotal(Order pOrder, Collection pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Computes a shipping amount in the form of a double. Takes into account the shipping promotions passed in by
pPricingModels
.double priceTaxForOrderTotal(Order pOrder, Collection pPricingModels, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters)
Computes a tax amount in the form of a double. Takes into account the tax promotions passed in through
pPricingModels
.boolean needsRounding(double pNumber)
Determines whether the input
number
needs to be rounded based on the value of theroundingDecimalPlaces
property. If the input number has more decimal places than N, where N is the value ofroundingDecimalPlaces
, the input number needs to be rounded.double round(double pNumber)
Rounds the input
number
to the number of decimal places specified by theroundingDecimalPlaces
property. This method rounds numbers 1 through 4 down and 5 through 9 up. It is important to always round if you are making a pricing adjustment. All of the existing pricing components round. If you create one that does not, there may be comparison errors.double roundDown(double pNumber)
Rounds the input
number
to the number of decimal places specified by theroundingDecimalPlaces
property. Rounds all numbers beyond the specified number of decimal places to zero.
PricingTools
also has some currency and locale properties and methods:
getPricingLocale
: method that determines the locale to use for pricing, first by checking the user’s price list, then falling back on thedefaultLocale
.usePassedLocaleAsPricingLocale
: iftrue
, use the locale passed togetPricingLocale
rather than determining a locale from the price list. The default isfalse
.useDefaultLocaleIfNotSpecified
: Iftrue
, and if the locale passed into thepriceTotalOrder
method is null, use thedefaultLocale
value. Iffalse
, useServletUtil.getUserLocale
to determine the locale.defaultLocale
: the locale passed in to all of the pricing engines if no other locale is passed intoPricingTools
.getCurrencySymbol
andgetInternationalCurrencySymbol
: helper methods for code that calls intoPricingTools
. The caller can use this method to quickly get the symbol with which the price thatPricingTools
returns should be displayed.