org.broadleafcommerce.offer.service
Class OfferServiceImpl

java.lang.Object
  extended by org.broadleafcommerce.offer.service.OfferServiceImpl
All Implemented Interfaces:
OfferService

@Service(value="blOfferService")
public class OfferServiceImpl
extends java.lang.Object
implements OfferService

The Class OfferServiceImpl.


Field Summary
protected  CustomerOfferDao customerOfferDao
           
protected  OfferCodeDao offerCodeDao
           
protected  OfferDao offerDao
           
 
Constructor Summary
OfferServiceImpl()
           
 
Method Summary
protected  void applyAllFulfillmentGroupOffers(java.util.List<CandidateFulfillmentGroupOffer> fulfillmentGroupOffers, FulfillmentGroup fulfillmentGroup)
          Private method that takes a list of sorted CandidateFulfillmentGroupOffer and determines if each offer can be applied based on the restrictions (stackable and/or combinable) on that offer.
protected  boolean applyAllItemOffers(java.util.List<CandidateItemOffer> itemOffers, java.util.List<DiscreteOrderItem> discreteOrderItems)
          Private method that takes a list of sorted CandidateItemOffers and determines if each offer can be applied based on the restrictions (stackable and/or combinable) on that offer.
protected  boolean applyAllOrderOffers(java.util.List<CandidateOrderOffer> orderOffers, Order order)
          Private method that takes a list of sorted CandidateOrderOffers and determines if each offer can be applied based on the restrictions (stackable and/or combinable) on that offer.
protected  void applyFulfillmentGroupOffer(CandidateFulfillmentGroupOffer fulfillmentGroupOffer)
          Private method used by applyAllFulfillmentGroupOffers to create an FulfillmentGroupAdjustment from a CandidateFulfillmentGroupOffer and associates the FulfillmentGroupAdjustment to the Order.
 void applyFulfillmentGroupOffers(FulfillmentGroup fulfillmentGroup)
          Apply offers for a fulfillmentGroup
 void applyFulfillmentGroupsOffers(java.util.List<FulfillmentGroup> fulfillmentGroups)
          Apply offers for a List of FulfillmentGroup
 void applyOffersToOrder(java.util.List<Offer> offers, Order order)
          Apply offers to order.
protected  void applyOrderItemOffer(CandidateItemOffer itemOffer)
          Private method used by applyAllItemOffers to create an OrderItemAdjustment from a CandidateItemOffer and associates the OrderItemAdjustment to the OrderItem.
protected  void applyOrderOffer(CandidateOrderOffer orderOffer)
          Private method used by applyAllOrderOffers to create an OrderAdjustment from a CandidateOrderOffer and associates the OrderAdjustment to the Order.
 java.util.List<Offer> buildOfferListForOrder(Order order)
          Creates a list of offers that applies to this order.
protected  void clearOffersandAdjustments(Order order)
           
protected  boolean couldOfferApplyToCustomer(Offer offer, Customer customer)
          Private method which executes the appliesToCustomerRules in the Offer to determine if this Offer can be applied to the Customer.
protected  boolean couldOfferApplyToOrder(Offer offer, Order order)
          Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.
protected  boolean couldOfferApplyToOrder(Offer offer, Order order, DiscreteOrderItem discreteOrderItem)
          Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.
protected  boolean couldOfferApplyToOrder(Offer offer, Order order, DiscreteOrderItem discreteOrderItem, FulfillmentGroup fulfillmentGroup)
          Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.
protected  boolean couldOfferApplyToOrder(Offer offer, Order order, FulfillmentGroup fulfillmentGroup)
          Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.
protected  java.lang.Boolean executeExpression(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> vars)
          Private method used by couldOfferApplyToOrder to execute the MVEL expression in the appliesToOrderRules to determine if this offer can be applied.
protected  java.util.List<Offer> filterOffers(java.util.List<Offer> offers, Customer customer)
           
 java.util.List<Offer> findAllOffers()
          Returns all offers
protected  java.util.List<Offer> lookupAutomaticDeliveryOffers()
          Private method used to retrieve all offers with DeliveryType of AUTOMATIC
 Offer lookupOfferByCode(java.lang.String code)
          Creates a list of offers that applies to this order.
 OfferCode lookupOfferCodeByCode(java.lang.String code)
          Lookup OfferCode by code.
protected  java.util.List<CustomerOffer> lookupOfferCustomerByCustomer(Customer customer)
          Private method used to retrieve all offers assigned to this customer.
protected  java.util.List<Offer> removeInvalidCustomerOffers(java.util.List<Offer> offers, Customer customer)
          Private method that takes in a list of Offers and removes all Offers from the list that does not apply to this customer.
protected  java.util.List<CandidateItemOffer> removeOfferFromCandidateItemOffers(java.util.List<CandidateItemOffer> candidateOffers, Offer offer)
           
protected  java.util.List<CandidateOrderOffer> removeOfferFromCandidateOrderOffers(java.util.List<CandidateOrderOffer> candidateOffers, Offer offer)
           
protected  java.util.List<OfferCode> removeOutOfDateOfferCodes(java.util.List<OfferCode> offerCodes)
          Removes all out of date offerCodes based on the offerCode and its offer's start and end date.
protected  java.util.List<Offer> removeOutOfDateOffers(java.util.List<Offer> offers)
          Removes all out of date offers.
protected  java.util.List<CandidateItemOffer> removeTrailingNotCombinableItemOffers(java.util.List<CandidateItemOffer> candidateOffers)
           
protected  java.util.List<CandidateOrderOffer> removeTrailingNotCombinableOrderOffers(java.util.List<CandidateOrderOffer> candidateOffers)
           
 Offer save(Offer offer)
          Save a new offer or updates an existing offer
 OfferCode saveOfferCode(OfferCode offerCode)
          Saves a new Offer or updates an existing Offer that belongs to an OfferCode, then saves or updates the OfferCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

customerOfferDao

protected CustomerOfferDao customerOfferDao

offerCodeDao

protected OfferCodeDao offerCodeDao

offerDao

protected OfferDao offerDao
Constructor Detail

OfferServiceImpl

public OfferServiceImpl()
Method Detail

findAllOffers

public java.util.List<Offer> findAllOffers()
Description copied from interface: OfferService
Returns all offers

Specified by:
findAllOffers in interface OfferService
Returns:
all offers

save

public Offer save(Offer offer)
Description copied from interface: OfferService
Save a new offer or updates an existing offer

Specified by:
save in interface OfferService
Returns:
the offer

saveOfferCode

public OfferCode saveOfferCode(OfferCode offerCode)
Description copied from interface: OfferService
Saves a new Offer or updates an existing Offer that belongs to an OfferCode, then saves or updates the OfferCode

Specified by:
saveOfferCode in interface OfferService
Returns:
the offerCode

lookupOfferByCode

public Offer lookupOfferByCode(java.lang.String code)
Creates a list of offers that applies to this order. All offers that are assigned to the customer, entered during checkout, or has a delivery type of automatic are added to the list. The same offer cannot appear more than once in the list.

Specified by:
lookupOfferByCode in interface OfferService
Parameters:
order -
Returns:
a List of offers that may apply to this order

buildOfferListForOrder

public java.util.List<Offer> buildOfferListForOrder(Order order)
Creates a list of offers that applies to this order. All offers that are assigned to the customer, entered during checkout, or has a delivery type of automatic are added to the list. The same offer cannot appear more than once in the list.

Specified by:
buildOfferListForOrder in interface OfferService
Parameters:
order -
Returns:
a List of offers that may apply to this order

lookupOfferCustomerByCustomer

protected java.util.List<CustomerOffer> lookupOfferCustomerByCustomer(Customer customer)
Private method used to retrieve all offers assigned to this customer. These offers have a DeliveryType of MANUAL and are programmatically assigned to the customer.

Parameters:
customer -
Returns:
a List of offers assigned to the customer

lookupAutomaticDeliveryOffers

protected java.util.List<Offer> lookupAutomaticDeliveryOffers()
Private method used to retrieve all offers with DeliveryType of AUTOMATIC

Returns:
a List of automatic delivery offers

removeOutOfDateOfferCodes

protected java.util.List<OfferCode> removeOutOfDateOfferCodes(java.util.List<OfferCode> offerCodes)
Removes all out of date offerCodes based on the offerCode and its offer's start and end date. If an offerCode has a later start date, that offerCode will be removed. OfferCodes without a start date will still be processed. If the offerCode has a end date that has already passed, that offerCode will be removed. OfferCodes without a end date will be processed. The start and end dates on the offer will still need to be evaluated.

Parameters:
offers -
Returns:
a List of non-expired offers

applyOffersToOrder

public void applyOffersToOrder(java.util.List<Offer> offers,
                               Order order)
                        throws PricingException
Description copied from interface: OfferService
Apply offers to order.

Specified by:
applyOffersToOrder in interface OfferService
Parameters:
offers - the offers
order - the order
Throws:
PricingException

removeTrailingNotCombinableOrderOffers

protected java.util.List<CandidateOrderOffer> removeTrailingNotCombinableOrderOffers(java.util.List<CandidateOrderOffer> candidateOffers)

removeTrailingNotCombinableItemOffers

protected java.util.List<CandidateItemOffer> removeTrailingNotCombinableItemOffers(java.util.List<CandidateItemOffer> candidateOffers)

removeOfferFromCandidateOrderOffers

protected java.util.List<CandidateOrderOffer> removeOfferFromCandidateOrderOffers(java.util.List<CandidateOrderOffer> candidateOffers,
                                                                                  Offer offer)

removeOfferFromCandidateItemOffers

protected java.util.List<CandidateItemOffer> removeOfferFromCandidateItemOffers(java.util.List<CandidateItemOffer> candidateOffers,
                                                                                Offer offer)

clearOffersandAdjustments

protected void clearOffersandAdjustments(Order order)

filterOffers

protected java.util.List<Offer> filterOffers(java.util.List<Offer> offers,
                                             Customer customer)

removeOutOfDateOffers

protected java.util.List<Offer> removeOutOfDateOffers(java.util.List<Offer> offers)
Removes all out of date offers. If an offer does not have a start date, or the start date is a later date, that offer will be removed. Offers without a start date should not be processed. If the offer has a end date that has already passed, that offer will be removed. Offers without a end date will be processed if the start date is prior to the transaction date.

Parameters:
offers -
Returns:
List of Offers with valid dates

removeInvalidCustomerOffers

protected java.util.List<Offer> removeInvalidCustomerOffers(java.util.List<Offer> offers,
                                                            Customer customer)
Private method that takes in a list of Offers and removes all Offers from the list that does not apply to this customer.

Parameters:
offers -
customer -
Returns:
List of Offers that apply to this customer

couldOfferApplyToCustomer

protected boolean couldOfferApplyToCustomer(Offer offer,
                                            Customer customer)
Private method which executes the appliesToCustomerRules in the Offer to determine if this Offer can be applied to the Customer.

Parameters:
offer -
customer -
Returns:
true if offer can be applied, otherwise false

applyAllItemOffers

protected boolean applyAllItemOffers(java.util.List<CandidateItemOffer> itemOffers,
                                     java.util.List<DiscreteOrderItem> discreteOrderItems)
Private method that takes a list of sorted CandidateItemOffers and determines if each offer can be applied based on the restrictions (stackable and/or combinable) on that offer. OrderItemAdjustments are create on the OrderItem for each applied CandidateItemOffer. An offer with stackable equals false cannot be applied to an OrderItem that already contains an OrderItemAdjustment. An offer with combinable equals false cannot be applied to an OrderItem if that OrderItem already contains an OrderItemAdjustment, unless the offer is the same offer as the OrderItemAdjustment offer.

Parameters:
itemOffers - a sorted list of CandidateItemOffer
Returns:
true if an OrderItemOffer was applied, otherwise false

applyOrderItemOffer

protected void applyOrderItemOffer(CandidateItemOffer itemOffer)
Private method used by applyAllItemOffers to create an OrderItemAdjustment from a CandidateItemOffer and associates the OrderItemAdjustment to the OrderItem.

Parameters:
itemOffer - a CandidateItemOffer to apply to an OrderItem

applyAllOrderOffers

protected boolean applyAllOrderOffers(java.util.List<CandidateOrderOffer> orderOffers,
                                      Order order)
Private method that takes a list of sorted CandidateOrderOffers and determines if each offer can be applied based on the restrictions (stackable and/or combinable) on that offer. OrderAdjustments are create on the Order for each applied CandidateOrderOffer. An offer with stackable equals false cannot be applied to an Order that already contains an OrderAdjustment. An offer with combinable equals false cannot be applied to the Order if the Order already contains an OrderAdjustment.

Parameters:
orderOffers - a sorted list of CandidateOrderOffer
order - the Order to apply the CandidateOrderOffers
Returns:
true if order offer applied; otherwise false

applyOrderOffer

protected void applyOrderOffer(CandidateOrderOffer orderOffer)
Private method used by applyAllOrderOffers to create an OrderAdjustment from a CandidateOrderOffer and associates the OrderAdjustment to the Order.

Parameters:
orderOffer - a CandidateOrderOffer to apply to an Order

couldOfferApplyToOrder

protected boolean couldOfferApplyToOrder(Offer offer,
                                         Order order)
Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.

Parameters:
offer -
order -
Returns:
true if offer can be applied, otherwise false

couldOfferApplyToOrder

protected boolean couldOfferApplyToOrder(Offer offer,
                                         Order order,
                                         DiscreteOrderItem discreteOrderItem)
Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.

Parameters:
offer -
order -
discreteOrderItem -
Returns:
true if offer can be applied, otherwise false

couldOfferApplyToOrder

protected boolean couldOfferApplyToOrder(Offer offer,
                                         Order order,
                                         FulfillmentGroup fulfillmentGroup)
Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.

Parameters:
offer -
order -
fulfillmentGroup -
Returns:
true if offer can be applied, otherwise false

couldOfferApplyToOrder

protected boolean couldOfferApplyToOrder(Offer offer,
                                         Order order,
                                         DiscreteOrderItem discreteOrderItem,
                                         FulfillmentGroup fulfillmentGroup)
Private method which executes the appliesToOrderRules in the Offer to determine if this offer can be applied to the Order, OrderItem, or FulfillmentGroup.

Parameters:
offer -
order -
discreteOrderItem -
fulfillmentGroup -
Returns:
true if offer can be applied, otherwise false

executeExpression

protected java.lang.Boolean executeExpression(java.lang.String expression,
                                              java.util.Map<java.lang.String,java.lang.Object> vars)
Private method used by couldOfferApplyToOrder to execute the MVEL expression in the appliesToOrderRules to determine if this offer can be applied.

Parameters:
expression -
vars -
Returns:
a Boolean object containing the result of executing the MVEL expression

applyFulfillmentGroupsOffers

public void applyFulfillmentGroupsOffers(java.util.List<FulfillmentGroup> fulfillmentGroups)
Description copied from interface: OfferService
Apply offers for a List of FulfillmentGroup

Specified by:
applyFulfillmentGroupsOffers in interface OfferService

applyFulfillmentGroupOffers

public void applyFulfillmentGroupOffers(FulfillmentGroup fulfillmentGroup)
Description copied from interface: OfferService
Apply offers for a fulfillmentGroup

Specified by:
applyFulfillmentGroupOffers in interface OfferService

applyAllFulfillmentGroupOffers

protected void applyAllFulfillmentGroupOffers(java.util.List<CandidateFulfillmentGroupOffer> fulfillmentGroupOffers,
                                              FulfillmentGroup fulfillmentGroup)
Private method that takes a list of sorted CandidateFulfillmentGroupOffer and determines if each offer can be applied based on the restrictions (stackable and/or combinable) on that offer. FulfillmentGroupAdjustment are create on the FulfillmentGroup for each applied CandidateFulfillmentGroupOffer. An offer with stackable equals false cannot be applied to an FulfillmentGroup that already contains an FulfillmentGroupAdjustment. An offer with combinable equals false cannot be applied to the FulfillmentGroup if the FulfillmentGroup already contains an FulfillmentGroupAdjustment.

Parameters:
fulfillmentGroupOffers - a sorted list of CandidateFulfillmentGroupOffer
fulfillmentGroup - the FulfillmentGroup to apply the CandidateOrderOffers

applyFulfillmentGroupOffer

protected void applyFulfillmentGroupOffer(CandidateFulfillmentGroupOffer fulfillmentGroupOffer)
Private method used by applyAllFulfillmentGroupOffers to create an FulfillmentGroupAdjustment from a CandidateFulfillmentGroupOffer and associates the FulfillmentGroupAdjustment to the Order.

Parameters:
fulfillmentGroupOffer - a CandidateFulfillmentGroupOffer to apply to an Order

lookupOfferCodeByCode

public OfferCode lookupOfferCodeByCode(java.lang.String code)
Description copied from interface: OfferService
Lookup OfferCode by code.

Specified by:
lookupOfferCodeByCode in interface OfferService
Parameters:
code - the code
Returns:
the offer


Copyright © 2010. All Rights Reserved.