com.softslate.commerce.businessobjects.order
Class BasicCartDiscountProcessor

java.lang.Object
  extended by com.softslate.commerce.businessobjects.core.BaseBusinessObject
      extended by com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
          extended by com.softslate.commerce.businessobjects.order.BasicCartDiscountProcessor
All Implemented Interfaces:
BusinessObject, BusinessProcessor, CartDiscountProcessor

public class BasicCartDiscountProcessor
extends BaseBusinessProcessor
implements CartDiscountProcessor

Processes business logic having to do with discounts in a user's cart.

BasicCartDiscountProcessor is the default implementation of the CartDiscountProcessor interface for the application.

Author:
David Tobey
See Also:
InventoryProcessor

Field Summary
(package private) static org.apache.commons.logging.Log log
           
 
Constructor Summary
BasicCartDiscountProcessor()
           
 
Method Summary
 java.util.Map calculateDiscount(Discount discount, java.lang.Double totalToDiscount, java.lang.Integer quantity)
          Calculated the value of a discount as applied to the current user's cart.
 java.util.Collection getDiscountsBySkuIDs(java.util.Collection skuIDs)
          Returns a Collection of Discount objects associated with the given Collection of SKU ids.
 java.util.Collection getGlobalDiscounts()
          Returns a Collection of global Discount objects that are not associated with a particular SKU.
 java.lang.Double getPreviousOrderTotal()
          Looks up the total of all of the orders the current user has previously placed.
 java.util.Collection getSkuIDs(OrderItem oi, java.util.Collection matchingSkus)
           
 java.lang.Integer getTimesUsedByCustomer(Discount discount)
          Looks up the number of times the current user has used a given Discount.
 boolean isCouponOk(Discount discount)
          Checks that a given Discount either is not a coupon, or is a coupon whose code the current user has already entered in the session.
 boolean isDiscountOk(Discount discount, java.lang.Double previousOrderTotal)
          Checks that a given discount is applicable.
 boolean isStartedAndNotExpired(Discount discount)
          Checks that the current time is not before a given Discount's start date or after its expiration date.
 boolean isTimesUsedOk(Discount discount)
          Checks that a given Discount has not been used more than the maximum number of times it's allowed to be used.
 boolean isUserQualified(Discount discount, java.lang.Double previousOrderTotal)
          Checks that the current user is qualified to use a given Discount based on its settings.
 java.util.Map processAddItems(java.util.Collection newOrderItems)
          Processes discounts upon adding an item or items to the user's cart.
 java.util.Map processCouponCode(java.util.Map parameters)
          Processes discounts as a user enters a coupon code.
 java.util.Map processCustomerLogin(java.util.Map parameters)
          Processes discounts as a customer logs in.
 java.util.Map processCustomerLogout(java.util.Map parameters)
          Processes discounts as a customer logs out.
 java.util.Map processDiscounts(java.util.Collection newOrderItems, boolean updateTimesUsed)
          Processes discount for the current user and his or her cart.
 java.util.Map processGlobalDiscounts(boolean updateTimesUsed)
          Processes global discounts, which are not associated with specific SKUs.
 java.util.Map processOnCheckout(java.util.Map parameters)
          Processes discounts during checkout, as taxes and shipping are processed.
 java.util.Map processOrderComplete(java.util.Map parameters)
          Processes discounts as a user's order is completed.
 java.util.Map processRemoveDiscounts()
          Removes all the discounts in the current user's cart.
 java.util.Map processSkuDiscounts(java.util.Collection orderItems, boolean updateTimesUsed)
          Processes discounts associated with specific SKUs in the current user's cart.
 void updateOrderAndDeliveryTotals(java.lang.Double discountTotal)
          Subtracts a discount total from the current user's order.
 
Methods inherited from class com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
formatDateTime, formatPrice, getAppComponents, getAppSettings, getAttributeIDs, getBusinessObjectFactory, getDaoFactory, getProductIDs, getSettings, getUser, initialize, loadMatchingSkus, parseDateTime, parseResponseData, prepareRequestData, sendHTTPPost, setAppComponents, setAppSettings, setBusinessObjectFactory, setDaoFactory, setSettings, setUser, utils
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static org.apache.commons.logging.Log log
Constructor Detail

BasicCartDiscountProcessor

public BasicCartDiscountProcessor()
Method Detail

processAddItems

public java.util.Map processAddItems(java.util.Collection newOrderItems)
                              throws java.lang.Exception
Description copied from interface: CartDiscountProcessor
Processes discounts upon adding an item or items to the user's cart. The default implementation simply calls processDiscounts(Collection, boolean)

Specified by:
processAddItems in interface CartDiscountProcessor
Parameters:
newOrderItems - The collection of OrderItem objects being added to the cart.
Returns:
A Map containing results of the processing. The default implementation returns null.
Throws:
java.lang.Exception

processCouponCode

public java.util.Map processCouponCode(java.util.Map parameters)
                                throws java.lang.Exception
Description copied from interface: CartDiscountProcessor
Processes discounts as a user enters a coupon code. The default implementation simply calls processDiscounts(Collection, boolean)

Specified by:
processCouponCode in interface CartDiscountProcessor
Parameters:
parameters - A Map with any parameters needed for the processing. The default implementation does not use this argument.
Returns:
A Map containing results of the processing. The default implementation returns null.
Throws:
java.lang.Exception

processOnCheckout

public java.util.Map processOnCheckout(java.util.Map parameters)
                                throws java.lang.Exception
Description copied from interface: CartDiscountProcessor
Processes discounts during checkout, as taxes and shipping are processed. The default implementation simply calls processDiscounts(Collection, boolean)

Specified by:
processOnCheckout in interface CartDiscountProcessor
Parameters:
parameters - A Map with any parameters needed for the processing. The default implementation does not use this argument.
Returns:
A Map containing results of the processing. The default implementation returns null.
Throws:
java.lang.Exception

processCustomerLogin

public java.util.Map processCustomerLogin(java.util.Map parameters)
                                   throws java.lang.Exception
Description copied from interface: CartDiscountProcessor
Processes discounts as a customer logs in. Some discounts only apply if the user is logged in as a customer, so discounts must be rerun. The default implementation simply calls processDiscounts(Collection, boolean)

Specified by:
processCustomerLogin in interface CartDiscountProcessor
Parameters:
parameters - A Map with any parameters needed for the processing. The default implementation does not use this argument.
Returns:
A Map containing results of the processing. The default implementation returns null.
Throws:
java.lang.Exception

processCustomerLogout

public java.util.Map processCustomerLogout(java.util.Map parameters)
                                    throws java.lang.Exception
Description copied from interface: CartDiscountProcessor
Processes discounts as a customer logs out. Some discounts only apply if the user is logged in as a customer, so discounts must be rerun. The default implementation simply calls processDiscounts(Collection, boolean)

Specified by:
processCustomerLogout in interface CartDiscountProcessor
Parameters:
parameters - A Map with any parameters needed for the processing. The default implementation does not use this argument.
Returns:
A Map containing results of the processing. The default implementation returns null.
Throws:
java.lang.Exception

processOrderComplete

public java.util.Map processOrderComplete(java.util.Map parameters)
                                   throws java.lang.Exception
Description copied from interface: CartDiscountProcessor
Processes discounts as a user's order is completed. The default implementation simply calls processDiscounts(Collection, boolean)

Specified by:
processOrderComplete in interface CartDiscountProcessor
Parameters:
parameters - A Map with any parameters needed for the processing. The default implementation does not use this argument.
Returns:
A Map containing results of the processing. The default implementation returns null.
Throws:
java.lang.Exception

processDiscounts

public java.util.Map processDiscounts(java.util.Collection newOrderItems,
                                      boolean updateTimesUsed)
                               throws java.lang.Exception
Processes discount for the current user and his or her cart. This method calls the following methods in turn:
  1. processRemoveDiscounts()
  2. processSkuDiscounts(Collection, boolean)
  3. processGlobalDiscounts(boolean)
Note all the discounts already in the user's cart are removed, then added back in.

Parameters:
newOrderItems - The Collection of OrderItems in the user's cart.
updateTimesUsed - true, if the discount is being recorded upon order completion and the number of times it's been used should be updated.
Returns:
A Map containing results of the processing. This implementation returns null.
Throws:
java.lang.Exception

processRemoveDiscounts

public java.util.Map processRemoveDiscounts()
                                     throws java.lang.Exception
Description copied from interface: CartDiscountProcessor
Removes all the discounts in the current user's cart. Updates the cart totals accordingly. Called before items are removed from the cart by BasicCartProcessor.processRemoveItem(OrderItem)

Specified by:
processRemoveDiscounts in interface CartDiscountProcessor
Returns:
A Map containing results of the processing. The default implementation returns null.
Throws:
java.lang.Exception

processSkuDiscounts

public java.util.Map processSkuDiscounts(java.util.Collection orderItems,
                                         boolean updateTimesUsed)
                                  throws java.lang.Exception
Processes discounts associated with specific SKUs in the current user's cart.

Parameters:
orderItems - The Collection of OrderItems in the user's cart.
updateTimesUsed - true, if the discount is being recorded upon order completion and the number of times it's been used should be updated.
Returns:
A Map containing results of the processing. This implementation returns null.
Throws:
java.lang.Exception

processGlobalDiscounts

public java.util.Map processGlobalDiscounts(boolean updateTimesUsed)
                                     throws java.lang.Exception
Processes global discounts, which are not associated with specific SKUs.

Parameters:
updateTimesUsed - true, if the discount is being recorded upon order completion and the number of times it's been used should be updated.
Returns:
A Map containing results of the processing. This implementation returns null.
Throws:
java.lang.Exception

getSkuIDs

public java.util.Collection getSkuIDs(OrderItem oi,
                                      java.util.Collection matchingSkus)

getDiscountsBySkuIDs

public java.util.Collection getDiscountsBySkuIDs(java.util.Collection skuIDs)
                                          throws java.lang.Exception
Returns a Collection of Discount objects associated with the given Collection of SKU ids. Used during SKU discount processing.

Parameters:
skuIDs - A Collection of SKU ids.
Returns:
A Collection of Discount objects
Throws:
java.lang.Exception

getGlobalDiscounts

public java.util.Collection getGlobalDiscounts()
                                        throws java.lang.Exception
Returns a Collection of global Discount objects that are not associated with a particular SKU. Used during global discount processing.

Returns:
A Collection of Discount objects
Throws:
java.lang.Exception

isDiscountOk

public boolean isDiscountOk(Discount discount,
                            java.lang.Double previousOrderTotal)
                     throws java.lang.Exception
Checks that a given discount is applicable. Used by discount processing to help determine which discounts to apply, and in the presentation to determine which discounts to display to the user.

This method calls the following methods in turn:

  1. isStartedAndNotExpired(Discount)
  2. isCouponOk(Discount)
  3. isUserQualified(Discount, Double)
  4. isTimesUsedOk(Discount)

Specified by:
isDiscountOk in interface CartDiscountProcessor
Parameters:
discount - The discount whose applicability is being checked.
previousOrderTotal - The previous order total of the current user, or null. Some discount are only applicable if the user has previously placed orders totaling a certain amount.
Returns:
true, the discount is applicable, otherwise, false.
Throws:
java.lang.Exception

isStartedAndNotExpired

public boolean isStartedAndNotExpired(Discount discount)
                               throws java.lang.Exception
Checks that the current time is not before a given Discount's start date or after its expiration date.

Parameters:
discount - The Discount to check.
Returns:
true, if the current time is not before the Discount's start date or after its expiration date.
Throws:
java.lang.Exception

isTimesUsedOk

public boolean isTimesUsedOk(Discount discount)
                      throws java.lang.Exception
Checks that a given Discount has not been used more than the maximum number of times it's allowed to be used.

Parameters:
discount - The Discount to check.
Returns:
true, if the Discount has not been used more than the maximum number of times it's allowed to be used.
Throws:
java.lang.Exception

isCouponOk

public boolean isCouponOk(Discount discount)
                   throws java.lang.Exception
Checks that a given Discount either is not a coupon, or is a coupon whose code the current user has already entered in the session.

Parameters:
discount - The Discount to check.
Returns:
true, if the Discount either is not a coupon, or is a coupon whose code the current user has already entered in the session.
Throws:
java.lang.Exception
See Also:
User.getEnteredCouponCodes()

isUserQualified

public boolean isUserQualified(Discount discount,
                               java.lang.Double previousOrderTotal)
                        throws java.lang.Exception
Checks that the current user is qualified to use a given Discount based on its settings.

Parameters:
discount - The Discount to check.
previousOrderTotal - The previous order total of the current user, or null. Some discounts are only applicable if the user has previously placed orders totalling a certain amount.
Returns:
true, if the current user is qualified to use the Discount.
Throws:
java.lang.Exception

getPreviousOrderTotal

public java.lang.Double getPreviousOrderTotal()
                                       throws java.lang.Exception
Looks up the total of all of the orders the current user has previously placed. Used to determine if certain discount are applicable.

Returns:
The total of all of the orders the current user has previously placed.
Throws:
java.lang.Exception

getTimesUsedByCustomer

public java.lang.Integer getTimesUsedByCustomer(Discount discount)
                                         throws java.lang.Exception
Looks up the number of times the current user has used a given Discount.

Parameters:
discount - The Discount to check.
Returns:
An Integer representing the number of times the current user has used the Discount.
Throws:
java.lang.Exception

calculateDiscount

public java.util.Map calculateDiscount(Discount discount,
                                       java.lang.Double totalToDiscount,
                                       java.lang.Integer quantity)
Calculated the value of a discount as applied to the current user's cart.

Parameters:
discount - The Discount to be applied.
totalToDiscount - The total that the discount is to be applied against. Discounts are not allowed to be more than the amount they are being applied against.
quantity - The total number of items in the user's cart, or the quantity of an OrderItem in the user's cart. Some discounts are applied according to DiscountRange that corresponds to the total number of items in the user's cart (in the case of global discounts), or the quantity of an OrderItem correponding to a SKU associated with the discount (in the case of SKU discounts).
Returns:
A Map with information about the discount, and a key named "discountTotal", holding the calculated value of the discount.

updateOrderAndDeliveryTotals

public void updateOrderAndDeliveryTotals(java.lang.Double discountTotal)
Subtracts a discount total from the current user's order.

Parameters:
discountTotal - The discount total to subtract.


Copyright ? SoftSlate, LLC 2003?2005