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, atg.nucleus.logging.VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class OrderDiscountCalculator
extends DiscountCalculatorService
implements OrderPricingCalculator

Calculates OrderPriceInfos for Orders which the calculator is given. This calculator consults the Qualifer service, looking for the Order to be priced. It calls Qualifier.findQualifyingOrder for this purpose. If it gets back an Order, an OrderPriceInfo is computed based on 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, 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 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)
          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  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.
 PricingTools getPricingTools()
          pricing tools to help with calculating prices
 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, getDiscountType, getPricingModelProperties, getQualifierService, isNegativeAmountException, setNegativeAmountException, setPricingModelProperties, 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, 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.

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)

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

computeGroupSubtotal

protected double computeGroupSubtotal(long pTimesToDiscount,
                                      int pNumberOfGroups,
                                      double pGroupSubTotal,
                                      double pAdjuster,
                                      java.lang.String pDiscountType,
                                      java.lang.String pOrderId,
                                      double pOldOrderAmount)
                               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

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:
pOrder - The order that will be discounted
Returns:
The list of items to be marked for receiving a share of the order discount

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