org.broadleafcommerce.core.offer.service.processor
Class ItemOfferProcessorImpl

java.lang.Object
  extended by org.broadleafcommerce.core.offer.service.processor.AbstractBaseProcessor
      extended by org.broadleafcommerce.core.offer.service.processor.OrderOfferProcessorImpl
          extended by org.broadleafcommerce.core.offer.service.processor.ItemOfferProcessorImpl
All Implemented Interfaces:
BaseProcessor, ItemOfferMarkTargets, ItemOfferProcessor, OrderOfferProcessor

@Service(value="blItemOfferProcessor")
public class ItemOfferProcessorImpl
extends OrderOfferProcessorImpl
implements ItemOfferProcessor, ItemOfferMarkTargets

Filter and apply order item offers.

Author:
jfischer

Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Fields inherited from class org.broadleafcommerce.core.offer.service.processor.OrderOfferProcessorImpl
offerDao, offerServiceUtilities, orderItemDao, promotableItemFactory
 
Fields inherited from class org.broadleafcommerce.core.offer.service.processor.AbstractBaseProcessor
extensionManager, offerTimeZoneProcessor
 
Constructor Summary
ItemOfferProcessorImpl()
           
 
Method Summary
protected  void applyAdjustments(PromotableOrder order, PromotableCandidateItemOffer itemOffer)
          The itemOffer has been qualified and prior methods added PromotionDiscount objects onto the ItemPriceDetail.
 void applyAllItemOffers(List<PromotableCandidateItemOffer> itemOffers, PromotableOrder order)
          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.
 void applyAndCompareOrderAndItemOffers(PromotableOrder order, List<PromotableCandidateOrderOffer> qualifiedOrderOffers, List<PromotableCandidateItemOffer> qualifiedItemOffers)
           
protected  void applyItemOffer(PromotableOrder order, PromotableCandidateItemOffer itemOffer)
           
protected  Boolean applyItemOfferExtension(PromotableOrder order, PromotableCandidateItemOffer itemOffer)
          Call out to extension managers.
protected  void applyItemQualifiersAndTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order)
           
protected  void applyLegacyAdjustments(PromotableOrder order, PromotableCandidateItemOffer itemOffer)
          Legacy adjustments use the stackable flag instead of item qualifiers and targets
protected  List<List<PromotableCandidateItemOffer>> buildItemOfferPermutations(List<PromotableCandidateItemOffer> offers)
          This method could be overridden to potentially run all permutations of offers.
protected  List<PromotableOrderItemPriceDetail> buildPriceDetailListFromOrderItems(List<PromotableOrderItem> items)
           
protected  void calculatePotentialSavings(List<PromotableCandidateItemOffer> itemOffers, PromotableOrder order)
          This method determines the potential savings for each item offer as if it was the only item offer being applied.
protected  Money calculatePotentialSavingsForOrderItem(PromotableCandidateItemOffer itemOffer, PromotableOrderItem item, int quantity)
          Provide an opportunity to for modules to override the potentialSavingsCalculation
protected  void chooseSaleOrRetailAdjustments(PromotableOrder order)
          Some promotions can only apply to the retail price.
protected  PromotableCandidateItemOffer createCandidateItemOffer(List<PromotableCandidateItemOffer> qualifiedItemOffers, Offer offer, PromotableOrder promotableOrder)
          Create a candidate item offer based on the offer in question and a specific order item
protected  void determineBestPermutation(List<PromotableCandidateItemOffer> itemOffers, PromotableOrder order)
           
 void filterItemLevelOffer(PromotableOrder order, List<PromotableCandidateItemOffer> qualifiedItemOffers, Offer offer)
          Review an item level offer against the list of discountable items from the order.
 void filterOffers(PromotableOrder order, List<Offer> filteredOffers, List<PromotableCandidateOrderOffer> qualifiedOrderOffers, List<PromotableCandidateItemOffer> qualifiedItemOffers)
           
protected  boolean isTotalitarianOfferAppliedToAnyItem(PromotableOrder order)
           
protected  boolean markQualifiers(PromotableCandidateItemOffer itemOffer, PromotableOrder order)
          Loop through ItemCriteria and mark qualifiers required to give the promotion to 1 or more targets.
protected  void markQualifiersAndTargets(PromotableOrder order, PromotableCandidateItemOffer itemOffer)
           
protected  boolean markRelatedQualifiersAndTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order)
          When the Offer.getRequiresRelatedTargetAndQualifiers() flag is set to true, we must make sure that we identify qualifiers and targets together, as they must be related to each other based on the OrderItem.getParentOrderItem() / OrderItem.getChildOrderItems() attributes.
protected  boolean markTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItem relatedQualifier)
           
 boolean markTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order, OrderItem relatedQualifier, boolean checkOnly)
          Loop through ItemCriteria and mark targets that can get this promotion to give the promotion to 1 or more targets.
protected  void mergePriceDetails(PromotableOrder order)
          Checks to see if any priceDetails need to be combined and if so, combines them.
protected  boolean offerListStartsWithNonCombinable(List<PromotableCandidateItemOffer> offerList)
           
protected  boolean offerMeetsSubtotalRequirements(PromotableOrder order, PromotableCandidateItemOffer itemOffer)
           
protected  void restPriceDetails(PromotableOrderItem item)
           
 
Methods inherited from class org.broadleafcommerce.core.offer.service.processor.OrderOfferProcessorImpl
applyAllOrderOffers, applyOrderOffer, buildItemPriceDetailKey, buildPromFulfillmentAdjMap, buildPromotableDetailsMap, buildPromotableFulfillmentGroupMap, buildPromotableOrderAdjustmentsMap, buildPromotableQualifiersMap, compareAndAdjustOrderAndItemOffers, couldOfferApplyToOrder, couldOfferApplyToOrder, couldOfferApplyToOrder, couldOfferApplyToOrder, createCandidateOrderOffer, filterOrderLevelOffer, getOfferServiceUtilities, getPromotableItemFactory, processMatchingDetails, removeTrailingNotCombinableOrderOffers, setOfferDao, setOfferServiceUtilities, setOrderItemDao, setPromotableItemFactory, synchronizeAdjustmentsAndPrices, synchronizeFulfillmentGroupAdjustments, synchronizeFulfillmentGroups, synchronizeItemPriceDetails, synchronizeItemQualifiers, synchronizeOrderAdjustments, synchronizeOrderItems
 
Methods inherited from class org.broadleafcommerce.core.offer.service.processor.AbstractBaseProcessor
checkForItemRequirements, clearAllNonFinalizedQuantities, couldOfferApplyToCustomer, couldOfferApplyToOrderItems, couldOfferApplyToRequestDTO, couldOfferApplyToTimePeriod, couldOrderItemMeetOfferRequirement, executeExpression, filterOffers, finalizeQuantities, getOfferTimeZoneProcessor, meetsItemQualifierSubtotal, removeInvalidCustomerOffers, removeInvalidRequestOffers, removeOutOfDateOffers, removeTimePeriodOffers, setOfferTimeZoneProcessor, splitDetailsIfNecessary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.broadleafcommerce.core.offer.service.processor.OrderOfferProcessor
applyAllOrderOffers, couldOfferApplyToOrder, executeExpression, filterOrderLevelOffer, getPromotableItemFactory, removeTrailingNotCombinableOrderOffers, setOfferDao, setOrderItemDao, setPromotableItemFactory, synchronizeAdjustmentsAndPrices
 
Methods inherited from interface org.broadleafcommerce.core.offer.service.processor.BaseProcessor
filterOffers
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
Constructor Detail

ItemOfferProcessorImpl

public ItemOfferProcessorImpl()
Method Detail

filterItemLevelOffer

public void filterItemLevelOffer(PromotableOrder order,
                                 List<PromotableCandidateItemOffer> qualifiedItemOffers,
                                 Offer offer)
Description copied from interface: ItemOfferProcessor
Review an item level offer against the list of discountable items from the order. If the offer applies, add it to the qualifiedItemOffers list.

Specified by:
filterItemLevelOffer in interface ItemOfferProcessor
Parameters:
order - the BLC order
qualifiedItemOffers - the container list for any qualified offers
offer - the offer in question

createCandidateItemOffer

protected PromotableCandidateItemOffer createCandidateItemOffer(List<PromotableCandidateItemOffer> qualifiedItemOffers,
                                                                Offer offer,
                                                                PromotableOrder promotableOrder)
Create a candidate item offer based on the offer in question and a specific order item

Parameters:
qualifiedItemOffers - the container list for candidate item offers
offer - the offer in question
Returns:
the candidate item offer

applyAllItemOffers

public void applyAllItemOffers(List<PromotableCandidateItemOffer> itemOffers,
                               PromotableOrder order)
Description copied from interface: ItemOfferProcessor
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.

Specified by:
applyAllItemOffers in interface ItemOfferProcessor
Parameters:
itemOffers - a sorted list of CandidateItemOffer

offerMeetsSubtotalRequirements

protected boolean offerMeetsSubtotalRequirements(PromotableOrder order,
                                                 PromotableCandidateItemOffer itemOffer)

isTotalitarianOfferAppliedToAnyItem

protected boolean isTotalitarianOfferAppliedToAnyItem(PromotableOrder order)

applyAdjustments

protected void applyAdjustments(PromotableOrder order,
                                PromotableCandidateItemOffer itemOffer)
The itemOffer has been qualified and prior methods added PromotionDiscount objects onto the ItemPriceDetail. This code will convert the PromotionDiscounts into Adjustments

Parameters:
order -
itemOffer -

applyLegacyAdjustments

protected void applyLegacyAdjustments(PromotableOrder order,
                                      PromotableCandidateItemOffer itemOffer)
Legacy adjustments use the stackable flag instead of item qualifiers and targets

Parameters:
order -
itemOffer -

applyItemOfferExtension

protected Boolean applyItemOfferExtension(PromotableOrder order,
                                          PromotableCandidateItemOffer itemOffer)
Call out to extension managers. Returns true if the core processing should still be performed for the passed in offer.

Parameters:
order -
itemOffer -
Returns:

applyItemOffer

protected void applyItemOffer(PromotableOrder order,
                              PromotableCandidateItemOffer itemOffer)

chooseSaleOrRetailAdjustments

protected void chooseSaleOrRetailAdjustments(PromotableOrder order)
Some promotions can only apply to the retail price. This method determines whether retailPrice only promotions should be used instead of those that can apply to the sale price as well.

Parameters:
order -

mergePriceDetails

protected void mergePriceDetails(PromotableOrder order)
Checks to see if any priceDetails need to be combined and if so, combines them.

Parameters:
order -

applyItemQualifiersAndTargets

protected void applyItemQualifiersAndTargets(PromotableCandidateItemOffer itemOffer,
                                             PromotableOrder order)

buildPriceDetailListFromOrderItems

protected List<PromotableOrderItemPriceDetail> buildPriceDetailListFromOrderItems(List<PromotableOrderItem> items)

markQualifiers

protected boolean markQualifiers(PromotableCandidateItemOffer itemOffer,
                                 PromotableOrder order)
Loop through ItemCriteria and mark qualifiers required to give the promotion to 1 or more targets.

Parameters:
itemOffer -
order -
Returns:

markTargets

protected boolean markTargets(PromotableCandidateItemOffer itemOffer,
                              PromotableOrder order,
                              OrderItem relatedQualifier)

markTargets

public boolean markTargets(PromotableCandidateItemOffer itemOffer,
                           PromotableOrder order,
                           OrderItem relatedQualifier,
                           boolean checkOnly)
Loop through ItemCriteria and mark targets that can get this promotion to give the promotion to 1 or more targets.

Specified by:
markTargets in interface ItemOfferMarkTargets
Parameters:
itemOffer -
order -
Returns:

markRelatedQualifiersAndTargets

protected boolean markRelatedQualifiersAndTargets(PromotableCandidateItemOffer itemOffer,
                                                  PromotableOrder order)
When the Offer.getRequiresRelatedTargetAndQualifiers() flag is set to true, we must make sure that we identify qualifiers and targets together, as they must be related to each other based on the OrderItem.getParentOrderItem() / OrderItem.getChildOrderItems() attributes.

Parameters:
itemOffer -
order -
Returns:
whether or not a suitable qualifier/target pair was found and marked

filterOffers

public void filterOffers(PromotableOrder order,
                         List<Offer> filteredOffers,
                         List<PromotableCandidateOrderOffer> qualifiedOrderOffers,
                         List<PromotableCandidateItemOffer> qualifiedItemOffers)
Specified by:
filterOffers in interface ItemOfferProcessor

calculatePotentialSavingsForOrderItem

protected Money calculatePotentialSavingsForOrderItem(PromotableCandidateItemOffer itemOffer,
                                                      PromotableOrderItem item,
                                                      int quantity)
Provide an opportunity to for modules to override the potentialSavingsCalculation

Parameters:
itemOffer -
item -
quantity -
Returns:

calculatePotentialSavings

protected void calculatePotentialSavings(List<PromotableCandidateItemOffer> itemOffers,
                                         PromotableOrder order)
This method determines the potential savings for each item offer as if it was the only item offer being applied.

Parameters:
itemOffers -
order -

markQualifiersAndTargets

protected void markQualifiersAndTargets(PromotableOrder order,
                                        PromotableCandidateItemOffer itemOffer)

offerListStartsWithNonCombinable

protected boolean offerListStartsWithNonCombinable(List<PromotableCandidateItemOffer> offerList)

buildItemOfferPermutations

protected List<List<PromotableCandidateItemOffer>> buildItemOfferPermutations(List<PromotableCandidateItemOffer> offers)
This method could be overridden to potentially run all permutations of offers. A reasonable alternative is to have a permutation with nonCombinable offers and another with combinable offers.

Parameters:
offers -
Returns:

restPriceDetails

protected void restPriceDetails(PromotableOrderItem item)

determineBestPermutation

protected void determineBestPermutation(List<PromotableCandidateItemOffer> itemOffers,
                                        PromotableOrder order)

applyAndCompareOrderAndItemOffers

public void applyAndCompareOrderAndItemOffers(PromotableOrder order,
                                              List<PromotableCandidateOrderOffer> qualifiedOrderOffers,
                                              List<PromotableCandidateItemOffer> qualifiedItemOffers)
Specified by:
applyAndCompareOrderAndItemOffers in interface ItemOfferProcessor


Copyright © 2013. All Rights Reserved.