Class DefaultOrderOfferProcessor
java.lang.Object
com.broadleafcommerce.promotion.offer.service.engine.application.processor.DefaultOrderOfferProcessor
- All Implemented Interfaces:
OrderOfferProcessor
- Author:
- Chad Harchar (charchar)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.broadleafcommerce.common.extension.TypeFactoryprotected final ProrationService -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOrderOfferProcessor(OrderAndItemOfferHelper helper, ProrationService prorationService) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCodeResponseToPermutationResult(EnhancedOrder order, Offer offer, OrderOfferPermutationResult result, com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponse codeResponse) Adds theCodeResponseto theOrderOfferPermutationResultfor the provided offer.protected voidaddVoucherToResult(OfferProcessingContext context, OrderOfferPermutationResult result, CandidateOrderOffer orderOffer) protected javax.money.MonetaryAmountadjustToMaxValueIfNeeded(Offer offer, javax.money.MonetaryAmount adjustmentValue) voidapplyOrderAdjustments(OfferProcessingContext context, OrderOfferPermutationResult orderOfferPermutationResult) protected com.broadleafcommerce.promotion.offer.client.web.context.info.VoucherbuildVoucher(Offer voucherOffer) Deprecated, for removal: This API element is subject to removal in a future version.protected com.broadleafcommerce.promotion.offer.client.web.context.info.VoucherbuildVoucher(CandidateOrderOffer orderOffer, EnhancedOrder order) protected DiscountableItemInfocalculateDiscountableItemTotal(List<EnhancedOrderLineItem> relevantItems, CandidateOrderOffer orderOffer, OfferProcessingContext context, CombinedTypesOfferPermutation ctop, OrderOfferPermutationResult orderResult) protected booleancanOfferBeApplied(EnhancedOrder order, CandidateOrderOffer orderOffer, OrderOfferPermutationResult result) protected Optional<javax.money.MonetaryAmount>computeAdjustmentValue(CandidateOrderOffer orderOffer, DiscountableItemInfo discountableItemInfo) Calculates the value of the adjustment by first getting the current value of the order and then calculating the value of this adjustment.protected OrderOfferPermutationResultcomputeOfferPermutationValue(OfferProcessingContext context, OffersPermutation<CandidateOrderOffer> offerPermutation, CombinedTypesOfferPermutation ctop) protected booleancouldOfferApplyToOrder(EnhancedOrder order, CandidateOrderOffer orderOffer) protected OrderOfferAdjustmentcreateOrderOfferAdjustment(OfferProcessingContext context, CandidateOrderOffer orderOffer, javax.money.MonetaryAmount amount) protected OrderOfferPermutationResultdetermineBestPermutationGivenEqualAdjustmentValues(OrderOfferPermutationResult bestPermutation, OrderOfferPermutationResult result) voidfindBestOrderOffersForPermutation(OfferProcessingContext context, CombinedTypesOfferPermutation ctop) protected Optional<DiscountTier>findMaxDiscountTier(CandidateOrderOffer offer, javax.money.MonetaryAmount amount) protected javax.money.MonetaryAmountgetEstimatedVoucherValue(EnhancedOrder order, Offer offer) protected OrderAndItemOfferHelperprotected com.broadleafcommerce.common.extension.TypeFactoryprotected voidlogIfDebugOn(String message, Object... formatArgs) Checks ifLog.isDebugEnabled()debug is enabled}, then wraps the message inString.format(String, Object...)with the givenformatArgsand logs it.protected voidlogIfTraceOn(String message, Object... formatArgs) Checks ifLog.isTraceEnabled()trace is enabled}, then wraps the message inString.format(String, Object...)with the givenformatArgsand logs it.protected booleanmeetsMinimumSubtotal(javax.money.MonetaryAmount actualSubtotal, CandidateOrderOffer candidateOffer) protected List<EnhancedOrderLineItem>relevantSegmentItems(EnhancedOrder order, CandidateOrderOffer offer) Returns list of order items matching the offers segment and then filters the returned list by calling #shouldFilterItemprotected voidremoveLowerValueItemOffersFromConsideration(EnhancedOrder order, OffersPermutation<CandidateOrderOffer> offerPermutation, CombinedTypesOfferPermutation ctop) When theOffer#isExcludeDiscountedItemsFromTotals()property is true, we want to check to see if the Order offer would be better than previously applied item offers.voidsetOfferFactory(com.broadleafcommerce.common.extension.TypeFactory offerFactory) protected booleanshouldIncludeItem(EnhancedOrderLineItem item, EnhancedOrder order, CandidateOrderOffer offer) protected booleanshouldIncludeSegmentItem(EnhancedOrderLineItem item, EnhancedOrder order, CandidateOrderOffer offer) Filters items that are part of the offer being processed.protected booleanThe removeLowerValueOffers process is conservative in its approach.
-
Field Details
-
prorationService
-
offerFactory
protected com.broadleafcommerce.common.extension.TypeFactory offerFactory
-
-
Constructor Details
-
DefaultOrderOfferProcessor
public DefaultOrderOfferProcessor(OrderAndItemOfferHelper helper, ProrationService prorationService)
-
-
Method Details
-
findBestOrderOffersForPermutation
public void findBestOrderOffersForPermutation(OfferProcessingContext context, CombinedTypesOfferPermutation ctop) - Specified by:
findBestOrderOffersForPermutationin interfaceOrderOfferProcessor
-
determineBestPermutationGivenEqualAdjustmentValues
protected OrderOfferPermutationResult determineBestPermutationGivenEqualAdjustmentValues(OrderOfferPermutationResult bestPermutation, OrderOfferPermutationResult result) -
applyOrderAdjustments
public void applyOrderAdjustments(OfferProcessingContext context, OrderOfferPermutationResult orderOfferPermutationResult) - Specified by:
applyOrderAdjustmentsin interfaceOrderOfferProcessor
-
computeOfferPermutationValue
protected OrderOfferPermutationResult computeOfferPermutationValue(OfferProcessingContext context, OffersPermutation<CandidateOrderOffer> offerPermutation, CombinedTypesOfferPermutation ctop) -
removeLowerValueItemOffersFromConsideration
protected void removeLowerValueItemOffersFromConsideration(EnhancedOrder order, OffersPermutation<CandidateOrderOffer> offerPermutation, CombinedTypesOfferPermutation ctop) When theOffer#isExcludeDiscountedItemsFromTotals()property is true, we want to check to see if the Order offer would be better than previously applied item offers. This method only handles the most simple and most common scenarios. It specifically only handles non-tiered percent off order offers and only considers items offers whose target criteria uses a qty of 1 and has no qualifying criteria. -
verifyOkToRemoveLowerValueDetails
The removeLowerValueOffers process is conservative in its approach. By default, the process only considers offers that have a single target criteria with a qty of 1. Bulk Item Offers and BOGOs are not considered.- Parameters:
details-- Returns:
-
calculateDiscountableItemTotal
protected DiscountableItemInfo calculateDiscountableItemTotal(List<EnhancedOrderLineItem> relevantItems, CandidateOrderOffer orderOffer, OfferProcessingContext context, CombinedTypesOfferPermutation ctop, OrderOfferPermutationResult orderResult) - Parameters:
relevantItems-orderOffer-context-orderResult-- Returns:
-
meetsMinimumSubtotal
protected boolean meetsMinimumSubtotal(javax.money.MonetaryAmount actualSubtotal, CandidateOrderOffer candidateOffer) -
canOfferBeApplied
protected boolean canOfferBeApplied(EnhancedOrder order, CandidateOrderOffer orderOffer, OrderOfferPermutationResult result) -
couldOfferApplyToOrder
-
createOrderOfferAdjustment
protected OrderOfferAdjustment createOrderOfferAdjustment(OfferProcessingContext context, CandidateOrderOffer orderOffer, javax.money.MonetaryAmount amount) -
addVoucherToResult
protected void addVoucherToResult(OfferProcessingContext context, OrderOfferPermutationResult result, CandidateOrderOffer orderOffer) - Parameters:
result- theOrderOfferPermutationResultto add theVouchertoorderOffer- thevoucher offerto build theVoucherfrom
-
buildVoucher
@Deprecated(forRemoval=true) protected com.broadleafcommerce.promotion.offer.client.web.context.info.Voucher buildVoucher(Offer voucherOffer) Deprecated, for removal: This API element is subject to removal in a future version. -
buildVoucher
protected com.broadleafcommerce.promotion.offer.client.web.context.info.Voucher buildVoucher(CandidateOrderOffer orderOffer, EnhancedOrder order) -
getEstimatedVoucherValue
-
computeAdjustmentValue
protected Optional<javax.money.MonetaryAmount> computeAdjustmentValue(CandidateOrderOffer orderOffer, DiscountableItemInfo discountableItemInfo) Calculates the value of the adjustment by first getting the current value of the order and then calculating the value of this adjustment. IfCandidateOrderOffer.isRoundDiscountsByItem()istrue, discount rounding is done at the item level instead.If this adjustment value is greater than the currentOrderValue (e.g. would make the order go negative then the adjustment value is set to the value of the order).
-
adjustToMaxValueIfNeeded
protected javax.money.MonetaryAmount adjustToMaxValueIfNeeded(Offer offer, javax.money.MonetaryAmount adjustmentValue) -
relevantSegmentItems
protected List<EnhancedOrderLineItem> relevantSegmentItems(EnhancedOrder order, CandidateOrderOffer offer) Returns list of order items matching the offers segment and then filters the returned list by calling #shouldFilterItem- Parameters:
order-offer-- Returns:
-
shouldIncludeSegmentItem
protected boolean shouldIncludeSegmentItem(EnhancedOrderLineItem item, EnhancedOrder order, CandidateOrderOffer offer) Filters items that are part of the offer being processed. -
shouldIncludeItem
protected boolean shouldIncludeItem(EnhancedOrderLineItem item, EnhancedOrder order, CandidateOrderOffer offer) -
findMaxDiscountTier
protected Optional<DiscountTier> findMaxDiscountTier(CandidateOrderOffer offer, javax.money.MonetaryAmount amount) -
addCodeResponseToPermutationResult
protected void addCodeResponseToPermutationResult(EnhancedOrder order, Offer offer, OrderOfferPermutationResult result, com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponse codeResponse) Adds theCodeResponseto theOrderOfferPermutationResultfor the provided offer.- Parameters:
order- provides context information around offers and offer codesoffer- the offer to add the code responses forresult- the permutation result to add the code response tocodeResponse- the code response to be added
-
logIfTraceOn
Checks ifLog.isTraceEnabled()trace is enabled}, then wraps the message inString.format(String, Object...)with the givenformatArgsand logs it. -
logIfDebugOn
Checks ifLog.isDebugEnabled()debug is enabled}, then wraps the message inString.format(String, Object...)with the givenformatArgsand logs it. -
getHelper
-
getOfferFactory
protected com.broadleafcommerce.common.extension.TypeFactory getOfferFactory() -
setOfferFactory
@Autowired public void setOfferFactory(com.broadleafcommerce.common.extension.TypeFactory offerFactory)
-
buildVoucher(CandidateOrderOffer, EnhancedOrder)