atg.commerce.promotion
Class GWPManager

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.promotion.GWPManager
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class GWPManager
extends GenericService

Provides API to manage Gift With Purchase promotions adding and removing gifts to the cart. Pricing invokes the processGWPInfos method at the end of item pricing. An application via a form handler may typically invoke the makeGiftSelection method for new or changed gift selections. These two methods update the order and so are synchronized on the order and wrapped in a transaction. If a caller wants to call any other method directly which updates the order then they need to do this wrapping themselves.

It is also assumed that the caller into these two methods will first have obtained a service lock on the order profile. Pricing and the GiftWithPurchaseFormHandler will do this.


Nested Class Summary
protected  class GWPManager.GWPPipelineErrorHandler
          Class to handle errors from the purchase process helper pipeline if needed.
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
protected  CatalogProperties mCatalogProperties
           
protected  CatalogTools mCatalogTools
           
protected  RqlStatement mCategoryQuery
           
protected  CommerceItemManager mCommerceItemManager
           
protected  atg.commerce.promotion.GWPMarkerManager mGwpMarkerManager
           
protected  boolean mJMSEnabled
           
protected  PricingTools mPricingTools
           
protected  RqlStatement mProductContentGroupQuery
           
protected  PromotionTools mPromotionTools
           
protected  PurchaseProcessHelper mPurchaseProcessHelper
           
protected  atg.repository.nucleus.RepositoryGroupContainerService mRepositoryGroupContainerService
           
protected  atg.multisite.SiteTools mSiteTools
           
protected  RqlStatement mSkuContentGroupQuery
           
protected  java.util.Map<java.lang.String,java.lang.String> mSkuToCommerceItemTypeMapping
           
protected static java.lang.String MY_RESOURCE_NAME
           
protected static java.util.ResourceBundle sResourceBundle
          Resource Bundle
 
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
GWPManager()
           
 
Method Summary
protected  CommerceItem addGiftQuantity(RepositoryItem pOrderMarker, java.lang.String pProductId, java.lang.String pSkuId, long pQuantityToAdd, java.lang.String pCatalogKey, ShippingGroup pShippingGroup, java.lang.String pCommerceItemType, java.lang.String pSiteId, java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos, java.util.List<CommerceItem> pNewItems, int pItemIndex, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Method to add GWP quantity to the order.
protected  boolean canRepriceItem(CommerceItem pItem)
          Check if this item can be re-priced to full price.
 boolean changeGiftQuantity(RepositoryItem pOrderMarker, long pQuantityDelta, java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos, java.util.List<CommerceItem> pNewItems, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Called if there has been a change in quantity of a free gift.
protected  java.lang.String determineSiteIdForSkuId(java.lang.String pSkuId, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Determines the site id to use for the given SKU id.
protected  GiftWithPurchaseSelectionChoice getAutoAddGiftSelectionChoice(java.lang.String pGiftType, java.lang.String pGiftDetail, java.util.Map pExtraParameters)
          Checks if the gift type and detail correspond to a single SKU and only if it does will it return a GiftWithPurchaseSelectionChoice bean for it.
protected  java.lang.String getCatalogKey(PricingContext pPricingContext, java.util.Map pExtraParameters)
          Gets the locale catalog key to use for adding new items.
 CatalogProperties getCatalogProperties()
          Getter for the catalog properties
 CatalogTools getCatalogTools()
          Getter for the catalog tools
 RqlStatement getCategoryQuery()
          Returns property CategoryQuery
 CommerceItemManager getCommerceItemManager()
          Getter for the commerce item manager
protected  java.lang.String getCommerceItemType(java.lang.String pProductId, java.lang.String pSkuId, java.lang.String pCatalogKey, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Gets the commerce item type to use based on the SKU item type by looking up the skuToCommerceItemTypeMapping.
 GiftWithPurchaseSelectionChoice[] getGiftSelectionChoices(java.lang.String pGiftType, java.lang.String pGiftDetail, boolean pReturnSkus, java.util.Map pExtraParameters)
          Gets an array of selection choices for the given GWP gift details.
 atg.commerce.promotion.GWPMarkerManager getGwpMarkerManager()
          Getter for the GWP marker manager
protected  java.util.Locale getLocale(PricingContext pPricingContext, java.util.Map pExtraParameters)
          Gets the locale to use.
 PricingTools getPricingTools()
          Returns the PricingTools property
 RqlStatement getProductContentGroupQuery()
          Returns property ProductContentGroupQuery
protected  RepositoryItem getProductForSku(RepositoryItem pSku, java.util.Set<Site> pValidSites)
          Determines which product to use for a given SKU.
protected  GiftWithPurchaseSelectionChoice getProductGWPSelectionChoice(RepositoryItem pProduct, boolean pGetSkus, java.util.Set<Site> pValidSites)
          Method to get the selection choice for a given product.
 PromotionTools getPromotionTools()
          Returns the PromotionTools property
 PurchaseProcessHelper getPurchaseProcessHelper()
          Getter for the purchase process helper
 atg.repository.nucleus.RepositoryGroupContainerService getRepositoryGroupContainerService()
          Returns the repositoryGroupContainerService property
 java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder)
          Retrieves all the gift with purchase selections available in the order.
 java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder, CommerceItem pItem)
          Retrieves all the gift with purchase selections available on a commerce item.
 java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder, CommerceItem pItem, java.lang.String pPromotionId, int pGiftHashCode)
          Retrieves all the gift with purchase selections for the given commerce item, promotion and gift.
 java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder, java.lang.String pPromotionId, int pGiftHashCode)
          Retrieves all the gift with purchase selections for the given order, promotion and gift.
 atg.multisite.SiteTools getSiteTools()
          Getter for the site tools
 RqlStatement getSkuContentGroupQuery()
          Returns property SkuContentGroupQuery
 java.util.Map<java.lang.String,java.lang.String> getSkuToCommerceItemTypeMapping()
          Mapping of sku item type to commerce item type if the default commerce item type is not sufficient
 boolean invalidateGift(RepositoryItem pOrderMarker, PricingContext pPricingContext, atg.commerce.promotion.GWPStatusHolder pStatusHolder, java.util.Map pExtraParameters)
          Method to invalidate a gift when a GWP promotion no longer qualifies.
 boolean invalidateGiftQuantity(RepositoryItem pOrderMarker, long pQuantityToInvalidate, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Invalidates a given quantity of a gift.
 boolean isJMSEnabled()
          Boolean flag, true to send JMS events for each GWP application message
protected  boolean isProductValidForSites(RepositoryItem pProduct, java.util.Set<Site> pValidSites)
          Utility method to check if the given product belongs to the given set of valid sites.
protected  boolean isTransactionMarkedAsRollBack()
          Returns true if the transaction associated with the current thread is marked for rollback.
 java.lang.String makeGiftSelection(java.lang.String pCurrentSelectedItemId, Order pOrder, java.lang.String pPromotionId, int pGiftHashCode, java.lang.String pProductId, java.lang.String pSkuId, long pQuantity, java.lang.String pCatalogKey, ShippingGroup pShippingGroup, java.lang.String pCommerceItemType, java.lang.String pSiteId, boolean pReplaceRemovedQuantity, boolean pReplaceFailedQuantity, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Method which makes a single gift selection for a given GWP gift.
 void mirrorOrderMarkers(Order pSourceOrder, Order pDestOrder)
          Method which removes existing order markers from the destination order and clones all of the order markers from the source order and adds them to the destination order.
protected  void priceQuantityToFree(CommerceItem pItem, long pQuantityFree, java.lang.String pPromotionId, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Prices the given quantity of the given item to be free due to the given GWP promotion id.
 CommerceItem processAutoAdd(RepositoryItem pOrderMarker, long pQuantityToAdd, java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos, java.util.List<CommerceItem> pNewItems, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Checks whether we can auto add some quantity of a gift.
 boolean processGWPInfos(java.util.Map<atg.commerce.promotion.GWPMultiHashKey,GWPInfo> pGWPInfos, PricingContext pPricingContext, java.util.Map pExtraParameters)
          This method will process the given map of GWPInfo objects that was created during item pricing.
 boolean qualifyGift(GWPInfo pGWPInfo, java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos, java.util.List<CommerceItem> pNewItems, PricingContext pPricingContext, atg.commerce.promotion.GWPStatusHolder pStatusHolder, java.util.Map pExtraParameters)
          Method to qualify a gift when a GWP promotion has newly qualified.
protected  long removeGiftQuantity(CommerceItem pItem, RepositoryItem pItemMarker, long pQuantityToRemove, boolean pAutoRemove, PricingContext pPricingContext, java.util.Map pExtraParameters)
          Method to remove the quantity of a given gift item for the given GWP item markers and quantity.
 void resetOrderMarkerQuantitiesfromItemMarkers(Order pOrder)
          Resets the quantity property values each order marker based on the corresponding item markers quantity property values.
 void setCatalogProperties(CatalogProperties pCatalogProperties)
          Setter for the catalog properties
 void setCatalogTools(CatalogTools pCatalogTools)
          Setter for the catalog tools
 void setCategoryQuery(RqlStatement pCategoryQuery)
          Sets property CategoryQuery
 void setCommerceItemManager(CommerceItemManager pCommerceItemManager)
          Setter for the commerce item manager
 void setGwpMarkerManager(atg.commerce.promotion.GWPMarkerManager pGwpMarkerManager)
          Setter for the GWP marker manager
 void setJMSEnabled(boolean pJMSEnabled)
          Boolean flag, true to send JMS events for each GWP application message
 void setPricingTools(PricingTools pPricingTools)
          Sets the PricingTools property
 void setProductContentGroupQuery(RqlStatement pProductContentGroupQuery)
          Sets property ProductContentGroupQuery
 void setPromotionTools(PromotionTools pPromotionTools)
          Sets the PromotionTools property
 void setPurchaseProcessHelper(PurchaseProcessHelper pPurchaseProcessHelper)
          Setter for the purchase process helper
 void setRepositoryGroupContainerService(atg.repository.nucleus.RepositoryGroupContainerService pRepositoryGroupContainerService)
          Sets the repositoryGroupContainerService property
 void setSiteTools(atg.multisite.SiteTools pSiteTools)
          Setter for the site tools
 void setSkuContentGroupQuery(RqlStatement pSkuContentGroupQuery)
          Sets property SkuContentGroupQuery
 void setSkuToCommerceItemTypeMapping(java.util.Map<java.lang.String,java.lang.String> pSkuToCommerceItemTypeMapping)
          Sets a mapping of sku item type to commerce item type if the default commerce item type is not sufficient
protected  void updateRemainingQuantities(Order pOrder)
          Method iterates over the items in the order and updates any item markers to ensure the remainingQuantity property is correct.
 void updateSelectableQuantity(Order pOrder, java.lang.String pPromotionId, int pGiftHashCode, long pSelectableQuantityToRemove)
          Updates the quantity available for selection for a GWP gift.
protected  java.util.Map<atg.commerce.promotion.GWPMultiHashKey,atg.commerce.promotion.GWPQuantityHolder> updateTargetedQuantities(java.util.Map<atg.commerce.promotion.GWPMultiHashKey,GWPInfo> pGWPInfos, Order pOrder, java.util.Map pExtraParameters)
          This method updates the targeted quantities on all existing item and order markers for promotions that are still qualifying in the current pricing operation.
protected  void validateGiftSelection(RepositoryItem pOrderMarker, java.lang.String pProductId, java.lang.String pSkuId, long pQuantity, boolean pReplaceExistingSelection, java.util.Map pExtraParameters)
          Validates the given product and SKU and quantity are valid as a gift selection for the given GWP order marker.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, 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
 
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

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
Class version string

See Also:
Constant Field Values

MY_RESOURCE_NAME

protected static final java.lang.String MY_RESOURCE_NAME
See Also:
Constant Field Values

sResourceBundle

protected static java.util.ResourceBundle sResourceBundle
Resource Bundle


mGwpMarkerManager

protected atg.commerce.promotion.GWPMarkerManager mGwpMarkerManager

mCatalogTools

protected CatalogTools mCatalogTools

mSiteTools

protected atg.multisite.SiteTools mSiteTools

mCommerceItemManager

protected CommerceItemManager mCommerceItemManager

mCatalogProperties

protected CatalogProperties mCatalogProperties

mPurchaseProcessHelper

protected PurchaseProcessHelper mPurchaseProcessHelper

mRepositoryGroupContainerService

protected atg.repository.nucleus.RepositoryGroupContainerService mRepositoryGroupContainerService

mPricingTools

protected PricingTools mPricingTools

mPromotionTools

protected PromotionTools mPromotionTools

mSkuContentGroupQuery

protected RqlStatement mSkuContentGroupQuery

mProductContentGroupQuery

protected RqlStatement mProductContentGroupQuery

mCategoryQuery

protected RqlStatement mCategoryQuery

mSkuToCommerceItemTypeMapping

protected java.util.Map<java.lang.String,java.lang.String> mSkuToCommerceItemTypeMapping

mJMSEnabled

protected boolean mJMSEnabled
Constructor Detail

GWPManager

public GWPManager()
Method Detail

getGwpMarkerManager

public atg.commerce.promotion.GWPMarkerManager getGwpMarkerManager()
Getter for the GWP marker manager

Returns:
GWPMarkerManager

setGwpMarkerManager

public void setGwpMarkerManager(atg.commerce.promotion.GWPMarkerManager pGwpMarkerManager)
Setter for the GWP marker manager

Parameters:
pGwpMarkerManager - GWPMarkerManager

getCatalogTools

public CatalogTools getCatalogTools()
Getter for the catalog tools

Returns:
CatalogTools

setCatalogTools

public void setCatalogTools(CatalogTools pCatalogTools)
Setter for the catalog tools

Parameters:
pCatalogTools - CatalogTools

getSiteTools

public atg.multisite.SiteTools getSiteTools()
Getter for the site tools

Returns:
SiteTools

setSiteTools

public void setSiteTools(atg.multisite.SiteTools pSiteTools)
Setter for the site tools

Parameters:
pSiteTools - SiteTools

getCommerceItemManager

public CommerceItemManager getCommerceItemManager()
Getter for the commerce item manager

Returns:
CommerceItemManager

setCommerceItemManager

public void setCommerceItemManager(CommerceItemManager pCommerceItemManager)
Setter for the commerce item manager

Parameters:
pCommerceItemManager - CommerceItemManager

getCatalogProperties

public CatalogProperties getCatalogProperties()
Getter for the catalog properties

Returns:
CatalogProperties

setCatalogProperties

public void setCatalogProperties(CatalogProperties pCatalogProperties)
Setter for the catalog properties

Parameters:
pCatalogProperties - CatalogProperties

getPurchaseProcessHelper

public PurchaseProcessHelper getPurchaseProcessHelper()
Getter for the purchase process helper

Returns:
PurchaseProcessHelper

setPurchaseProcessHelper

public void setPurchaseProcessHelper(PurchaseProcessHelper pPurchaseProcessHelper)
Setter for the purchase process helper

Parameters:
pPurchaseProcessHelper - PurchaseProcessHelper

getRepositoryGroupContainerService

public atg.repository.nucleus.RepositoryGroupContainerService getRepositoryGroupContainerService()
Returns the repositoryGroupContainerService property

Returns:
The repositoryGroupContainerService property

setRepositoryGroupContainerService

public void setRepositoryGroupContainerService(atg.repository.nucleus.RepositoryGroupContainerService pRepositoryGroupContainerService)
Sets the repositoryGroupContainerService property

Parameters:
pRepositoryGroupContainerService - The property value to set

getPricingTools

public PricingTools getPricingTools()
Returns the PricingTools property

Returns:
The PricingTools property

setPricingTools

public void setPricingTools(PricingTools pPricingTools)
Sets the PricingTools property

Parameters:
pPricingTools - The property value to set

getPromotionTools

public PromotionTools getPromotionTools()
Returns the PromotionTools property

Returns:
The PromotionTools property

setPromotionTools

public void setPromotionTools(PromotionTools pPromotionTools)
Sets the PromotionTools property

Parameters:
pPromotionTools - The property value to set

setSkuContentGroupQuery

public void setSkuContentGroupQuery(RqlStatement pSkuContentGroupQuery)
Sets property SkuContentGroupQuery


getSkuContentGroupQuery

public RqlStatement getSkuContentGroupQuery()
Returns property SkuContentGroupQuery


setProductContentGroupQuery

public void setProductContentGroupQuery(RqlStatement pProductContentGroupQuery)
Sets property ProductContentGroupQuery


getProductContentGroupQuery

public RqlStatement getProductContentGroupQuery()
Returns property ProductContentGroupQuery


setCategoryQuery

public void setCategoryQuery(RqlStatement pCategoryQuery)
Sets property CategoryQuery


getCategoryQuery

public RqlStatement getCategoryQuery()
Returns property CategoryQuery


getSkuToCommerceItemTypeMapping

public java.util.Map<java.lang.String,java.lang.String> getSkuToCommerceItemTypeMapping()
Mapping of sku item type to commerce item type if the default commerce item type is not sufficient

Returns:
Map of String SKU item type to String commerce item type

setSkuToCommerceItemTypeMapping

public void setSkuToCommerceItemTypeMapping(java.util.Map<java.lang.String,java.lang.String> pSkuToCommerceItemTypeMapping)
Sets a mapping of sku item type to commerce item type if the default commerce item type is not sufficient

Parameters:
pSkuToCommerceItemTypeMapping - Map of String SKU item type to String commerce item type

isJMSEnabled

public boolean isJMSEnabled()
Boolean flag, true to send JMS events for each GWP application message

Returns:
boolean

setJMSEnabled

public void setJMSEnabled(boolean pJMSEnabled)
Boolean flag, true to send JMS events for each GWP application message

Parameters:
pJMSEnabled - boolean

updateRemainingQuantities

protected void updateRemainingQuantities(Order pOrder)
                                  throws CommerceException
Method iterates over the items in the order and updates any item markers to ensure the remainingQuantity property is correct.

Parameters:
pOrder - Order to update
Throws:
CommerceException - for problems updating an item marker

updateTargetedQuantities

protected java.util.Map<atg.commerce.promotion.GWPMultiHashKey,atg.commerce.promotion.GWPQuantityHolder> updateTargetedQuantities(java.util.Map<atg.commerce.promotion.GWPMultiHashKey,GWPInfo> pGWPInfos,
                                                                                                                                  Order pOrder,
                                                                                                                                  java.util.Map pExtraParameters)
                                                                                                                           throws CommerceException
This method updates the targeted quantities on all existing item and order markers for promotions that are still qualifying in the current pricing operation.
This method will also detect manually removed targeted quantity and update the order markers accordingly.
This method does not process newly qualified promotions, i.e. those that do not as yet have an order marker.

Note, The method destructively removes the entries from each GWPInfo.targetedItemsMap as targeted item quantities are updated.

For performance reasons this method also returns a map containing the total quantities on each of the item markers in the order. This map is used to reconcile the order markers.
See {@link GWPMarkerManager#reconcileOrderMarkers(Order, Map)

Parameters:
pGWPInfos - Map of GWPInfo from the current pricing operation
pOrder - Order
pExtraParameters - Optional map of extra parameters
Returns:
Map of GWPMultiHashKey to GWPQuantityHolder with the quantities on all item markers.
Throws:
CommerceException

processGWPInfos

public boolean processGWPInfos(java.util.Map<atg.commerce.promotion.GWPMultiHashKey,GWPInfo> pGWPInfos,
                               PricingContext pPricingContext,
                               java.util.Map pExtraParameters)
                        throws PricingException
This method will process the given map of GWPInfo objects that was created during item pricing.
Typically it is called by PricingTools once item pricing is complete.

The keys to the map should be a composite of the promotion id and the gift hash code.

Parameters:
pGWPInfos - Map of GWPInfo objects keyed by a GWPMultiHashKey of promotion id and gift hash code
pPricingContext - PricingContext including the Order to update
pExtraParameters - Map of extra parameters (optional)
Returns:
true if item pricing need to be restarted
Throws:
PricingException - if processing a GWPInfo or order marker fails.

changeGiftQuantity

public boolean changeGiftQuantity(RepositoryItem pOrderMarker,
                                  long pQuantityDelta,
                                  java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos,
                                  java.util.List<CommerceItem> pNewItems,
                                  PricingContext pPricingContext,
                                  java.util.Map pExtraParameters)
                           throws PricingException
Called if there has been a change in quantity of a free gift. This method should only ever be called if there is already an existing order marker for the gift.

Parameters:
pOrderMarker - RepositoryItem order marker
pQuantityDelta - long +ve/-ve change in quantity
pNewItemInfos - List of AddCommerceItemInfo that should be populated with any new item infos added
pNewItems - List of CommerceItem that should be populated with any new items added
pPricingContext - PricingContext
pExtraParameters - Optional map of extra parameters
Returns:
boolean, true if item pricing needs to be restarted
Throws:
PricingException

invalidateGift

public boolean invalidateGift(RepositoryItem pOrderMarker,
                              PricingContext pPricingContext,
                              atg.commerce.promotion.GWPStatusHolder pStatusHolder,
                              java.util.Map pExtraParameters)
                       throws PricingException
Method to invalidate a gift when a GWP promotion no longer qualifies.
Removes the order marker for the gift and any item quantity associated with it.

Parameters:
pOrderMarker - RepositoryItem GWP order marker
pPricingContext - PricingContext for this pricing operation
pStatusHolder - GWPStatusHolder to update with any invalidation information
pExtraParameters - Map of extra parameters (optional)
Returns:
true if item pricing needs to be restarted
Throws:
PricingException

invalidateGiftQuantity

public boolean invalidateGiftQuantity(RepositoryItem pOrderMarker,
                                      long pQuantityToInvalidate,
                                      PricingContext pPricingContext,
                                      java.util.Map pExtraParameters)
                               throws PricingException
Invalidates a given quantity of a gift.

Parameters:
pOrderMarker - GWP order marker for the gift to invalidate
pQuantityToInvalidate - long quantity to invalidate or -1 for all
pPricingContext - PricingContext
pExtraParameters - Optional extra parameters map
Returns:
true if pricing needs to be restarted
Throws:
PricingException

removeGiftQuantity

protected long removeGiftQuantity(CommerceItem pItem,
                                  RepositoryItem pItemMarker,
                                  long pQuantityToRemove,
                                  boolean pAutoRemove,
                                  PricingContext pPricingContext,
                                  java.util.Map pExtraParameters)
                           throws PricingException
Method to remove the quantity of a given gift item for the given GWP item markers and quantity.
quantity is either removed or re-priced to full price depending on the auto remove flag.

Parameters:
pItem - CommerceItem with GWP quantity to be removed
pItemMarker - RepositoryItem GWP item marker to have quantity removed, if null then it will be looked up
pQuantityToRemove - long maximum quantity to be removed or -1 for all quantity
pAutoRemove - boolean true if quantity should be removed, otherwise it is re-priced
pPricingContext - PricingContext for this pricing operation
pExtraParameters - Map of extra parameters (optional)
Returns:
long GWP quantity that was removed from the markers, -ve total if some quantity was re-priced
Throws:
PricingException

qualifyGift

public boolean qualifyGift(GWPInfo pGWPInfo,
                           java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos,
                           java.util.List<CommerceItem> pNewItems,
                           PricingContext pPricingContext,
                           atg.commerce.promotion.GWPStatusHolder pStatusHolder,
                           java.util.Map pExtraParameters)
                    throws PricingException
Method to qualify a gift when a GWP promotion has newly qualified.
Add an order marker for the gift and any auto item quantity associated with it.

Note: the caller is responsible for calling PurchaseProcessHelper postAddItemsToOrder for newly added items.

Parameters:
pGWPInfo - GWPInfo for the newly qualified gift
pNewItemInfos - List of AddCommerceItemInfo populated for each new item added by this method
pNewItems - List of CommerceItem populated for each new item added by this method
pPricingContext - PricingContext for this pricing operation
pStatusHolder - GWPStatusHolder to track newly qualified promotions
pExtraParameters - Map of extra parameters (optional)
Returns:
true if item pricing needs to be restarted
Throws:
PricingException

processAutoAdd

public CommerceItem processAutoAdd(RepositoryItem pOrderMarker,
                                   long pQuantityToAdd,
                                   java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos,
                                   java.util.List<CommerceItem> pNewItems,
                                   PricingContext pPricingContext,
                                   java.util.Map pExtraParameters)
                            throws PricingException
Checks whether we can auto add some quantity of a gift.

Parameters:
pOrderMarker - RepositoryItem order marker
pQuantityToAdd - long +ve/-ve quantity to auto add
pNewItemInfos - List of AddCommerceItemInfo to be populated with any new item info
pNewItems - List of CommerceItem to be populated
pPricingContext - PricingContext
pExtraParameters - Optional map of extra parameters
Returns:
CommerceItem of any auto added item
Throws:
PricingException

addGiftQuantity

protected CommerceItem addGiftQuantity(RepositoryItem pOrderMarker,
                                       java.lang.String pProductId,
                                       java.lang.String pSkuId,
                                       long pQuantityToAdd,
                                       java.lang.String pCatalogKey,
                                       ShippingGroup pShippingGroup,
                                       java.lang.String pCommerceItemType,
                                       java.lang.String pSiteId,
                                       java.util.List<atg.commerce.order.purchase.AddCommerceItemInfo> pNewItemInfos,
                                       java.util.List<CommerceItem> pNewItems,
                                       int pItemIndex,
                                       PricingContext pPricingContext,
                                       java.util.Map pExtraParameters)
                                throws CommerceException
Method to add GWP quantity to the order. Typically called to auto add on promotion qualifying or to add when making a new gift selection. Prices the new quantity to zero.
Populates the newItems and newItemInfos lists with the new item.

Note: Once the caller has added all free gifts the PurchaseProcessHelper postAddItemsToOrder method should be called.

Parameters:
pOrderMarker - RepositoryItem GWP order marker to update
pProductId - String Product id to add
pSkuId - String SKU id to add
pQuantityToAdd - long quantity to add
pCatalogKey - String catalog key
pShippingGroup - ShippingGroup to use
pCommerceItemType - String commerce item type
pSiteId - String site id to use
pNewItemInfos - List of AddCommerceItemInfo populated by this method
pNewItems - List of CommerceItem populated with any newly added items by this method
pItemIndex - int index to add the new items into the order list of items, -1 for the end of the list
pPricingContext - PricingContext
pExtraParameters - Map of extra parameters (optional)
Returns:
Throws:
PricingException
CommerceException

getLocale

protected java.util.Locale getLocale(PricingContext pPricingContext,
                                     java.util.Map pExtraParameters)
Gets the locale to use. Usually the users locale.

Parameters:
pPricingContext - PricingContext which may contain the locale
pExtraParameters - Map of extra parameters (optional)
Returns:
Locale

getCatalogKey

protected java.lang.String getCatalogKey(PricingContext pPricingContext,
                                         java.util.Map pExtraParameters)
Gets the locale catalog key to use for adding new items. Usually the users locale.

Parameters:
pPricingContext - PricingContext which may contain the locale
pExtraParameters - Map of extra parameters (optional)
Returns:
String catalog key

getCommerceItemType

protected java.lang.String getCommerceItemType(java.lang.String pProductId,
                                               java.lang.String pSkuId,
                                               java.lang.String pCatalogKey,
                                               PricingContext pPricingContext,
                                               java.util.Map pExtraParameters)
                                        throws PricingException
Gets the commerce item type to use based on the SKU item type by looking up the skuToCommerceItemTypeMapping.

Parameters:
pProductId - String product repository id
pSkuId - String sku repository id
pCatalogKey - String catalog locale
pPricingContext - PricingContext for current pricing operation
pExtraParameters - Optional Map of extra parameters
Returns:
String commerce item type
Throws:
PricingException

priceQuantityToFree

protected void priceQuantityToFree(CommerceItem pItem,
                                   long pQuantityFree,
                                   java.lang.String pPromotionId,
                                   PricingContext pPricingContext,
                                   java.util.Map pExtraParameters)
                            throws PricingException
Prices the given quantity of the given item to be free due to the given GWP promotion id.

Parameters:
pItem - CommerceItem to price
pQuantityFree - long quantity of the item that needs priced to be free
pPromotionId - String GWP promotion id.
pPricingContext - PricingContext
pExtraParameters - Map of extra parameters (optional)
Throws:
PricingException

getGiftSelectionChoices

public GiftWithPurchaseSelectionChoice[] getGiftSelectionChoices(java.lang.String pGiftType,
                                                                 java.lang.String pGiftDetail,
                                                                 boolean pReturnSkus,
                                                                 java.util.Map pExtraParameters)
                                                          throws CommerceException
Gets an array of selection choices for the given GWP gift details.

Parameters:
pGiftType - String gift type, e.g. sku
pGiftDetail - String gift detail, e.g. sku1234
pReturnSkus - boolean, true to return the SKUs for all choices
pExtraParameters - Map of extra parameters (optional)
Returns:
Array of GiftWithPurchaseSelectionChoice
Throws:
CommerceException

getAutoAddGiftSelectionChoice

protected GiftWithPurchaseSelectionChoice getAutoAddGiftSelectionChoice(java.lang.String pGiftType,
                                                                        java.lang.String pGiftDetail,
                                                                        java.util.Map pExtraParameters)
                                                                 throws CommerceException
Checks if the gift type and detail correspond to a single SKU and only if it does will it return a GiftWithPurchaseSelectionChoice bean for it. This is used to try and get a SKU to auto add to cart.

Parameters:
pGiftType - String gift type
pGiftDetail - String gift detail
pExtraParameters - Optional map of extra parameters
Returns:
GiftWithPurchaseSelectionChoice with a single SKU or null if not valid for auto add.
Throws:
CommerceException

makeGiftSelection

public java.lang.String makeGiftSelection(java.lang.String pCurrentSelectedItemId,
                                          Order pOrder,
                                          java.lang.String pPromotionId,
                                          int pGiftHashCode,
                                          java.lang.String pProductId,
                                          java.lang.String pSkuId,
                                          long pQuantity,
                                          java.lang.String pCatalogKey,
                                          ShippingGroup pShippingGroup,
                                          java.lang.String pCommerceItemType,
                                          java.lang.String pSiteId,
                                          boolean pReplaceRemovedQuantity,
                                          boolean pReplaceFailedQuantity,
                                          PricingContext pPricingContext,
                                          java.util.Map pExtraParameters)
                                   throws PricingException
Method which makes a single gift selection for a given GWP gift. The method can remove the current selected item quantity first before selecting the new quantity. Typically this is called when a shopper has made a gift selection or changed an existing selection. The replaceRemovedQuantity and replaceFailedQuantity flags can be set to ensure the new selection is to replace existing removed or failed quantity rather than existing commerce item quantity. If both flags are set then removed quantity is replaced before failed quantity.

Parameters:
pCurrentSelectedItemId - String commerce item id of any currently selection item to replace(optional)
pOrder - Order to update
pPromotionId - String GWP promotion repository id the selection id for.
pGiftHashCode - int GWP hash code for gift the selection is for. -1 is not valid in this case.
pProductId - String product id of the new selection
pSkuId - String SKU id of the new selection
pQuantity - long quantity of the new selection
pCatalogKey - Locale catalog key of the new selection
pShippingGroup - ShippingGroup of the new selection
pCommerceItemType - String commerce item type of the new selection
pSiteId - String site id of the new selection
pReplaceRemovedQuantity - boolean true to replace removed quantity first
pReplaceFailedQuantity - boolean true to replace failed quantity (after removed quantity)
pPricingContext - PricingContext
pExtraParameters - Map of extra parameters (optional)
Returns:
String commerce id of the new selection
Throws:
PricingException

isTransactionMarkedAsRollBack

protected boolean isTransactionMarkedAsRollBack()
Returns true if the transaction associated with the current thread is marked for rollback. This is useful if you do not want to perform some action (e.g. updating the order) if some other subservice already needs the transaction rolledback.

Returns:
a boolean value

validateGiftSelection

protected void validateGiftSelection(RepositoryItem pOrderMarker,
                                     java.lang.String pProductId,
                                     java.lang.String pSkuId,
                                     long pQuantity,
                                     boolean pReplaceExistingSelection,
                                     java.util.Map pExtraParameters)
                              throws PricingException
Validates the given product and SKU and quantity are valid as a gift selection for the given GWP order marker. Throws a PricingException if the selection is invalid.

Parameters:
pOrderMarker - RepositoryItem GWP order marker
pProductId - String product id for the selection
pSkuId - String SKU id for the selection
pQuantity - long quantity for the selection
pReplaceExistingSelection - boolean flag, true if we are replacing an existing selection
pExtraParameters - Map of extra parameters (optional)
Throws:
PricingException - if the selection is invalid

getProductForSku

protected RepositoryItem getProductForSku(RepositoryItem pSku,
                                          java.util.Set<Site> pValidSites)
                                   throws PricingException
Determines which product to use for a given SKU. The first parent product that belongs in the given set of valid sites is returned.

Parameters:
pSku - RepositoryItem sku
pValidSites - Set of valid Site the parent product can belong in
Returns:
RepositoryItem product
Throws:
PricingException - if a product couldn't be found.

isProductValidForSites

protected boolean isProductValidForSites(RepositoryItem pProduct,
                                         java.util.Set<Site> pValidSites)
Utility method to check if the given product belongs to the given set of valid sites.

Parameters:
pProduct - RepositoryItem product to check
pValidSites - Set of Site that are valid
Returns:
true if the product is valid for the given set of sites

getProductGWPSelectionChoice

protected GiftWithPurchaseSelectionChoice getProductGWPSelectionChoice(RepositoryItem pProduct,
                                                                       boolean pGetSkus,
                                                                       java.util.Set<Site> pValidSites)
Method to get the selection choice for a given product. Only gets the SKUs if the getSkus flag is true. If there are no valid SKUs then the method returns null. If the product does not belong to one of the valid sites passed in then the method will return null.

Parameters:
pProduct - RepositoryItem product
pGetSkus - boolean flag, true if we need to get the SKUs as well.
pValidSites - Set of Site that are valid for any choice
Returns:
GiftWithPurchaseSelectionChoice for that product

canRepriceItem

protected boolean canRepriceItem(CommerceItem pItem)
Check if this item can be re-priced to full price.

Parameters:
pItem - CommerceItem to check
Returns:
true if it can be re-priced

getSelections

public java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder)
                                                              throws CommerceException
Retrieves all the gift with purchase selections available in the order.

Parameters:
pOrder - Order to inspect
Returns:
Collection of GiftWithPurchaseSelection beans
Throws:
CommerceException

getSelections

public java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder,
                                                                     java.lang.String pPromotionId,
                                                                     int pGiftHashCode)
                                                              throws CommerceException
Retrieves all the gift with purchase selections for the given order, promotion and gift. The promotion can be null for all promotions. The gift hash code can be -1 for all gifts in the promotion.

Parameters:
pOrder - Order to inspect
pPromotionId - String promotion, can be null for all promotions
pGiftHashCode - in gift hash code, can be -1 for all gifts in the promotion
Returns:
Collection of GiftWithPurchaseSelection beans
Throws:
CommerceException

getSelections

public java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder,
                                                                     CommerceItem pItem)
                                                              throws CommerceException
Retrieves all the gift with purchase selections available on a commerce item.

Parameters:
pOrder - Order to inspect
pItem - CommerceItem to inspect
Returns:
Collection of GiftWithPurchaseSelection beans
Throws:
CommerceException

getSelections

public java.util.Collection<GiftWithPurchaseSelection> getSelections(Order pOrder,
                                                                     CommerceItem pItem,
                                                                     java.lang.String pPromotionId,
                                                                     int pGiftHashCode)
                                                              throws CommerceException
Retrieves all the gift with purchase selections for the given commerce item, promotion and gift. The promotion can be null for all promotions. The gift hash code can be -1 for all gifts in the promotion.

Parameters:
pOrder - Order to inspect
pItem - CommerceItem to inspect
pPromotionId - String promotion, can be null for all promotions
pGiftHashCode - int gift hash code, can be -1 for all gifts in the promotion
Returns:
Collection of GiftWithPurchaseSelection beans
Throws:
CommerceException

determineSiteIdForSkuId

protected java.lang.String determineSiteIdForSkuId(java.lang.String pSkuId,
                                                   PricingContext pPricingContext,
                                                   java.util.Map pExtraParameters)
                                            throws CommerceException
Determines the site id to use for the given SKU id. Will attempt to find a commerce item in the order first with the same SKU id and use its site id. Otherwise defaults to the standard catalog tools behaviour.

Parameters:
pSkuId - String sku Id
pPricingContext - PricingContext
pExtraParameters - Optional map of extra parameters
Returns:
String site id to use
Throws:
CommerceException

mirrorOrderMarkers

public void mirrorOrderMarkers(Order pSourceOrder,
                               Order pDestOrder)
                        throws CommerceException
Method which removes existing order markers from the destination order and clones all of the order markers from the source order and adds them to the destination order.

This method is used in returns and exchanges.

Parameters:
pSourceOrder - Order with order markers to copy
pDestOrder - Order to copy into
Throws:
CommerceException

resetOrderMarkerQuantitiesfromItemMarkers

public void resetOrderMarkerQuantitiesfromItemMarkers(Order pOrder)
                                               throws CommerceException
Resets the quantity property values each order marker based on the corresponding item markers quantity property values. The order quantity values updated from the item markers include: automaticQuantity, targetedQuantity and selectedQuantity.

Order markers that have no corresponding item markers have all their quantity properties reset to 0.

failedQuantity and removedQuantity are always reset to 0 on all order markers.

Parameters:
pOrder - Order to update
Throws:
CommerceException

updateSelectableQuantity

public void updateSelectableQuantity(Order pOrder,
                                     java.lang.String pPromotionId,
                                     int pGiftHashCode,
                                     long pSelectableQuantityToRemove)
                              throws CommerceException
Updates the quantity available for selection for a GWP gift. e.g. to remove placeholder quantity from the order for a gift.

Parameters:
pOrder - Order
pPromotionId - String promotion Id
pGiftHashCode - int gift hash code
pSelectableQuantityToRemove - +ve selectable quantity to remove from the order
Throws:
CommerceException