| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectatg.nucleus.logging.VariableArgumentApplicationLoggingImpl
atg.nucleus.GenericService
atg.commerce.pricing.DiscountCalculatorService
atg.commerce.pricing.ItemDiscountCalculator
public class ItemDiscountCalculator
Calculates the new price for an item or items based on a given pricing model. The pricing model must be a RepositoryItem of type item-discount (that is, it must be a RepositoryItem with all the same properties as the DCS item-discount item descriptor).
  The calculator has two methods of operation: 
  1. If the extra parameters map contains pre-qualified items and a discount structure then 
  the calculator will just apply the discount to those items. QualifiedItem objects should be stored
  in a Collection with the map key Constants.QUALIFIED_ITEMS. The DiscountStructure object should
  be stored with the map key Constants.DISCOUNT_STRUCTURE. 
  2. The calculator will inspect the pricing model repository item that it is given and, based
  on the discountType and adjuster properties,
  applies the discount to the price in the ItemPriceInfo corresponding to each
  CommerceItem that's passed in.  It does this by consulting the Qualifier service
  for a list of items which should receive the input discount.  It calls
  Qualifier.findQualifyingItems to do this.
  
The ItemDiscountCalculator inherits properties from DiscountCalculatorService.
Qualifier, 
DiscountCalculatorService| Field Summary | |
|---|---|
| static java.lang.String | CLASS_VERSIONClass version string | 
| static java.lang.String | EXTRA_PARAM_QUALIFIERSERVICEThe name used for specifying a qualifier service through the extra parameters map passed into the pricing operation. | 
| 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 | |
|---|---|
| ItemDiscountCalculator() | |
| Method Summary | |
|---|---|
| protected  long | determineDiscountNumber(DetailedItemPriceInfo pDetailedItemPriceInfo,
                        QualifiedItem pQualifiedItem,
                        RepositoryItem pPricingModel)determines the quantity to be discounted in the given detailed item price info | 
|  void | doStartService()Checks to see if property qualifierServiceis set | 
|  double | findAdjustedPrice(DetailedItemPriceInfo pDetailedItemPriceInfo,
                  java.util.List pPriceQuotes,
                  java.util.List pItems,
                  RepositoryItem pPricingModel,
                  RepositoryItem pProfile,
                  java.util.Locale pLocale,
                  Order pOrder,
                  java.util.Map pExtraParameters)Calls the DiscountCalculatorService's adjust method to determine the new price for the input pDetailedItemPriceInfo. | 
| protected  java.util.Collection | findQualifyingItems(java.util.List pPriceQuotes,
                    java.util.List pItems,
                    RepositoryItem pPricingModel,
                    RepositoryItem pProfile,
                    java.util.Locale pLocale,
                    Order pOrder,
                    java.util.Map pExtraParameters)Produces a collection of QualifiedItem objects, each of which contains a CommerceItem and a map of detailed item price info to the ranges to be discounted. | 
| protected  double | getAmountToDiscount(DetailedItemPriceInfo pDetailedItemPriceInfo,
                    java.util.List pPriceQuotes,
                    java.util.List pItems,
                    RepositoryItem pPricingModel,
                    RepositoryItem pProfile,
                    java.util.Locale pLocale,
                    Order pOrder,
                    java.util.Map pExtraParameters)This will return the amount that will eventually be discounted. | 
|  PricingTools | getPricingTools()pricing tools to help with price generation | 
|  atg.core.util.RangeComparator | getRangeComparator()The object that is used to compare ranges | 
| protected  DetailedItemPriceInfo | priceDetailedItemPriceInfo(DetailedItemPriceInfo pDetailedItemPriceInfo,
                           QualifiedItem pQualifiedItem,
                           java.util.List pPriceQuotes,
                           java.util.List pItems,
                           RepositoryItem pPricingModel,
                           RepositoryItem pProfile,
                           java.util.Locale pLocale,
                           Order pOrder,
                           java.util.Map pExtraParameters)Deprecated. This method is deprecated. Call updateDetailedItemPriceInfos instead. | 
|  void | priceEachItem(java.util.List pPriceQuotes,
              java.util.List pItems,
              RepositoryItem pPricingModel,
              java.util.Locale pLocale,
              RepositoryItem pProfile,
              java.util.Map pExtraParameters)give each item the configured discount, if it qualifies | 
|  void | priceItem(ItemPriceInfo pPriceQuote,
          CommerceItem pItem,
          RepositoryItem pPricingModel,
          java.util.Locale pLocale,
          RepositoryItem pProfile,
          java.util.Map pExtraParameters)give a single item the configured discount, if it is eligible. | 
|  void | priceItems(java.util.List pPriceQuotes,
           java.util.List pItems,
           RepositoryItem pPricingModel,
           java.util.Locale pLocale,
           RepositoryItem pProfile,
           Order pOrder,
           java.util.Map pExtraParameters)Price a List of items together in a context when it comes right down to it, we're only discounting single items : the only reason we need to price items in a context is to allow complex qualification statements. | 
| protected  void | priceQualifyingItem(QualifiedItem pQualifiedItem,
                    java.util.List pPriceQuotes,
                    java.util.List pItems,
                    RepositoryItem pPricingModel,
                    RepositoryItem pProfile,
                    java.util.Locale pLocale,
                    Order pOrder,
                    java.util.Map pExtraParameters)Determines and sets the amount of the ItemPriceInfo in pPriceQuotes at the index corresponding to the CommerceItem in pItems that is contained in pQualifiedItem. | 
| protected  void | priceQualifyingItems(java.util.Collection pQualifyingItems,
                     java.util.List pPriceQuotes,
                     java.util.List pItems,
                     RepositoryItem pPricingModel,
                     RepositoryItem pProfile,
                     java.util.Locale pLocale,
                     Order pOrder,
                     java.util.Map pExtraParameters)Loops through each QualifiedItem object in pQualifyingItems, determining and setting the price for each QualifiedItem's CommerceItem'sItemPriceInfo. | 
|  void | setPricingTools(PricingTools pPricingTools)pricing tools to help with price generation | 
|  void | setRangeComparator(atg.core.util.RangeComparator pRangeComparator) | 
| protected  java.util.List | updateDetailedPriceInfos(DetailedItemPriceInfo pDetailedItemPriceInfo,
                         QualifiedItem pQualifiedItem,
                         java.util.List pPriceQuotes,
                         java.util.List pItems,
                         RepositoryItem pPricingModel,
                         RepositoryItem pProfile,
                         java.util.Locale pLocale,
                         Order pOrder,
                         java.util.Map pExtraParameters)Maintains the Amount, Adjustments, and HasBeenDiscounted properties of pDetailedItemPriceInfo | 
| protected  void | updateQualifyingDetails(QualifiedItem pQualifiedItem,
                        ItemPriceInfo pPriceQuote)This method allows a QualifiedItem qualifyingDetailsMap to be updated. | 
| protected  void | updateQuantityAsQualifier(FilteredCommerceItem pFilteredCommerceItem,
                          java.util.List<DetailedItemPriceInfo> pDetails,
                          java.util.List<atg.core.util.Range> pQuantityAsQualifierRanges)After a partial adjustment a detail may have been split into multiple details. | 
| protected  boolean | validateQualifierService()Determines if the qualifier service is valid. | 
| 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.logging.VariableArgumentApplicationLoggingImpl | 
|---|
| vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, 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 | 
|---|
public static final java.lang.String CLASS_VERSION
public static final java.lang.String EXTRA_PARAM_QUALIFIERSERVICE
| Constructor Detail | 
|---|
public ItemDiscountCalculator()
| Method Detail | 
|---|
public void setPricingTools(PricingTools pPricingTools)
pPricingTools - new value to setpublic PricingTools getPricingTools()
public void setRangeComparator(atg.core.util.RangeComparator pRangeComparator)
public atg.core.util.RangeComparator getRangeComparator()
public void priceItem(ItemPriceInfo pPriceQuote,
                      CommerceItem pItem,
                      RepositoryItem pPricingModel,
                      java.util.Locale pLocale,
                      RepositoryItem pProfile,
                      java.util.Map pExtraParameters)
               throws PricingException
priceItem in interface ItemPricingCalculatorpPriceQuote - ItemPriceInfo representing the current price quote for the itempItem - The item to pricepPricingModel - A RepositoryItem representing a PricingModelpLocale - the locale for this pricingpProfile - The user's profilepExtraParameters - A Map of extra parameters to be used in the pricing, may be null
PricingException - if there was a problem in determining an item's price
public void priceEachItem(java.util.List pPriceQuotes,
                          java.util.List pItems,
                          RepositoryItem pPricingModel,
                          java.util.Locale pLocale,
                          RepositoryItem pProfile,
                          java.util.Map pExtraParameters)
                   throws PricingException
priceEachItem in interface ItemPricingCalculatorpPriceQuotes - List of ItemPriceInfo objects representing the current price quotes for each itempItems - The items to price (individually)pPricingModel - A RepositoryItem representing a PricingModelpLocale - the locale for this pricingpProfile - The user's profilepExtraParameters - A Map of extra parameters to be used in the pricing, may be null
PricingException - if there was a problem in determining an item's price
public void priceItems(java.util.List pPriceQuotes,
                       java.util.List pItems,
                       RepositoryItem pPricingModel,
                       java.util.Locale pLocale,
                       RepositoryItem pProfile,
                       Order pOrder,
                       java.util.Map pExtraParameters)
                throws PricingException
priceItems in interface ItemPricingCalculatorpPriceQuotes - List of ItemPriceInfo objects representing the current price quotes for the itemspItems - The items to pricepPricingModel - A RepositoryItem representing a PricingModelpProfile - The user's profilepLocale - the locale for this pricingpOrder - The Order object of which the List of items are a part, may be nullpExtraParameters - A Map of extra parameters to be used in the pricing, may be null
PricingException - if there was a problem in determining an item's priceprotected boolean validateQualifierService()
public void doStartService()
                    throws ServiceException
qualifierService is set
doStartService in class GenericServiceServiceException - if there was a problem initializing this service
protected java.util.Collection findQualifyingItems(java.util.List pPriceQuotes,
                                                   java.util.List pItems,
                                                   RepositoryItem pPricingModel,
                                                   RepositoryItem pProfile,
                                                   java.util.Locale pLocale,
                                                   Order pOrder,
                                                   java.util.Map pExtraParameters)
                                            throws PricingException
Note: in the lists pPriceQuotes and pItems, there is a 1:1 correspondence between ItemPriceInfos and items. That is to say, element 1 of pPriceQuotes is the ItemPriceInfo for the item at element 1 of pItems, and so on.
Side Effects:
In each ItemPriceInfo for each qualifying item, if its corresponding item acted as a qualifier in determining the qualifying items, the appropriate quantity is marked as having acted as a qualifier. This marking takes place only if the ItemPriceInfo is an instance of ItemPriceInfo.
pPriceQuotes - the input list of item pricespItems - the total set of items from which qualifying items will be selectedpPricingModel - the discount which defines which items qualifypProfile - the user for whom this calculation is being performedpLocale - the locale in which this calculation is being performedpOrder - the order in which the qualifying items residepExtraParameters - any extra information that this calculator might need to determine
        which items qualify for a discount.
PricingException - if anything went wrong while determining the QualifiedItemsPriceItems
protected void priceQualifyingItems(java.util.Collection pQualifyingItems,
                                    java.util.List pPriceQuotes,
                                    java.util.List pItems,
                                    RepositoryItem pPricingModel,
                                    RepositoryItem pProfile,
                                    java.util.Locale pLocale,
                                    Order pOrder,
                                    java.util.Map pExtraParameters)
                             throws PricingException
Note: the Collection of QualifiedItem's (and the DiscountStructure if available) is stored in the extra parameters map so that they can be accessed within the getAdjuster method since this is needed by some extensions of this calculator, e.g. BulkItemDiscountCalculator. The qualified items are stored with the key Constants.QUALIFIED_ITEMS and the discount structure is stored with the key Constants.DISCOUNT_STRUCTURE.
Side Effects: Each ItemPriceInfo in pPriceQuotes that is at the same index as that at which the CommerceItem in pItems that is the QualifiedItem's CommerceItem resides has its price set to the proper price.
pQualifyingItems - a collection of QualifiedItem objects that contains information about
        which and how many items should be discounted.pPriceQuotes - the price objects corresponding to pItemspItems - the items whose prices are contained in pPriceQuotespPricingModel - the discount which states how the qualifying items should be pricedpProfile - the person for whom the items are to be discountedpLocale - the locale in which the items are to be discountedpOrder - the order in which the discounted items have been placedpExtraParameters - any extra information that this method might need to set the
        prices of a number of qualifying items
PricingException - if anything went wrong while pricing the QualifiedItemsPriceItems
protected void priceQualifyingItem(QualifiedItem pQualifiedItem,
                                   java.util.List pPriceQuotes,
                                   java.util.List pItems,
                                   RepositoryItem pPricingModel,
                                   RepositoryItem pProfile,
                                   java.util.Locale pLocale,
                                   Order pOrder,
                                   java.util.Map pExtraParameters)
                            throws PricingException
Side Effects:
The default implementation of this method assumes that the ItemPriceInfo whose Amount this method is maintaining has a detailedCurrentPrice property which represents a breakdown of the price into smaller quantities. These DetailedItemPriceInfo objects have their amounts maintained as well, through calls to priceDetailedItemPriceInfo. The ItemPriceInfo has its Amount, Adjustments, and QuantityDiscounted properties maintained.
pQualifiedItem - the object stating which item, and how many of that item, qualified
        for the discount defined by pPricingModel.  It is expected that each QualifiedItem
        is a FilteredCommerceItempPriceQuotes - the price objects corresponding to pItemspItems - the items whose prices are contained in pPriceQuotespPricingModel - the discount which states how the qualifying items should be pricedpProfile - the person for whom the items are to be discountedpLocale - the locale in which the items are to be discountedpOrder - the order in which the discounted items have been placedpExtraParameters - any extra information that this method might need to set the
        prices of a number of the qualifying item
PricingException - if anything went wrong while pricing the QualifiedItemPriceItems
protected DetailedItemPriceInfo priceDetailedItemPriceInfo(DetailedItemPriceInfo pDetailedItemPriceInfo,
                                                           QualifiedItem pQualifiedItem,
                                                           java.util.List pPriceQuotes,
                                                           java.util.List pItems,
                                                           RepositoryItem pPricingModel,
                                                           RepositoryItem pProfile,
                                                           java.util.Locale pLocale,
                                                           Order pOrder,
                                                           java.util.Map pExtraParameters)
                                                    throws PricingException
PricingException#updateDetailedItemPriceInfos
protected java.util.List updateDetailedPriceInfos(DetailedItemPriceInfo pDetailedItemPriceInfo,
                                                  QualifiedItem pQualifiedItem,
                                                  java.util.List pPriceQuotes,
                                                  java.util.List pItems,
                                                  RepositoryItem pPricingModel,
                                                  RepositoryItem pProfile,
                                                  java.util.Locale pLocale,
                                                  Order pOrder,
                                                  java.util.Map pExtraParameters)
                                           throws PricingException
Side Effects:
Each DetailedItemPriceInfo has its Amount, Adjustments, and HasBeenDiscounted properties maintained.
pDetailedItemPriceInfo - the price object which should receive the discount specified
        by pPricingModelpQualifiedItem - the object stating which item, and how many of that item, qualified
        for the discount defined by pPricingModel.  It is expected that each QualifiedItem
        is a FilteredCommerceItempPriceQuotes - the price objects corresponding to pItemspItems - the items whose prices are contained in pPriceQuotespPricingModel - the discount which states how the qualifying items should be pricedpProfile - the person for whom the items are to be discountedpLocale - the locale in which the items are to be discountedpOrder - the order in which the discounted items have been placedpExtraParameters - any extra information that this method might need to set the
        prices of a number of the qualifying item
PricingException - if anything went wrong while pricing the
  DetailedItemPriceInfopriceItems, 
priceQualfyingItem
protected long determineDiscountNumber(DetailedItemPriceInfo pDetailedItemPriceInfo,
                                       QualifiedItem pQualifiedItem,
                                       RepositoryItem pPricingModel)
                                throws PricingException
pDetailedItemPriceInfo - pQualifiedItem - pPricingModel - 
PricingException
protected void updateQuantityAsQualifier(FilteredCommerceItem pFilteredCommerceItem,
                                         java.util.List<DetailedItemPriceInfo> pDetails,
                                         java.util.List<atg.core.util.Range> pQuantityAsQualifierRanges)
                                  throws PricingException
pFilteredCommerceItem - FilteredCommerceItem to updatepDetails - List of DetailedItemPriceInfo after the split, includes the original detail too.pQuantityAsQualifierRanges - List of Range of the original detail quantity as qualifiers.
PricingException - for errors.
public double findAdjustedPrice(DetailedItemPriceInfo pDetailedItemPriceInfo,
                                java.util.List pPriceQuotes,
                                java.util.List pItems,
                                RepositoryItem pPricingModel,
                                RepositoryItem pProfile,
                                java.util.Locale pLocale,
                                Order pOrder,
                                java.util.Map pExtraParameters)
                         throws PricingException
pDetailedItemPriceInfo - the price object whose price is to be modifiedpPriceQuotes - the price objects corresponding to pItemspItems - the items whose prices are contained in pPriceQuotespPricingModel - the discount which states how the qualifying items should be pricedpProfile - the person for whom the items are to be discountedpLocale - the locale in which the items are to be discountedpOrder - the order in which the discounted items have been placedpExtraParameters - any extra information that this method might need to set the
        prices of a number of the qualifying item
PricingException - if there was a problem in determining the adjusted price
protected double getAmountToDiscount(DetailedItemPriceInfo pDetailedItemPriceInfo,
                                     java.util.List pPriceQuotes,
                                     java.util.List pItems,
                                     RepositoryItem pPricingModel,
                                     RepositoryItem pProfile,
                                     java.util.Locale pLocale,
                                     Order pOrder,
                                     java.util.Map pExtraParameters)
                              throws PricingException
pOrder - The order containing the shipping grouppPriceQuote - ShippingPriceInfo representing the current price quote for the shipping grouppShippingGroup - The shipping group 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)
PricingException
protected void updateQualifyingDetails(QualifiedItem pQualifiedItem,
                                       ItemPriceInfo pPriceQuote)
                                throws PricingException
For example it is possible for multiple discounts in a single promotion that a previous discount could have split some detailed item price info. However the QualifiedItem was created before this split took place and so some qualifying ranges may still be pointing to the original unsplit detailed item price info. So we need to fix any such references to point to the correct dipi. This implementation will update the QualifiedItem's qualifyingDetailsMap to ensure the latest detailed item price info references are used.
pQualifiedItem - the QualifiedItem to check and fix if neededpPriceQuote - the item price info
PricingException - if the qualifying ranges can't be updated| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||