com.konakart.bl
Class PromotionMgr

java.lang.Object
  extended by com.konakart.bl.BaseMgr
      extended by com.konakart.bl.PromotionMgr
All Implemented Interfaces:
PromotionMgrIf

public class PromotionMgr
extends BaseMgr
implements PromotionMgrIf

Promotions Manager


Nested Class Summary
protected  class PromotionMgr.StaticData
          Used to store the static data of this manager
 
Field Summary
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
           
protected static int PROMOTION_RELATION_TYPE
          Constant for Promotion To Product Relation
protected static java.util.Map<java.lang.String,PromotionMgr.StaticData> staticDataHM
          Hash Map that contains the static data
 
Fields inherited from class com.konakart.bl.BaseMgr
templateBaseDir
 
Constructor Summary
PromotionMgr(KKEngIf eng)
          Constructor
 
Method Summary
protected  void applyDiscount(ProductIf prod, PromotionResultIf promResult, PromotionOptionsIf options)
          Apply the promotion discount to a product
protected  int checkCategory(Promotion prm, ProductIf prod)
          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)
          We check to see whether the expression evaluates to TRUE
protected  int checkManufacturer(Promotion prm, ProductIf prod)
          We check to see whether the product manufacturer is a manufacturer that can use the promotion.
protected  int checkProduct(Promotion prm, OrderProductIf orderProd)
          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
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.
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  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.
protected  Promotion[] getPromotionsPerOrderTotalCode(java.lang.String orderTotalCode)
          The promotions related to the orderTotalCode passed in as a parameter, are fetched from the database.
 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 insertCoupon(CouponIf coupon, int promotionId)
          Insert a coupon and associate it with the promotion referenced by promotionId.
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(org.apache.torque.util.Criteria c)
          Set the criteria object with all of the attributes for a coupon
protected  void setPromotionCriteriaWithStandardAttributes(org.apache.torque.util.Criteria c)
          Set the criteria object with all of the attributes for a promotion
 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
 
Methods inherited from class com.konakart.bl.BaseMgr
addInsertAttr, addInsertAttr, checkRequired, getAdminEngMgr, getBasketMgr, getBillingMgr, getBookableProductMgr, getCatMgr, getConfigMgr, getCookieMgr, getCurrMgr, getCustMgr, getCustomerIdFromSession, getCustomerStatsMgr, getCustomerTagMgr, getEmailMgr, getEng, getLangMgr, getManuMgr, getMiscItemMgr, getMode, getModeString, getMqMgr, getMultiStoreMgr, getNewCriteria, getNewCriteria, getOrderMgr, getOrderTotalMgr, getPaymentMgr, getProdMgr, getPromMgr, getRewardPointMgr, getSecMgr, getShippingMgr, getSolrMgr, getStoreId, getTaxMgr, getTemplate, getTemplateRoot, getVelocityContextMgr, getWishListMgr, init, isEnterprise, isMultiStoreShareCustomers, isMultiStoreShareProducts
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log
the log


mutex

protected static java.lang.String mutex

staticDataHM

protected static java.util.Map<java.lang.String,PromotionMgr.StaticData> staticDataHM
Hash Map that contains the static data


ALL

public static final int ALL
Constant for Promotion Rule

See Also:
Constant Field Values

EXCLUDE

public static final int EXCLUDE
Constant for Promotion Rule

See Also:
Constant Field Values

INCLUDE

public static final int INCLUDE
Constant for Promotion Rule

See Also:
Constant Field Values

PROMOTION_RELATION_TYPE

protected static final int PROMOTION_RELATION_TYPE
Constant for Promotion To Product Relation

See Also:
Constant Field Values

GIFT_CERTIFICATE_RELATION_TYPE

protected static final int GIFT_CERTIFICATE_RELATION_TYPE
Constant for Promotion To Product Relation

See Also:
Constant Field Values

COUPON_DOESNT_EXIST

public static final int COUPON_DOESNT_EXIST
Coupon doesn't exist

See Also:
Constant Field Values

COUPON_EXISTS_ACTIVE

public static final int COUPON_EXISTS_ACTIVE
Coupon exists and is active

See Also:
Constant Field Values

COUPON_EXISTS_INACTIVE

public static final int COUPON_EXISTS_INACTIVE
Coupon exists but is no longer active

See Also:
Constant Field Values
Constructor Detail

PromotionMgr

public PromotionMgr(KKEngIf eng)
             throws java.lang.Exception
Constructor

Parameters:
eng -
Throws:
java.lang.Exception
Method Detail

getPromotions

public Promotion[] getPromotions(java.lang.String orderTotalCode,
                                 Order order)
                          throws java.lang.Exception
We return all active promotions for the orderTotalCode passed in as a parameter. The promotion may only apply for a subset of the products within the order so we return this information as an attribute of the Promotion object.

Specified by:
getPromotions in interface PromotionMgrIf
Parameters:
orderTotalCode -
order -
Returns:
An array of promotion objects
Throws:
java.lang.Exception

getAllPromotions

public Promotion[] getAllPromotions()
                             throws java.lang.Exception
Returns an array of all active promotions

Specified by:
getAllPromotions in interface PromotionMgrIf
Returns:
Returns an array of all active promotions
Throws:
java.lang.Exception

checkPromotion

protected boolean checkPromotion(Promotion prm)
Checks the validity of the promotion object.

Parameters:
prm -
Returns:
Returns true if valid. Otherwise false.

checkCustomer

protected int checkCustomer(Promotion prm,
                            int customerId)
                     throws com.workingdogs.village.DataSetException,
                            org.apache.torque.TorqueException
We check to see whether the customer submitting the order is a customer that can use the promotion. He may have to be included explicitly or may have been excluded.

Parameters:
prm -
customerId -
Returns:
Returns 0 if the customer can use the promotion. Otherwise a negative number.
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

checkCustomerUse

protected int checkCustomerUse(Promotion prm,
                               int customerId)
                        throws com.workingdogs.village.DataSetException,
                               org.apache.torque.TorqueException
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.

Parameters:
prm -
customerId -
Returns:
Returns 0 if the customer can use the promotion. Otherwise a negative number.
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

checkCustomerGroup

protected int checkCustomerGroup(Promotion prm,
                                 int customerId)
                          throws java.lang.Exception
We check to see whether the group of the customer submitting the order is a group that can use the promotion.

Parameters:
prm -
customerId -
Returns:
Returns 0 if the customer can use the promotion. Otherwise a negative number.
Throws:
java.lang.Exception

checkManufacturer

protected int checkManufacturer(Promotion prm,
                                ProductIf prod)
                         throws com.workingdogs.village.DataSetException,
                                org.apache.torque.TorqueException
We check to see whether the product manufacturer is a manufacturer that can use the promotion.

Parameters:
prm -
prod -
Returns:
Returns 0 if the manufacturer can use the promotion. Otherwise a negative number.
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

checkProduct

protected int checkProduct(Promotion prm,
                           OrderProductIf orderProd)
                    throws com.workingdogs.village.DataSetException,
                           org.apache.torque.TorqueException
We check to see whether the product is a product that can use the promotion. The order product may contain an array of options so we have to consider each option separately.

Parameters:
prm -
orderProd -
Returns:
Returns 0 if the orderProd can use the promotion. Otherwise a negative number.
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

checkCategory

protected int checkCategory(Promotion prm,
                            ProductIf prod)
                     throws java.lang.Exception
We check to see whether the product category is a category that can use the promotion.

Parameters:
prm -
prod -
Returns:
Returns 0 if the category can use the promotion. Otherwise a negative number.
Throws:
java.lang.Exception

checkCoupon

protected int checkCoupon(Promotion prm,
                          Order order)
                   throws com.workingdogs.village.DataSetException,
                          org.apache.torque.TorqueException
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. When we find a valid coupon, we attach it to the promotion.

Parameters:
prm -
order -
Returns:
Returns 0 if the order coupon code matches a valid active coupon for the promotion. Otherwise a negative number.
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

checkCoupon

protected int checkCoupon(Promotion prm,
                          java.lang.String[] coupons)
                   throws com.workingdogs.village.DataSetException,
                          org.apache.torque.TorqueException
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. When we find a valid coupon, we attach it to the promotion.

Parameters:
prm -
coupons -
Returns:
Returns 0 if the coupon code matches a valid active coupon for the promotion. Otherwise a negative number.
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

checkExpression

protected int checkExpression(Promotion prm,
                              int customerId)
                       throws java.lang.Exception
We check to see whether the expression evaluates to TRUE

Parameters:
prm -
customerId -
Returns:
Returns 0 if the expression evaluates to TRUE or doesn't exist. Otherwise a negative number.
Throws:
java.lang.Exception

getPromotionsPerOrderTotalCode

protected Promotion[] getPromotionsPerOrderTotalCode(java.lang.String orderTotalCode)
                                              throws com.workingdogs.village.DataSetException,
                                                     org.apache.torque.TorqueException
The promotions related to the orderTotalCode passed in as a parameter, are fetched from the database. They are then added to the return array if they are active.

Parameters:
orderTotalCode -
Returns:
Returns an array of promotion objects
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

updatePromotionUsage

public void updatePromotionUsage(Order order)
                          throws org.apache.torque.TorqueException,
                                 com.workingdogs.village.DataSetException
If the order has any associated coupons we iterate through the coupons and increment the timesUsed attribute. If the order has any associated promotions that were linked to the customer directly through the promotion_to_customer table, then we retrieve these records and increment the timesUsed attribute.

Specified by:
updatePromotionUsage in interface PromotionMgrIf
Parameters:
order -
Throws:
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException

setPromotionCriteriaWithStandardAttributes

protected void setPromotionCriteriaWithStandardAttributes(org.apache.torque.util.Criteria c)
Set the criteria object with all of the attributes for a promotion

Parameters:
c -

setCouponCriteriaWithStandardAttributes

protected void setCouponCriteriaWithStandardAttributes(org.apache.torque.util.Criteria c)
Set the criteria object with all of the attributes for a coupon

Parameters:
c -

getPromotionIdForGiftCertificate

public int getPromotionIdForGiftCertificate(OrderProductIf op)
                                     throws KKException,
                                            org.apache.torque.TorqueException,
                                            com.workingdogs.village.DataSetException
Get the promotion id for an order product object containing a gift certificate. A negative id is returned if a promotion doesn't exist.

Specified by:
getPromotionIdForGiftCertificate in interface PromotionMgrIf
Parameters:
op -
Returns:
Returns the id of the promotion or -1 if a promotion doesn't exist.
Throws:
KKException
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException

getPromotionIdForGiftCertificate

protected int getPromotionIdForGiftCertificate(int productId,
                                               int productOptionId,
                                               int productOptionValueId)
                                        throws org.apache.torque.TorqueException,
                                               com.workingdogs.village.DataSetException
Protected method for common code to get the promotion id of a promotion connected to a gift certificate. There should only be one promotion.

Parameters:
productId -
productOptionId -
productOptionValueId -
Returns:
Returns the id of the promotion
Throws:
org.apache.torque.TorqueException
com.workingdogs.village.DataSetException

insertCoupon

public int insertCoupon(CouponIf coupon,
                        int promotionId)
                 throws java.lang.Exception
Insert a coupon and associate it with the promotion referenced by promotionId. If the promotionId is a negative number then no association is done.

Specified by:
insertCoupon in interface PromotionMgrIf
Parameters:
coupon -
promotionId -
Returns:
Returns the couponId
Throws:
java.lang.Exception

validateCoupon

protected void validateCoupon(CouponIf coupon)
                       throws KKException
Used to validate a coupon before inserting

Parameters:
coupon -
Throws:
KKException

checkCoupon

public int checkCoupon(java.lang.String couponCode)
                throws com.workingdogs.village.DataSetException,
                       org.apache.torque.TorqueException
This method is used to verify whether a coupon code actually exists and if it does, whether the coupon is still active. Valid return values for this method are: Even if the coupon exists and is active, it won't actually do anything if it isn't connected to a valid promotion and any rules associated with the promotion are also satisfied. However, this method may still be used to at least warn a customer that he may have mistyped the coupon code or that it is no longer valid.

Specified by:
checkCoupon in interface PromotionMgrIf
Parameters:
couponCode - The coupon code
Returns:
Returns an integer
Throws:
com.workingdogs.village.DataSetException
org.apache.torque.TorqueException

getPromotionsPerProducts

public ProductIf[] getPromotionsPerProducts(java.lang.String sessionId,
                                            int customerId,
                                            ProductIf[] products,
                                            PromotionIf[] promotions,
                                            java.lang.String[] couponCodes,
                                            PromotionOptionsIf options)
                                     throws java.lang.Exception
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. The PromotionResult contains the value of the discount, whether it is an amount or a percentage discount and also information regarding the promotion it applies to. If a product has an array of ProductQuantity objects (one for each SKU) each one of these may have an array of PromotionResult objects since a promotion may only apply to one product configuration and not to another (i.e. blue shirt and not red shirt).
The PromotionOptions object can be configured so that the values of the promotions for a product are subtracted from the product price. The options allow you to set rules that determine whether in this case the promotions need to be cumulative or whether the largest or smallest should be chosen. The calculation is only made for products with a single array of PromotionResult objects. It is not calculated for products that have an array of PromotionResult objects for each ProductQuantity.

Specified by:
getPromotionsPerProducts in interface PromotionMgrIf
Parameters:
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 processed
promotions - 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 null
options - An object containing information to configure the calculation for applying one or more promotion results to the product price.
Returns:
Returns the same array of products passed in as a parameter with attached PromotionResult objects if applicable
Throws:
java.lang.Exception

processPrice

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

Parameters:
prod -
options -

applyDiscount

protected void applyDiscount(ProductIf prod,
                             PromotionResultIf promResult,
                             PromotionOptionsIf options)
Apply the promotion discount to a product

Parameters:
prod -
promResult -
options -

getPromotionResultArray

protected PromotionResultIf[] getPromotionResultArray(PromotionResultIf[] currentArray,
                                                      PromotionResult newResult)
Utility method to add a PromotionResult object on to the end of an array

Parameters:
currentArray -
newResult -
Returns:
Returns an array of PromotionResult objects

getOrderProductsFromProduct

protected OrderProduct[] getOrderProductsFromProduct(ProductIf prod)
                                              throws java.lang.Exception
Creates OrderProducts from a product so that we can reuse the checkProduct() method.

Parameters:
prod -
Returns:
Returns an array of OrderProduct objects
Throws:
java.lang.Exception

getCustomerId

protected int getCustomerId(java.lang.String sessionId,
                            int customerId)
                     throws java.lang.Exception
If the sessionId is null, we check the customerId to ensure that it is negative. If it is negative, this means that it is a non registered customer or a customer that hasn't logged in yet and so there is no customer mapped to the session id. Otherwise we ensure that the sessionId is valid and we don't use the customerId because we get the id from the session.

Parameters:
sessionId -
customerId -
Returns:
Returns the customerId that should be used by the caller
Throws:
java.lang.Exception

refreshConfigs

public void refreshConfigs()
                    throws java.lang.Exception
Description copied from interface: PromotionMgrIf
Refresh the configuration of the Promotion manager

Specified by:
refreshConfigs in interface PromotionMgrIf
Throws:
java.lang.Exception


Copyright © 2011 DS Data Systems UK Ltd.