public class ItemDiscountCalculator extends DiscountCalculatorService implements ItemPricingCalculator
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
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string
|
static java.lang.String |
EXTRA_PARAM_QUALIFIERSERVICE
The name used for specifying a qualifier service through the extra parameters map passed into
the pricing operation.
|
AMOUNT_INCREASE_TYPE, AMOUNT_OFF_TYPE, FIXED_PRICE_TYPE, ILLEGAL_TYPE, mPromotionTools, PERCENT_OFF_TYPE
SERVICE_INFO_KEY
DEFAULT_LOG_TRACE_STATUS
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
Constructor and Description |
---|
ItemDiscountCalculator() |
Modifier and Type | Method and Description |
---|---|
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
qualifierService is 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.
|
adjust, adjustAmount, adjustAmount, getAdjuster, getDiscountType, getDiscountType, getPricingModelProperties, getPromotionTools, getQualifierService, getQualifierService, isNegativeAmountException, setNegativeAmountException, setPricingModelProperties, setPromotionTools, setQualifierService
addLogListener, createAdminServlet, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, 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, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
public static final java.lang.String CLASS_VERSION
public static final java.lang.String EXTRA_PARAM_QUALIFIERSERVICE
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 ItemPricingCalculator
pPriceQuote
- 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 nullPricingException
- if there was a problem in determining an item's pricepublic 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 ItemPricingCalculator
pPriceQuotes
- 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 nullPricingException
- if there was a problem in determining an item's pricepublic 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 ItemPricingCalculator
pPriceQuotes
- 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 nullPricingException
- if there was a problem in determining an item's priceprotected boolean validateQualifierService()
public void doStartService() throws ServiceException
qualifierService
is setdoStartService
in class GenericService
ServiceException
- if there was a problem initializing this serviceprotected 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 itemsPricingException
- 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 itemPricingException
- 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 itemPricingException
- 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 itemPricingException
- if there was a problem in determining the adjusted priceprotected 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 infoPricingException
- if the qualifying ranges can't be updated