public class PromotionMgr extends BaseMgr implements PromotionMgrIf
Modifier and Type | Class and Description |
---|---|
protected class |
PromotionMgr.StaticData
Used to store the static data of this manager
|
Modifier and Type | Field and Description |
---|---|
static int |
ALL
Constant for Promotion Rule
|
static int |
COUPON_DOESNT_EXIST
Coupon doesn't exist
|
static int |
COUPON_EXISTS_ACTIVE
Coupon exists and is active
|
static int |
COUPON_EXISTS_INACTIVE
Coupon exists but is no longer active
|
static int |
EXCLUDE
Constant for Promotion Rule
|
protected static int |
GIFT_CERTIFICATE_RELATION_TYPE
Constant for Promotion To Product Relation
|
static int |
INCLUDE
Constant for Promotion Rule
|
protected static org.apache.commons.logging.Log |
log
the log
|
protected static java.lang.String |
mutex
mutex
|
protected static int |
PROMOTION_RELATION_TYPE
Constant for Promotion To Product Relation
|
protected static int |
promotionUsageCountMaxRetries
Number of times to retry the promotion usage count update SQL
|
protected static java.lang.String |
promotionUseMutex
Mutex for updating promotion usage count
|
protected static java.util.Map<java.lang.String,PromotionMgr.StaticData> |
staticDataHM
Hash Map that contains the static data
|
templateBaseDir
Constructor and Description |
---|
PromotionMgr(KKEngIf eng)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected void |
applyDiscount(ProductIf prod,
PromotionResultIf promResult,
PromotionOptionsIf options)
Apply the promotion discount to a product
|
protected int |
checkCategory(Promotion prm,
ProductIf prod,
java.util.HashMap<java.lang.String,java.lang.String> promotionCatMap,
java.util.HashMap<java.lang.Integer,java.util.ArrayList<java.lang.Integer>> productCatIdMap)
We check to see whether the product category is a category that can use the promotion.
|
protected int |
checkCoupon(Promotion prm,
Order order)
If the promotion requires a coupon, we try and find one or more active coupons for the
promotion that have a coupon code equal to the one in the order.
|
protected int |
checkCoupon(Promotion prm,
java.lang.String[] coupons)
If the promotion requires a coupon, we try and find one or more active coupons for the
promotion that have a coupon code equal to one of the ones the array.
|
int |
checkCoupon(java.lang.String couponCode)
This method is used to verify whether a coupon code actually exists and if it does, whether
the coupon is still active.
|
protected int |
checkCustomer(Promotion prm,
int customerId)
We check to see whether the customer submitting the order is a customer that can use the
promotion.
|
protected int |
checkCustomerGroup(Promotion prm,
int customerId)
We check to see whether the group of the customer submitting the order is a group that can
use the promotion.
|
protected int |
checkCustomerUse(Promotion prm,
int customerId)
If the promotion has the maxUse attribute set to a positive value, then we check to see
whether the customer can still use the promotion or whether he has already used it the
maximum number of times allowed.
|
protected int |
checkExpression(Promotion prm,
int customerId,
java.util.HashMap<java.lang.Integer,java.util.ArrayList<java.lang.Integer>> expressionIdMap)
We check to see whether the expression evaluates to TRUE
|
protected int |
checkManufacturer(Promotion prm,
ProductIf prod,
java.util.HashMap<java.lang.String,java.lang.String> promotionManuMap)
We check to see whether the product manufacturer is a manufacturer that can use the
promotion.
|
protected int |
checkProduct(Promotion prm,
OrderProductIf orderProd,
java.util.HashMap<java.lang.String,PromotionProduct> promotionProdMap)
We check to see whether the product is a product that can use the promotion.
|
protected boolean |
checkPromotion(Promotion prm)
Checks the validity of the promotion object.
|
Promotion[] |
getAllPromotions()
Returns an array of all active promotions
|
Coupon |
getCouponPerId(int couponId,
CouponOptionsIf options)
Returns a coupon for the coupon id passed in as a parameter.
|
Coupon[] |
getCouponsPerCode(java.lang.String couponCode,
CouponOptionsIf options)
Returns an array of coupons for the coupon code passed in as a parameter.
|
protected int |
getCustomerId(java.lang.String sessionId,
int customerId)
If the sessionId is null, we check the customerId to ensure that it is negative.
|
protected OrderProduct[] |
getOrderProductsFromProduct(ProductIf prod)
Creates OrderProducts from a product so that we can reuse the checkProduct() method.
|
PromotionIf |
getPromotion(int promotionId,
java.lang.String promotionName,
int languageId,
FetchPromotionOptionsIf prmOptions,
FetchProductOptionsIf prodOptions)
This API call is used to retrieve a single promotion matching an id or name.
|
protected java.util.HashMap<java.lang.String,java.lang.String> |
getPromotionCategoryMap(PromotionIf[] activePromotions)
Create a hash map of all of the categories associated with the active promotions with a
single database query
|
protected java.lang.String |
getPromotionCategoryMapKey(int promotionId,
int catId)
Create a unique key for the Promotion Category Map
|
protected java.util.HashMap<java.lang.Integer,java.util.ArrayList<java.lang.Integer>> |
getPromotionExpressionMap(PromotionIf[] activePromotions)
Create a hash map of all of the expressions associated with the active promotions with a
single database query
|
protected int |
getPromotionIdForGiftCertificate(int productId,
int productOptionId,
int productOptionValueId)
Protected method for common code to get the promotion id of a promotion connected to a gift
certificate.
|
int |
getPromotionIdForGiftCertificate(OrderProductIf op)
Get the promotion id for an order product object containing a gift certificate.
|
protected java.util.HashMap<java.lang.String,java.lang.String> |
getPromotionManufacturerMap(PromotionIf[] activePromotions)
Create a hash map of all of the manufacturers associated with the active promotions with a
single database query
|
protected java.lang.String |
getPromotionManufacturerMapKey(int promotionId,
int manuId)
Create a unique key for the Promotion Manufacturer Map
|
protected java.util.HashMap<java.lang.String,PromotionProduct> |
getPromotionProductMap(PromotionIf[] activePromotions,
Order order,
ProductIf[] products)
Create a hash map of all of the products associated with the active promotions with a single
database query.
|
protected java.lang.String |
getPromotionProductMapKey(int promotionId,
int prodId,
int prodOptionId,
int prodOptionValueId)
Create a unique key for the Promotion Product Map
|
protected PromotionResultIf[] |
getPromotionResultArray(PromotionResultIf[] currentArray,
PromotionResult newResult)
Utility method to add a PromotionResult object on to the end of an array
|
Promotion[] |
getPromotions(java.lang.String orderTotalCode,
Order order)
We return all active promotions for the orderTotalCode passed in as a parameter.
|
Promotion[] |
getPromotionsPerCoupon(java.lang.String couponCode,
int couponId,
PromotionOptionsIf options)
This method is used to return an array of promotions associated with the coupon(s) identified
by the input parameters.
|
protected Promotion[] |
getPromotionsPerOrderTotalCode(java.util.ArrayList<java.lang.String> orderTotalCodeList)
The active promotions related to the list of orderTotalCodes passed in as a parameter, are
fetched from the database and returned.
|
protected Promotion[] |
getPromotionsPerOrderTotalCode(java.lang.String orderTotalCode)
The active promotions related to the list of orderTotalCodes passed in as a parameter, are
fetched from the database and returned.
|
ProductIf[] |
getPromotionsPerProducts(java.lang.String sessionId,
int customerId,
ProductIf[] products,
PromotionIf[] promotions,
java.lang.String[] couponCodes,
PromotionOptionsIf options)
This method is used to calculate a discount on individual products so that the discount can
be displayed without having to add the product to the cart.
The method receives an array of products and returns an array of products with attached PromotionResult objects that contain the results of one or more of the promotions passed in as a parameter. |
int |
getPromotionUsageCountMaxRetries() |
int |
insertCoupon(CouponIf coupon,
int promotionId)
Insert a coupon and associate it with the promotion referenced by promotionId.
|
protected boolean |
isEnhancedVariantHandlingModeEnabled()
Check in the static data if enhanced variant handling mode is enabled.
|
protected void |
processPrice(ProductIf prod,
PromotionOptionsIf options)
We apply the discount to a product, taking into consideration the rules to decide which
promotion discount to select
|
void |
refreshConfigs()
Refresh the configuration of the Promotion manager
|
protected void |
setCouponCriteriaWithStandardAttributes(KKCriteria c)
Set the criteria object with all of the attributes for a coupon
|
protected void |
setPromotionCriteriaWithStandardAttributes(KKCriteria c)
Set the criteria object with all of the attributes for a promotion
|
void |
setPromotionUsageCountMaxRetries(int promotionUsageCountMaxRetries)
The maximum number of optimistic concurrency retries when setting the promotion usage count
|
void |
updatePromotionUsage(Order order)
If the order has any associated coupons we iterate through the coupons and increment the
timesUsed attribute.
|
protected void |
validateCoupon(CouponIf coupon)
Used to validate a coupon before inserting
|
acquireLock, addInsertAttr, addInsertAttr, addStringRuleConstraint, addStringRuleConstraint, checkRequired, escapeHTML, executeQuery, executeQuery, executeQuery, executeQuery, executeQuery, getAdminEngMgr, getBasketMgr, getBillingMgr, getBookableProductMgr, getCacheMgr, getCatMgr, getConfigMgr, getCookieMgr, getCurrMgr, getCustMgr, getCustomerIdFromSession, getCustomerStatsMgr, getCustomerTagMgr, getEmailMgr, getEng, getEventMgr, getExportMgr, getHTMLEscaper, getKonaKartConfig, getKonaKartConfig, getKonaKartConfig, getLangMgr, getManuMgr, getMiscItemMgr, getMiscPriceMgr, getMode, getModeString, getMqMgr, getMultiStoreMgr, getNewCriteria, getNewCriteria, getOrderIntegrationMgr, getOrderMgr, getOrderTotalMgr, getPaymentMgr, getProdMgr, getProductsToCategoresCriteria, getPromMgr, getPunchOutMgr, getRewardPointMgr, getSecMgr, getShippingMgr, getSolrMgr, getStoreId, getStoreMgr, getStoreTime, getSuggestionMgr, getTaxMgr, getTemplate, getTemplateRoot, getVelocityContextMgr, getWishListMgr, init, insertKKEvent, insertKKEvent, isBusiness, isBusinessOrEnterprise, isClassPresent, isCommunity, isDeadlockException, isEnterprise, isMultiStoreShareCategories, isMultiStoreShareCustomers, isMultiStoreShareCustomersOrProducts, isMultiStoreSharedDb, isMultiStoreShareProducts, isMultiVendor, isUnix, manageThrowable, releaseLock, updateStaticVariablesNow
protected static org.apache.commons.logging.Log log
protected static java.lang.String mutex
protected static java.util.Map<java.lang.String,PromotionMgr.StaticData> staticDataHM
public static final int ALL
public static final int EXCLUDE
public static final int INCLUDE
protected static final int PROMOTION_RELATION_TYPE
protected static final int GIFT_CERTIFICATE_RELATION_TYPE
public static final int COUPON_DOESNT_EXIST
public static final int COUPON_EXISTS_ACTIVE
public static final int COUPON_EXISTS_INACTIVE
protected static int promotionUsageCountMaxRetries
protected static java.lang.String promotionUseMutex
public PromotionMgr(KKEngIf eng) throws java.lang.Exception
eng
- the engjava.lang.Exception
- an unexpected exceptionpublic Promotion[] getPromotions(java.lang.String orderTotalCode, Order order) throws java.lang.Exception
getPromotions
in interface PromotionMgrIf
orderTotalCode
- the orderTotalCodeorder
- the orderjava.lang.Exception
- an unexpected exceptionpublic Promotion[] getAllPromotions() throws java.lang.Exception
getAllPromotions
in interface PromotionMgrIf
java.lang.Exception
- an unexpected exceptionprotected boolean checkPromotion(Promotion prm)
prm
- the prmprotected int checkCustomer(Promotion prm, int customerId) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
prm
- the prmcustomerId
- the customerIdcom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected int checkCustomerUse(Promotion prm, int customerId) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
prm
- the prmcustomerId
- the customerIdcom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected int checkCustomerGroup(Promotion prm, int customerId) throws java.lang.Exception
prm
- the prmcustomerId
- the customerIdjava.lang.Exception
- an unexpected exceptionprotected int checkManufacturer(Promotion prm, ProductIf prod, java.util.HashMap<java.lang.String,java.lang.String> promotionManuMap) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
prm
- the prmprod
- the prodpromotionManuMap
- the promotionManuMapcom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected java.util.HashMap<java.lang.String,PromotionProduct> getPromotionProductMap(PromotionIf[] activePromotions, Order order, ProductIf[] products) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
activePromotions
- the activePromotionsorder
- the orderproducts
- the productscom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected java.lang.String getPromotionProductMapKey(int promotionId, int prodId, int prodOptionId, int prodOptionValueId)
promotionId
- the promotionIdprodId
- the prodIdprodOptionId
- the prodOptionIdprodOptionValueId
- the prodOptionValueIdprotected java.util.HashMap<java.lang.String,java.lang.String> getPromotionManufacturerMap(PromotionIf[] activePromotions) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
activePromotions
- the activePromotionscom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected java.lang.String getPromotionManufacturerMapKey(int promotionId, int manuId)
promotionId
- the promotionIdmanuId
- the manuIdprotected java.util.HashMap<java.lang.String,java.lang.String> getPromotionCategoryMap(PromotionIf[] activePromotions) throws java.lang.Exception
activePromotions
- the activePromotionsjava.lang.Exception
- an unexpected exceptionprotected java.lang.String getPromotionCategoryMapKey(int promotionId, int catId)
promotionId
- the promotionIdcatId
- the catIdprotected java.util.HashMap<java.lang.Integer,java.util.ArrayList<java.lang.Integer>> getPromotionExpressionMap(PromotionIf[] activePromotions) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
activePromotions
- the activePromotionscom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected int checkProduct(Promotion prm, OrderProductIf orderProd, java.util.HashMap<java.lang.String,PromotionProduct> promotionProdMap) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
prm
- the prmorderProd
- the orderProdpromotionProdMap
- the promotionProdMapcom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected int checkCategory(Promotion prm, ProductIf prod, java.util.HashMap<java.lang.String,java.lang.String> promotionCatMap, java.util.HashMap<java.lang.Integer,java.util.ArrayList<java.lang.Integer>> productCatIdMap) throws java.lang.Exception
prm
- the prmprod
- the prodpromotionCatMap
- the promotionCatMapproductCatIdMap
- the productCatIdMapjava.lang.Exception
- an unexpected exceptionprotected int checkCoupon(Promotion prm, Order order) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
prm
- the prmorder
- the ordercom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected int checkCoupon(Promotion prm, java.lang.String[] coupons) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
prm
- the prmcoupons
- the couponscom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)protected int checkExpression(Promotion prm, int customerId, java.util.HashMap<java.lang.Integer,java.util.ArrayList<java.lang.Integer>> expressionIdMap) throws java.lang.Exception
prm
- the prmcustomerId
- the customerIdexpressionIdMap
- the expressionIdMapjava.lang.Exception
- an unexpected exceptionprotected Promotion[] getPromotionsPerOrderTotalCode(java.lang.String orderTotalCode) throws java.lang.Exception
orderTotalCode
- the orderTotalCodejava.lang.Exception
- an unexpected exceptionprotected Promotion[] getPromotionsPerOrderTotalCode(java.util.ArrayList<java.lang.String> orderTotalCodeList) throws java.lang.Exception
orderTotalCodeList
- the orderTotalCodeListjava.lang.Exception
- an unexpected exceptionpublic void updatePromotionUsage(Order order) throws java.lang.Exception
updatePromotionUsage
in interface PromotionMgrIf
order
- the orderjava.lang.Exception
- an unexpected exceptionprotected void setPromotionCriteriaWithStandardAttributes(KKCriteria c)
c
- the cprotected void setCouponCriteriaWithStandardAttributes(KKCriteria c)
c
- the cpublic int getPromotionIdForGiftCertificate(OrderProductIf op) throws com.konakart.app.KKException, org.apache.torque.TorqueException, com.workingdogs.village.DataSetException
getPromotionIdForGiftCertificate
in interface PromotionMgrIf
op
- the opcom.konakart.app.KKException
- an unexpected KKException exceptionorg.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)com.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)protected int getPromotionIdForGiftCertificate(int productId, int productOptionId, int productOptionValueId) throws org.apache.torque.TorqueException, com.workingdogs.village.DataSetException
productId
- the productIdproductOptionId
- the productOptionIdproductOptionValueId
- the productOptionValueIdorg.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)com.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)public int insertCoupon(CouponIf coupon, int promotionId) throws java.lang.Exception
insertCoupon
in interface PromotionMgrIf
coupon
- the couponpromotionId
- the promotionIdjava.lang.Exception
- an unexpected exceptionprotected void validateCoupon(CouponIf coupon) throws com.konakart.app.KKException
coupon
- the couponcom.konakart.app.KKException
- an unexpected KKException exceptionpublic int checkCoupon(java.lang.String couponCode) throws com.workingdogs.village.DataSetException, org.apache.torque.TorqueException
checkCoupon
in interface PromotionMgrIf
couponCode
- The coupon codecom.workingdogs.village.DataSetException
- an unexpected exception due to data in Torque (the database layer)org.apache.torque.TorqueException
- an unexpected exception in Torque (the database layer)public ProductIf[] getPromotionsPerProducts(java.lang.String sessionId, int customerId, ProductIf[] products, PromotionIf[] promotions, java.lang.String[] couponCodes, PromotionOptionsIf options) throws java.lang.Exception
getPromotionsPerProducts
in interface PromotionMgrIf
sessionId
- Only used if the customer is logged in. Otherwise set to null.customerId
- If the sessionId is set to null then the customerId should contain the id of the
temporary user which is a negative number. The temporary user id can be used for
evaluating expression rules.products
- An array of products to be processedpromotions
- The promotions which will be applied to the products if all rules are matched.couponCodes
- Coupon codes to use. If none of the promotions require coupons, it should be set
to nulloptions
- An object containing information to configure the calculation for applying one or
more promotion results to the product price.java.lang.Exception
- an unexpected exceptionprotected void processPrice(ProductIf prod, PromotionOptionsIf options)
prod
- the prodoptions
- the optionsprotected void applyDiscount(ProductIf prod, PromotionResultIf promResult, PromotionOptionsIf options)
prod
- the prodpromResult
- the promResultoptions
- the optionsprotected PromotionResultIf[] getPromotionResultArray(PromotionResultIf[] currentArray, PromotionResult newResult)
currentArray
- the currentArraynewResult
- the newResultprotected OrderProduct[] getOrderProductsFromProduct(ProductIf prod) throws java.lang.Exception
prod
- the prodjava.lang.Exception
- an unexpected exceptionprotected int getCustomerId(java.lang.String sessionId, int customerId) throws java.lang.Exception
sessionId
- the sessionIdcustomerId
- the customerIdjava.lang.Exception
- an unexpected exceptionpublic void refreshConfigs() throws java.lang.Exception
PromotionMgrIf
refreshConfigs
in interface PromotionMgrIf
java.lang.Exception
- an unexpected exceptionpublic Coupon[] getCouponsPerCode(java.lang.String couponCode, CouponOptionsIf options) throws java.lang.Exception
The options object allows you to specify that only active coupons should be returned.
getCouponsPerCode
in interface PromotionMgrIf
couponCode
- the couponCodeoptions
- Allows you to specify that only active coupons should be returnedjava.lang.Exception
- an unexpected exceptionpublic Coupon getCouponPerId(int couponId, CouponOptionsIf options) throws java.lang.Exception
The options object allows you to specify that only active coupons should be returned.
getCouponPerId
in interface PromotionMgrIf
couponId
- the couponIdoptions
- Allows you to specify that only active coupons should be returnedjava.lang.Exception
- an unexpected exceptionpublic Promotion[] getPromotionsPerCoupon(java.lang.String couponCode, int couponId, PromotionOptionsIf options) throws java.lang.Exception
The PromotionOptions may be used to control whether or not to use expired coupons and whether or not to return expired promotions. The default is to not check whether coupons or promotions have expired.
If no promotions are found, an empty array is returned.
getPromotionsPerCoupon
in interface PromotionMgrIf
couponCode
- The code of the couponcouponId
- The unique numeric id of the couponoptions
- A PromotionOptions object to control whether or not to use expired coupons and
whether or not to return expired promotionsjava.lang.Exception
- an unexpected exceptionpublic int getPromotionUsageCountMaxRetries()
getPromotionUsageCountMaxRetries
in interface PromotionMgrIf
public void setPromotionUsageCountMaxRetries(int promotionUsageCountMaxRetries)
setPromotionUsageCountMaxRetries
in interface PromotionMgrIf
promotionUsageCountMaxRetries
- the promotionUsageCountMaxRetries to setpublic PromotionIf getPromotion(int promotionId, java.lang.String promotionName, int languageId, FetchPromotionOptionsIf prmOptions, FetchProductOptionsIf prodOptions) throws java.lang.Exception
The purpose of this method is mainly to determine what products, manufacturers or categories
are included or excluded from the promotion in order to be able to display this information
on the storefront. However if the FetchPromotionOptions
is configured to only
return the promotion if active, then we check the following:
couponCodes
attribute of the FetchPromotionOptions
object has been populated and the promotion requires a coupon then we check that at least one
coupon will activate the promotion.getPromotion
in interface PromotionMgrIf
promotionId
- The numeric id of the promotion used to identify it. It should be set to a
negative number in order to search for the promotion using the promotion name.promotionName
- If not set to null, the promotion name is used to search for the promotion instead
of the numeric id.languageId
- The id for the language that will be used when creating the attached products,
categories and manufacturers. Value of -1 selects the default language.prmOptions
- A FetchPromotionOptions object used to configure the API call. It may be set to
null for default functionality.prodOptions
- A FetchProductOptions used to configure the products (if any) attached to the
promotion. It may be set to null for default functionality.java.lang.Exception
- an unexpected exceptionprotected boolean isEnhancedVariantHandlingModeEnabled() throws com.konakart.app.KKException
com.konakart.app.KKException
- an unexpected KKException exceptionCopyright © 2018 DS Data Systems UK Ltd.