atg.commerce.pricing
Class OrderDiscountCalculator

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.pricing.DiscountCalculatorService
              extended by atg.commerce.pricing.OrderDiscountCalculator
All Implemented Interfaces:
OrderPricingCalculator, NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
BulkOrderDiscountCalculator

public class OrderDiscountCalculator
extends DiscountCalculatorService
implements OrderPricingCalculator

Calculates OrderPriceInfos for Orders which the calculator is given. This calculator can either be passed in a MatchingObject via the extra parameters map with key Constants.MATCHING_OBJECT containing the order that qualified for the promotion or it can consult the Qualifier service, looking for the Order to be priced. It calls Qualifier.findQualifyingOrder for this purpose.

If it obtains an Order that qualified then it can determine the discount either via a DiscountStructure object being passed into the calculator via the extra parameters map with key Constants.DISCOUNT_STRUCTURE or by getting the discountType and adjuster properties of the input PricingModel (RepositoryItem).

See Also:
Qualifier

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.commerce.pricing.DiscountCalculatorService
AMOUNT_INCREASE_TYPE, AMOUNT_OFF_TYPE, FIXED_PRICE_TYPE, ILLEGAL_TYPE, mPromotionTools, PERCENT_OFF_TYPE
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
OrderDiscountCalculator()
           
 
Method Summary
protected  double adjustOrderSubTotal(double pOrderSubTotal, double pAdjuster, java.lang.String pDiscountType, java.lang.String pOrderId, RepositoryItem pPricingModel, java.util.Map pExtraParameters)
          Applies the given adjuster to the given order subtotal.
protected  double computeGroupSubtotal(long pTimesToDiscount, int pNumberOfGroups, double pGroupSubTotal, double pAdjuster, java.lang.String pDiscountType, java.lang.String pId)
          Computes a shippinggroup subtotal based on the type of discount given.
protected  double computeGroupSubtotal(long pTimesToDiscount, int pNumberOfGroups, double pGroupSubTotal, double pAdjuster, java.lang.String pDiscountType, java.lang.String pOrderId, double pOldOrderAmount)
          Deprecated.  
protected  double computeGroupSubtotal(long pTimesToDiscount, int pNumberOfGroups, double pGroupSubTotal, double pAdjuster, java.lang.String pDiscountType, java.lang.String pOrderId, double pOldOrderAmount, double pNewOrderAmount, RepositoryItem pPricingModel, java.util.Map pExtraParameters)
          Computes a shippinggroup subtotal based on the type of discount given.
 void doStartService()
          This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values.
protected  MatchingObject findMatchingObject(OrderPriceInfo pPriceQuote, java.util.List pPriceQuotes, java.util.List pItems, RepositoryItem pPricingModel, RepositoryItem pProfile, java.util.Locale pLocale, Order pOrder, java.util.Map pExtraParameters)
          This method determines if the order qualifies for the given order promotion.
protected  double getAmountToDiscount(OrderPriceInfo pPriceQuote, Order pOrder, RepositoryItem pPricingModel, java.util.Locale pLocale, RepositoryItem pProfile, java.util.Map pExtraParameters)
          This will return the amount that will eventually be discounted.
protected  java.util.List getDetailsToReceiveDiscountShare(ItemPriceInfo pItemPriceInfo)
          This will return the price details in an item price info that will be marked as receiving a share of the order discount.
protected  java.util.List getItemsToReceiveDiscountShare(Order pOrder)
          This will return the items in an order that will be marked as receiving a share of the order discount.
protected  double getNonTaxableShippingGroupTotal(OrderPriceInfo pOrderPriceInfo)
          Returns the total of the NonTaxableShippingItemsSubtotalPriceInfos in the given OrderPriceInfo
 PricingTools getPricingTools()
          pricing tools to help with calculating prices
protected  double getTaxableShippingGroupTotal(OrderPriceInfo pOrderPriceInfo)
          Returns the total of the TaxableShippingItemsSubtotalPriceInfos in the given OrderPriceInfo
protected  double getTotalForShippingGroups(java.util.Map pOrderPriceInfos)
          Returns the total of the OrderPriceInfos in the map
 boolean isSaveDetailsOrderDiscountShare()
          If this is true, update itemPriceInfo.orderDiscountShare
 boolean isSaveItemsOrderDiscountShare()
          If this is true, update itemPriceInfo.orderDiscountShare
 void priceOrder(OrderPriceInfo pPriceQuote, Order pOrder, RepositoryItem pPricingModel, java.util.Locale pLocale, RepositoryItem pProfile, java.util.Map pExtraParameters)
          Price a single order within a context defined by the input parameters.
 void setPricingTools(PricingTools pPricingTools)
          pricing tools to help with calculating prices
 void setSaveDetailsOrderDiscountShare(boolean pSaveDetailsOrderDiscountShare)
           
 void setSaveItemsOrderDiscountShare(boolean pSaveItemsOrderDiscountShare)
           
protected  void updateItemsDiscountShare(Order pOrder, double pUnadjustedPrice, double pTotalAdjustment, double pAdjuster, java.lang.String pDiscountType, long pTimesToDiscount)
          This method will set the orderDiscountShare property of each CommerceItem's priceInfo.
protected  double updateShippingItemsSubtotalMaps(double pOrderSubTotal, double pOldOrderAmount, MatchingObject pQualifier, double pAdjuster, java.lang.String pDiscountType, OrderPriceInfo pPriceQuote, Order pOrder, RepositoryItem pPricingModel, java.util.Map pExtraParameters)
          These method will iterate through each of the maps in the OrderPriceInfo that contain shipping group subtotal information.
 
Methods inherited from class atg.commerce.pricing.DiscountCalculatorService
adjust, adjustAmount, getAdjuster, getDiscountType, getDiscountType, getPricingModelProperties, getPromotionTools, getQualifierService, getQualifierService, isNegativeAmountException, setNegativeAmountException, setPricingModelProperties, setPromotionTools, setQualifierService
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

OrderDiscountCalculator

public OrderDiscountCalculator()
Method Detail

setPricingTools

public void setPricingTools(PricingTools pPricingTools)
pricing tools to help with calculating prices

Parameters:
pPricingTools - new value to set

getPricingTools

public PricingTools getPricingTools()
pricing tools to help with calculating prices

Returns:
property PricingTools

setSaveItemsOrderDiscountShare

public void setSaveItemsOrderDiscountShare(boolean pSaveItemsOrderDiscountShare)

isSaveItemsOrderDiscountShare

public boolean isSaveItemsOrderDiscountShare()
If this is true, update itemPriceInfo.orderDiscountShare


setSaveDetailsOrderDiscountShare

public void setSaveDetailsOrderDiscountShare(boolean pSaveDetailsOrderDiscountShare)

isSaveDetailsOrderDiscountShare

public boolean isSaveDetailsOrderDiscountShare()
If this is true, update itemPriceInfo.orderDiscountShare


priceOrder

public void priceOrder(OrderPriceInfo pPriceQuote,
                       Order pOrder,
                       RepositoryItem pPricingModel,
                       java.util.Locale pLocale,
                       RepositoryItem pProfile,
                       java.util.Map pExtraParameters)
                throws PricingException
Price a single order within a context defined by the input parameters. The order's price is adjusted as well as the shipping group subtotals.

The order can be passed in within a MatchingObject via the pExtraParameters map with key Constants.MATCHING_OBJECT. If this is not the case then it will call findMatchingObject to try and obtain the MatchingObject from the qualifier service.

Specified by:
priceOrder in interface OrderPricingCalculator
Parameters:
pPriceQuote - OrderPriceInfo representing the current price quote for the order
pOrder - The order to price
pPricingModel - A RepositoryItems representing a PricingModel
pProfile - The user's profile
pExtraParameters - A Map of extra parameters to be used in the pricing, may be null
Throws:
PricingException
See Also:
updateShippingItemsSubtotalMaps(double, double, atg.commerce.pricing.definition.MatchingObject, double, java.lang.String, atg.commerce.pricing.OrderPriceInfo, atg.commerce.order.Order, atg.repository.RepositoryItem, java.util.Map)

computeGroupSubtotal

protected double computeGroupSubtotal(long pTimesToDiscount,
                                      int pNumberOfGroups,
                                      double pGroupSubTotal,
                                      double pAdjuster,
                                      java.lang.String pDiscountType,
                                      java.lang.String pOrderId,
                                      double pOldOrderAmount,
                                      double pNewOrderAmount,
                                      RepositoryItem pPricingModel,
                                      java.util.Map pExtraParameters)
                               throws PricingException
Computes a shippinggroup subtotal based on the type of discount given. The logic is as follows:

If functionality other than that described above, this method can be overridden to do that which is necessary. For example, rather than spreading out amount off discounts across all shippingGroups, some implementations might want the first ShippingGroup to get the full benefit of the discount.

Parameters:
pTimesToDiscount - the number of times we should apply the configured discount
pNumberOfGroups - the number of groups in the order, including the one for which this method is computing a subtotal
pGroupSubTotal - is the subtotal that needs adjusting
pAdjuster - is the amount by which to adjust pGroupSubTotal
pDiscountType - the way in which pAdjuster is applied to pGroupSubTotal. May be one of: "Fixed Price", "Amount Off", or "Percent Off".
pOrderId - an ID to associate with this adjustment for error reporting
pOldOrderAmount - the order subtotal before this discount was applied at the order level
pNewOrderAmount - the order subtotal after this discount was applied at the order level
pPricingModel - the order promotion that's being applied
pExtraParameters - the extra parameter map originally passed into the pricing operation.
Returns:
the adjusted subtotal for the input pGroupSubTotal
Throws:
PricingException - if there was a problem computing the group subtotal

adjustOrderSubTotal

protected double adjustOrderSubTotal(double pOrderSubTotal,
                                     double pAdjuster,
                                     java.lang.String pDiscountType,
                                     java.lang.String pOrderId,
                                     RepositoryItem pPricingModel,
                                     java.util.Map pExtraParameters)
                              throws PricingException
Applies the given adjuster to the given order subtotal.

Parameters:
pOrderSubTotal - the order's current subtotal
pAdjuster - the pricing model's adjuster
pDiscountType - the pricing models discount type
pOrderId - the id of the order to which the adjustment is beig made
pPricingModel - the order promotion repository item
pExtraParameters - the original extra parameter map passed to the pricing operation.
Returns:
the new, calculated order subtotal.
Throws:
PricingException
See Also:
DiscountCalculatorService.adjust(double, double, String, String)

findMatchingObject

protected MatchingObject findMatchingObject(OrderPriceInfo pPriceQuote,
                                            java.util.List pPriceQuotes,
                                            java.util.List pItems,
                                            RepositoryItem pPricingModel,
                                            RepositoryItem pProfile,
                                            java.util.Locale pLocale,
                                            Order pOrder,
                                            java.util.Map pExtraParameters)
                                     throws PricingException
This method determines if the order qualifies for the given order promotion.

It determines this by calling the QualifierService

Parameters:
pPriceQuote -
pPriceQuotes -
pItems -
pPricingModel -
pProfile -
pLocale -
pOrder -
pExtraParameters -
Returns:
Throws:
PricingException
See Also:
Qualifier.findQualifyingOrder(List, List, RepositoryItem, RepositoryItem, Locale, Order, OrderPriceInfo, ShippingGroup, ShippingPriceInfo, Map)

updateShippingItemsSubtotalMaps

protected double updateShippingItemsSubtotalMaps(double pOrderSubTotal,
                                                 double pOldOrderAmount,
                                                 MatchingObject pQualifier,
                                                 double pAdjuster,
                                                 java.lang.String pDiscountType,
                                                 OrderPriceInfo pPriceQuote,
                                                 Order pOrder,
                                                 RepositoryItem pPricingModel,
                                                 java.util.Map pExtraParameters)
                                          throws PricingException
These method will iterate through each of the maps in the OrderPriceInfo that contain shipping group subtotal information. These include: For each of entry in each of these maps, computeGroupSubtotal is called. The amount of the price info in the entry is set to this value, the info is marked discounted, and a new adjustement is added to the info

Parameters:
pOrderSubTotal - The new subtotal of the order
pOldOrderAmount - The previous subtotal of the order
pQualifier - The MatchingObject as returned by Qualifier.evaluateQualifier
pAdjuster - The adjuster of the promotion
pDiscountType - The type of discount being given
pPriceQuote - The order's price info
pOrder - The order that was discounted
pPricingModel - The promotion that changed the price of the order
pExtraParameters - Any extra parameters
Returns:
The new subtotal of the order. This is the sum of the shipping group subtotals and should match pOrderSubTotal
Throws:
PricingException

computeGroupSubtotal

protected double computeGroupSubtotal(long pTimesToDiscount,
                                      int pNumberOfGroups,
                                      double pGroupSubTotal,
                                      double pAdjuster,
                                      java.lang.String pDiscountType,
                                      java.lang.String pId)
                               throws PricingException
Computes a shippinggroup subtotal based on the type of discount given. The logic is as follows:

If functionality other than that described above, this method can be overridden to do that which is necessary. For example, rather than spreading out amount off discounts across all shippingGroups, some implementations might want the first ShippingGroup to get the full benefit of the discount.

Parameters:
pTimesToDiscount - the number of times we should apply the configured discount
pNumberOfGroups - the number of groups in the order, including the one for which this method is computing a subtotal
pGroupSubTotal - is the subtotal that needs adjusting
pAdjuster - is the amount by which to adjust pGroupSubTotal
pDiscountType - the way in which pAdjuster is applied to pGroupSubTotal. May be one of: "Fixed Price", "Amount Off", or "Percent Off".
pId - an ID to associate with this adjustment for error reporting
Returns:
the adjusted subtotal for the input pGroupSubTotal
Throws:
PricingException - if there was a problem computing the group subtotal

getTaxableShippingGroupTotal

protected double getTaxableShippingGroupTotal(OrderPriceInfo pOrderPriceInfo)
Returns the total of the TaxableShippingItemsSubtotalPriceInfos in the given OrderPriceInfo

Parameters:
pOrderPriceInfo -
Returns:
total

getNonTaxableShippingGroupTotal

protected double getNonTaxableShippingGroupTotal(OrderPriceInfo pOrderPriceInfo)
Returns the total of the NonTaxableShippingItemsSubtotalPriceInfos in the given OrderPriceInfo

Parameters:
pOrderPriceInfo -
Returns:
total

getTotalForShippingGroups

protected double getTotalForShippingGroups(java.util.Map pOrderPriceInfos)
Returns the total of the OrderPriceInfos in the map

Parameters:
pShippingGroupPriceInfos -
Returns:

computeGroupSubtotal

protected double computeGroupSubtotal(long pTimesToDiscount,
                                      int pNumberOfGroups,
                                      double pGroupSubTotal,
                                      double pAdjuster,
                                      java.lang.String pDiscountType,
                                      java.lang.String pOrderId,
                                      double pOldOrderAmount)
                               throws PricingException
Deprecated. 

Throws:
PricingException
See Also:
computeGroupSubtotal(long, int, double, double, String, String, double, double, RepositoryItem, Map)

updateItemsDiscountShare

protected void updateItemsDiscountShare(Order pOrder,
                                        double pUnadjustedPrice,
                                        double pTotalAdjustment,
                                        double pAdjuster,
                                        java.lang.String pDiscountType,
                                        long pTimesToDiscount)
                                 throws PricingException
This method will set the orderDiscountShare property of each CommerceItem's priceInfo. This happens if saveItemsOrderDiscountShare is true. If saveDetailsOrderDiscountShare is true, then the orderDiscountShare property of each DetailedItemPriceInfo is also updated.

Parameters:
pOrder - the order that was discounted
pUnadjustedPrice - The original pre-discount price of the order
pTotalAdjustment - This is the total change to the order total, for the current promotion
pAdjuster - The size of the discount
pDiscountType - the way in which pAdjuster is applied to pGroupSubTotal. May be one of: "Fixed Price", "Amount Off", or "Percent Off".
pTimesToDiscount - The number of times to apply the given discount
Throws:
PricingException

getAmountToDiscount

protected double getAmountToDiscount(OrderPriceInfo pPriceQuote,
                                     Order pOrder,
                                     RepositoryItem pPricingModel,
                                     java.util.Locale pLocale,
                                     RepositoryItem pProfile,
                                     java.util.Map pExtraParameters)
                              throws PricingException
This will return the amount that will eventually be discounted. This will be priceQuote.amount by default (and there will usually be no need to change this.)

Parameters:
pPriceQuote - OrderPriceInfo representing the current price quote for the order
pOrder - The order that will be discounted (ignored by default)
pPricingModel - A RepositoryItems representing a PricingModel (ignored by default)
pProfile - The user's profile (ignored by default)
pExtraParameters - A Map of extra parameters to be used in the pricing, may be null (ignored by default)
Returns:
The amount to discount... defaults to pPriceQuote.getAmount()
Throws:
PricingException

getDetailsToReceiveDiscountShare

protected java.util.List getDetailsToReceiveDiscountShare(ItemPriceInfo pItemPriceInfo)
This will return the price details in an item price info that will be marked as receiving a share of the order discount. This will be all price details with a non-zero amount.

Parameters:
pItemPriceInfo - The item price info
Returns:
The list of items to be marked for receiving a share of the order discount
See Also:
DetailedItemPriceTools.getDetailsToReceiveDiscountShare(ItemPriceInfo, Range)

getItemsToReceiveDiscountShare

protected java.util.List getItemsToReceiveDiscountShare(Order pOrder)
This will return the items in an order that will be marked as receiving a share of the order discount. This will be all items in the order with a non-zero price.

Parameters:
pOrder - The order that will be discounted
Returns:
The list of items to be marked for receiving a share of the order discount

doStartService

public void doStartService()
                    throws ServiceException
Description copied from class: GenericService
This is called after a Service has been created, placed into the naming hierarchy, and initialized with its configured property values. The Service should override this method to start any processes it requires.

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up