Class BasicCartDiscountProcessor
java.lang.Object
com.softslate.commerce.businessobjects.core.BaseBusinessObject
com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
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:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean(package private) static org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddDiscountNotAppliedReason(Discount discount, String reasonCode) voidvoidaddSkuDiscount(Collection skuDiscountsToApply, Discount discount, OrderItem oi) calculateDiscount(Discount discount, Double totalToDiscount, Integer quantity) Calculated the value of a discount as applied to the current user's cart.protected voiddefineDiscountSettings(Product product, Collection attributeSKUCollection, Collection storeDiscounts) Inspects a Product and returns a Map of useful variables related to the state of the product's discounts.excludeGiftCertificateProducts(Discount discount, Double totalToDiscount, Integer quantity) When computing a global discount, exclude the value of any gift certificates that are being purchased if called for by the setting 'excludeGiftCertificatesFromDiscounts'.getDiscountsBySkuIDs(Collection skuIDs) Looks up the total of all of the orders the current user has previously placed.getSkuIDs(OrderItem oi, Collection matchingSkus) getTimesUsedByCustomer(Discount discount) Looks up the number of times the current user has used a givenDiscount.protected booleanhasDiscountBeenAddedToOrder(Order order, Discount discount) booleanisCartItemsOk(Discount discount) Checks that the current user's cart contains the required items to use a givenDiscountbased on its settings.booleanisCouponOk(Discount discount) Checks that a givenDiscounteither is not a coupon, or is a coupon whose code the current user has already entered in the session.booleanisDiscountOk(Discount discount, Double previousOrderTotal) Checks that a given discount is applicable.booleanisDiscountOkIfItemInCart(Discount discount, Double previousOrderTotal, String productCode) Checks if a given discount would be applicable, if the given product code were in the user's cart.booleanisItemWouldAllowDiscount(Discount discount, String productCode) Checks whether the given productCode is among the products that are required to be in the user's cart for theDiscountto apply, based on its settings.booleanisShippingMethodOk(Discount discount) Checks that the current user's cart contains the required shipping method to use a givenDiscountbased on its settings.booleanisStartedAndNotExpired(Discount discount) Checks that the current time is not before a givenDiscount's start date or after its expiration date.booleanisTimesUsedOk(Discount discount) Checks that a givenDiscounthas not been used more than the maximum number of times it's allowed to be used.booleanisUserQualified(Discount discount, Double previousOrderTotal) Checks that the current user is qualified to use a givenDiscountbased on its settings.Returns aCollectionof gift certificateDiscountobjects matching the list of coupon/gift certificate codes that the current user has entered.Returns aCollectionof shipping discounts -Discountobjects matching the list of coupon codes that the current user has entered.processAddItems(Collection newOrderItems) Processes discounts upon adding an item or items to the user's cart.processAfterTaxes(Map parameters) Processes discounts after shipping and taxes have been calculated.processCouponCode(Map parameters) Processes discounts as a user enters a coupon code.processCustomerLogin(Map parameters) Processes discounts as a customer logs in.processCustomerLogout(Map parameters) Processes discounts as a customer logs out.processDiscounts(Collection newOrderItems) Processes discount for the current user and his or her cart.Queries for and applies the gift certs applicable for the user/order.Processes global discounts, which are not associated with specific SKUs.processOnCheckout(Map parameters) Processes discounts during checkout, as taxes and shipping are processed.processOrderComplete(Map parameters) Processes discounts as a user's order is completed.Removes all the discounts in the current user's cart.Queries for and inserts the shipping discounts applicable for the user/order.processShippingDiscountsOnShippingOptions(Collection shippingOptions) Applies shipping discounts to each of the shipping options in the incoming Collection.processSkuDiscounts(Collection orderItems) Processes discounts associated with specific SKUs in the current user's cart.processTimesUsed(int addOrSubtract) voidupdateGiftCertOrderAndDeliveryTotals(Double discountTotal) Subtracts a gift certificate total from the current user's order's total (rather than its subtotal as is the case for other types of discounts).voidupdateOrderAndDeliveryTotals(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, getEventBus, getInjector, getProductIDs, getSettings, getUser, initialize, isProcessorClassActive, loadMatchingSkus, parseDateTime, parseResponseData, prepareRequestData, sendHTTPGet, sendHTTPPost, sendHTTPPost, setAppComponents, setAppSettings, setBusinessObjectFactory, setDaoFactory, setEventBus, setInjector, setSettings, setUser, updateOrderTotals, updateOrderTotals, updateOrderTotals, utilsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.softslate.commerce.businessobjects.core.BusinessObject
initializeMethods inherited from interface com.softslate.commerce.businessobjects.core.BusinessProcessor
getAppComponents, getAppSettings, getBusinessObjectFactory, getDaoFactory, getEventBus, getInjector, getSettings, getUser, setAppComponents, setAppSettings, setBusinessObjectFactory, setDaoFactory, setEventBus, setInjector, setSettings, setUser, utils
-
Field Details
-
log
static org.apache.commons.logging.Log log -
justProcessGiftCertificates
boolean justProcessGiftCertificates
-
-
Constructor Details
-
BasicCartDiscountProcessor
public BasicCartDiscountProcessor()
-
-
Method Details
-
processAddItems
Description copied from interface:CartDiscountProcessorProcesses discounts upon adding an item or items to the user's cart. The default implementation simply callsprocessDiscounts(Collection)- Specified by:
processAddItemsin interfaceCartDiscountProcessor- Parameters:
newOrderItems- The collection ofOrderItemobjects being added to the cart.- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processCouponCode
Description copied from interface:CartDiscountProcessorProcesses discounts as a user enters a coupon code. The default implementation simply callsprocessDiscounts(Collection)- Specified by:
processCouponCodein interfaceCartDiscountProcessor- Parameters:
parameters- AMapwith any parameters needed for the processing. The default implementation does not use this argument.- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processOnCheckout
Description copied from interface:CartDiscountProcessorProcesses discounts during checkout, as taxes and shipping are processed. The default implementation simply callsprocessDiscounts(Collection)- Specified by:
processOnCheckoutin interfaceCartDiscountProcessor- Parameters:
parameters- AMapwith any parameters needed for the processing. The default implementation does not use this argument.- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processAfterTaxes
Description copied from interface:CartDiscountProcessorProcesses discounts after shipping and taxes have been calculated. This is so that if there are any gift certificates, they may be applied against the order's total rather than its subtotal as is the case with regular discounts. The default implementation simply callsprocessDiscounts(Collection)- Specified by:
processAfterTaxesin interfaceCartDiscountProcessor- Parameters:
parameters- AMapwith any parameters needed for the processing. The default implementation does not use this argument.- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processCustomerLogin
Description copied from interface:CartDiscountProcessorProcesses 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 callsprocessDiscounts(Collection)- Specified by:
processCustomerLoginin interfaceCartDiscountProcessor- Parameters:
parameters- AMapwith any parameters needed for the processing. The default implementation does not use this argument.- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processCustomerLogout
Description copied from interface:CartDiscountProcessorProcesses 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 callsprocessDiscounts(Collection)- Specified by:
processCustomerLogoutin interfaceCartDiscountProcessor- Parameters:
parameters- AMapwith any parameters needed for the processing. The default implementation does not use this argument.- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processOrderComplete
Description copied from interface:CartDiscountProcessorProcesses discounts as a user's order is completed. The default implementation simply callsprocessDiscounts(Collection)- Specified by:
processOrderCompletein interfaceCartDiscountProcessor- Parameters:
parameters- AMapwith any parameters needed for the processing. The default implementation does not use this argument.- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processDiscounts
Processes discount for the current user and his or her cart. This method calls the following methods in turn: Note all the discounts already in the user's cart are removed, then added back in.- Parameters:
newOrderItems- TheCollectionofOrderItems in the user's cart.- Returns:
- A
Mapcontaining results of the processing. This implementation returns null. - Throws:
Exception
-
processRemoveDiscounts
Description copied from interface:CartDiscountProcessorRemoves all the discounts in the current user's cart. Updates the cart totals accordingly. Called before items are removed from the cart byBasicCartProcessor.processRemoveItem(OrderItem)- Specified by:
processRemoveDiscountsin interfaceCartDiscountProcessor- Returns:
- A
Mapcontaining results of the processing. The default implementation returns null. - Throws:
Exception
-
processSkuDiscounts
Processes discounts associated with specific SKUs in the current user's cart.- Parameters:
orderItems- TheCollectionofOrderItems in the user's cart.- Returns:
- A
Mapcontaining results of the processing. This implementation returns null. - Throws:
Exception
-
processGlobalDiscounts
Processes global discounts, which are not associated with specific SKUs.- Returns:
- A
Mapcontaining results of the processing. This implementation returns null. - Throws:
Exception
-
processShippingDiscounts
Queries for and inserts the shipping discounts applicable for the user/order. The discount is not actually applied - a zero-total discount is inserted. The discount is actually applied during shipping processing, ie, processShippingDiscountsOnShippingOptions()- Returns:
- A Map, null in this implementation.
- Throws:
Exception
-
hasDiscountBeenAddedToOrder
-
processShippingDiscountsOnShippingOptions
public Collection processShippingDiscountsOnShippingOptions(Collection shippingOptions) throws Exception Description copied from interface:CartDiscountProcessorApplies shipping discounts to each of the shipping options in the incoming Collection.- Specified by:
processShippingDiscountsOnShippingOptionsin interfaceCartDiscountProcessor- Returns:
- the same Collection of shipping options, with discounts applied
- Throws:
Exception
-
processGiftCertificates
Queries for and applies the gift certs applicable for the user/order.- Returns:
- A Map, null in this implementation.
- Throws:
Exception
-
processTimesUsed
- Throws:
Exception
-
processTimesUsed
- Throws:
Exception
-
getSkuIDs
-
getDiscountsBySkuIDs
-
getGlobalDiscounts
Returns aCollectionof globalDiscountobjects that are not associated with a particularSKU. Used during global discount processing. -
loadShippingDiscounts
Returns aCollectionof shipping discounts -Discountobjects matching the list of coupon codes that the current user has entered. Used during discount processing. -
loadGiftCertificates
Returns aCollectionof gift certificateDiscountobjects matching the list of coupon/gift certificate codes that the current user has entered. Used during discount processing. -
isDiscountOk
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:
- Specified by:
isDiscountOkin interfaceCartDiscountProcessor- 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:
Exception
-
isDiscountOkIfItemInCart
public boolean isDiscountOkIfItemInCart(Discount discount, Double previousOrderTotal, String productCode) throws Exception Checks if a given discount would be applicable, if the given product code were in the user's cart. Used by the presentation layer to communicate the discounts that would be available if the item were added to the cart.This method calls the following methods in turn:
- Specified by:
isDiscountOkIfItemInCartin interfaceCartDiscountProcessor- 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:
Exception
-
isStartedAndNotExpired
Checks that the current time is not before a givenDiscount's start date or after its expiration date.- Parameters:
discount- TheDiscountto check.- Returns:
- true, if the current time is not before the
Discount's start date or after its expiration date. - Throws:
Exception
-
isTimesUsedOk
Checks that a givenDiscounthas not been used more than the maximum number of times it's allowed to be used.- Parameters:
discount- TheDiscountto check.- Returns:
- true, if the
Discounthas not been used more than the maximum number of times it's allowed to be used. - Throws:
Exception
-
isCouponOk
Checks that a givenDiscounteither is not a coupon, or is a coupon whose code the current user has already entered in the session.- Parameters:
discount- TheDiscountto check.- Returns:
- true, if the
Discounteither is not a coupon, or is a coupon whose code the current user has already entered in the session. - Throws:
Exception- See Also:
-
isUserQualified
Checks that the current user is qualified to use a givenDiscountbased on its settings.- Parameters:
discount- TheDiscountto 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:
Exception
-
isCartItemsOk
Checks that the current user's cart contains the required items to use a givenDiscountbased on its settings.- Parameters:
discount- TheDiscountto check.- Returns:
- true, if the current user is qualified to use the
Discount. - Throws:
Exception
-
isShippingMethodOk
Checks that the current user's cart contains the required shipping method to use a givenDiscountbased on its settings.- Parameters:
discount- TheDiscountto check.- Returns:
- true, if the current user is qualified to use the
Discount. - Throws:
Exception
-
isItemWouldAllowDiscount
Checks whether the given productCode is among the products that are required to be in the user's cart for theDiscountto apply, based on its settings.- Parameters:
discount- TheDiscountto check.- Returns:
- true, if the current user is qualified to use the
Discount. - Throws:
Exception
-
getPreviousOrderTotal
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:
Exception
-
getTimesUsedByCustomer
Looks up the number of times the current user has used a givenDiscount.- Parameters:
discount- TheDiscountto check.- Returns:
- An
Integerrepresenting the number of times the current user has used theDiscount. - Throws:
Exception
-
clearDiscountNotAppliedReasons
protected void clearDiscountNotAppliedReasons() -
addDiscountNotAppliedReason
-
calculateDiscount
Calculated the value of a discount as applied to the current user's cart.- Parameters:
discount- TheDiscountto 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 anOrderItemin the user's cart. Some discounts are applied according toDiscountRangethat corresponds to the total number of items in the user's cart (in the case of global discounts), or the quantity of anOrderItemcorreponding to aSKUassociated with the discount (in the case ofSKUdiscounts).- Returns:
- A
Mapwith information about the discount, and a key named "discountTotal", holding the calculated value of the discount.
-
excludeGiftCertificateProducts
public Double excludeGiftCertificateProducts(Discount discount, Double totalToDiscount, Integer quantity) When computing a global discount, exclude the value of any gift certificates that are being purchased if called for by the setting 'excludeGiftCertificatesFromDiscounts'.- Parameters:
discount-totalToDiscount-quantity-- Returns:
- Updated totalToDiscount that does not include the value of Gift Certificates
-
updateOrderAndDeliveryTotals
Subtracts a discount total from the current user's order.- Parameters:
discountTotal- The discount total to subtract.
-
updateGiftCertOrderAndDeliveryTotals
Subtracts a gift certificate total from the current user's order's total (rather than its subtotal as is the case for other types of discounts).- Parameters:
discountTotal- The discount total to subtract.
-
addSkuDiscount
-
addOrderItemToSkuDiscount
-
defineDiscountSettings
public Map defineDiscountSettings(Product product, Collection attributeSKUCollection, Collection storeDiscounts) throws Exception Description copied from interface:CartDiscountProcessorInspects a Product and returns a Map of useful variables related to the state of the product's discounts.- Specified by:
defineDiscountSettingsin interfaceCartDiscountProcessorattributeSKUCollection- An optional Collection of attribute-only SKUs used to define the inventory settings that are returned.storeDiscounts- An optional Collection of global, store discounts, used to determine if "promotions" for the product exist, ie, discounts that would be applied if the product were added to the cart.- Returns:
- A Map of variables related to the product's discounts.
- Throws:
Exception
-