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, ItemOfferProcessor, OrderOfferProcessor

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

Filter and apply order item offers.

Author:
jfischer

Field Summary
 
Fields inherited from class org.broadleafcommerce.core.offer.service.processor.OrderOfferProcessorImpl
offerDao, orderItemDao, promotableItemFactory
 
Fields inherited from class org.broadleafcommerce.core.offer.service.processor.AbstractBaseProcessor
offerTimeZoneProcessor
 
Constructor Summary
ItemOfferProcessorImpl()
           
 
Method Summary
protected  boolean adjustmentIsNotGoodEnoughToBeApplied(PromotableCandidateItemOffer itemOffer, PromotableOrderItemPriceDetail detail)
          The adjustment might not be better than the sale price.
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  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  void applyOrderItemAdjustment(PromotableCandidateItemOffer itemOffer, PromotableOrderItemPriceDetail itemPriceDetail)
          Private method used by applyAdjustments to create an OrderItemAdjustment from a CandidateOrderOffer and associates the OrderItemAdjustment to the OrderItem.
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  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  Comparator<PromotableOrderItemPriceDetail> getQualifierItemComparator(boolean applyToSalePrice)
          Used in applyItemQualifiersAndTargets(PromotableCandidateItemOffer, PromotableOrder) allow for customized sorting for which qualifier items should be attempted to be used first for a promotion.
protected  Comparator<PromotableOrderItemPriceDetail> getTargetItemComparator(boolean applyToSalePrice)
           Used in applyItemQualifiersAndTargets(PromotableCandidateItemOffer, PromotableOrder) allow for customized sorting for which target items the promotion should be attempted to be applied to first.
protected  boolean isTotalitarianOfferAppliedToAnyItem(PromotableOrder order)
           
protected  boolean itemOfferCanBeApplied(PromotableOrder order, PromotableCandidateItemOffer itemOffer)
          Return false if a totalitarian offer has already been applied and this order already has item adjustments.
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 markTargets(PromotableCandidateItemOffer itemOffer, PromotableOrder order)
          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)
           
 
Methods inherited from class org.broadleafcommerce.core.offer.service.processor.OrderOfferProcessorImpl
applyAllOrderOffers, applyOrderOffer, buildItemDetailAdjustmentMap, buildItemPriceDetailKey, buildOrderItemList, buildPromFulfillmentAdjMap, buildPromotableDetailsMap, buildPromotableFulfillmentGroupMap, buildPromotableItemMap, buildPromotableOrderAdjustmentsMap, buildPromotableQualifiersMap, compareAndAdjustOrderAndItemOffers, couldOfferApplyToOrder, couldOfferApplyToOrder, couldOfferApplyToOrder, couldOfferApplyToOrder, createCandidateOrderOffer, filterOrderLevelOffer, getPromotableItemFactory, processMatchingDetails, removeTrailingNotCombinableOrderOffers, setOfferDao, setOrderItemDao, setPromotableItemFactory, synchronizeAdjustmentsAndPrices, synchronizeFulfillmentGroupAdjustments, synchronizeFulfillmentGroups, synchronizeItemPriceDetails, synchronizeItemQualifiers, synchronizeOrderAdjustments, synchronizeOrderItems, updateItemAdjustment, updatePriceDetail
 
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
 

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)

applyOrderItemAdjustment

protected void applyOrderItemAdjustment(PromotableCandidateItemOffer itemOffer,
                                        PromotableOrderItemPriceDetail itemPriceDetail)
Private method used by applyAdjustments to create an OrderItemAdjustment from a CandidateOrderOffer and associates the OrderItemAdjustment to the OrderItem.

Parameters:
orderOffer - a CandidateOrderOffer to apply to an 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 -

adjustmentIsNotGoodEnoughToBeApplied

protected boolean adjustmentIsNotGoodEnoughToBeApplied(PromotableCandidateItemOffer itemOffer,
                                                       PromotableOrderItemPriceDetail detail)
The adjustment might not be better than the sale price.

Parameters:
itemOffer -
detail -
Returns:

itemOfferCanBeApplied

protected boolean itemOfferCanBeApplied(PromotableOrder order,
                                        PromotableCandidateItemOffer itemOffer)
Return false if a totalitarian offer has already been applied and this order already has item adjustments.

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)
Loop through ItemCriteria and mark targets that can get this promotion to give the promotion to 1 or more targets.

Parameters:
itemOffer -
order -
Returns:

getQualifierItemComparator

protected Comparator<PromotableOrderItemPriceDetail> getQualifierItemComparator(boolean applyToSalePrice)
Used in applyItemQualifiersAndTargets(PromotableCandidateItemOffer, PromotableOrder) allow for customized sorting for which qualifier items should be attempted to be used first for a promotion. Default behavior is to sort descending, so higher-value items are attempted to be qualified first.

Parameters:
applyToSalePrice - - whether or not the Comparator should use the sale price for comparison
Returns:

getTargetItemComparator

protected Comparator<PromotableOrderItemPriceDetail> getTargetItemComparator(boolean applyToSalePrice)

Used in applyItemQualifiersAndTargets(PromotableCandidateItemOffer, PromotableOrder) allow for customized sorting for which target items the promotion should be attempted to be applied to first. Default behavior is to sort descending, so higher-value items get the promotion over lesser-valued items.

Note: By default, both the getQualifierItemComparator(boolean) and this target comparator are sorted in descending order. This means that higher-valued items can be paired with higher-valued items and lower-valued items can be paired with lower-valued items. This also ensures that you will not have the scenario where 2 lower-valued items can be used to qualify a higher-valued target.

Parameters:
applyToSalePrice - - whether or not the Comparator should use the sale price for comparison
Returns:

filterOffers

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

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:

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.