Class DefaultOrderOfferProcessor
java.lang.Object
com.broadleafcommerce.promotion.offer.service.engine.application.processor.DefaultOrderOfferProcessor
- All Implemented Interfaces:
OrderOfferProcessor
- Author:
- Chad Harchar (charchar)
-
Field Summary
Modifier and TypeFieldDescriptionprotected com.broadleafcommerce.common.extension.TypeFactory
protected final ProrationService
-
Constructor Summary
ConstructorDescriptionDefaultOrderOfferProcessor
(OrderAndItemOfferHelper helper, ProrationService prorationService) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCodeResponseToPermutationResult
(EnhancedOrder order, Offer offer, OrderOfferPermutationResult result, com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponse codeResponse) Adds theCodeResponse
to theOrderOfferPermutationResult
for the provided offer.protected void
addVoucherToResult
(OfferProcessingContext context, OrderOfferPermutationResult result, CandidateOrderOffer orderOffer) protected javax.money.MonetaryAmount
adjustToMaxValueIfNeeded
(Offer offer, javax.money.MonetaryAmount adjustmentValue) void
applyOrderAdjustments
(OfferProcessingContext context, OrderOfferPermutationResult orderOfferPermutationResult) 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.protected com.broadleafcommerce.promotion.offer.client.web.context.info.Voucher
buildVoucher
(CandidateOrderOffer orderOffer, EnhancedOrder order) protected DiscountableItemInfo
calculateDiscountableItemTotal
(List<EnhancedOrderLineItem> relevantItems, CandidateOrderOffer orderOffer, OfferProcessingContext context, CombinedTypesOfferPermutation ctop, OrderOfferPermutationResult orderResult) protected boolean
canOfferBeApplied
(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 OrderOfferPermutationResult
computeOfferPermutationValue
(OfferProcessingContext context, OffersPermutation<CandidateOrderOffer> offerPermutation, CombinedTypesOfferPermutation ctop) protected boolean
couldOfferApplyToOrder
(EnhancedOrder order, CandidateOrderOffer orderOffer) protected OrderOfferAdjustment
createOrderOfferAdjustment
(OfferProcessingContext context, CandidateOrderOffer orderOffer, javax.money.MonetaryAmount amount) protected OrderOfferPermutationResult
determineBestPermutationGivenEqualAdjustmentValues
(OrderOfferPermutationResult bestPermutation, OrderOfferPermutationResult result) void
findBestOrderOffersForPermutation
(OfferProcessingContext context, CombinedTypesOfferPermutation ctop) protected Optional<DiscountTier>
findMaxDiscountTier
(CandidateOrderOffer offer, javax.money.MonetaryAmount amount) protected javax.money.MonetaryAmount
getEstimatedVoucherValue
(EnhancedOrder order, Offer offer) protected OrderAndItemOfferHelper
protected com.broadleafcommerce.common.extension.TypeFactory
protected void
logIfDebugOn
(String message, Object... formatArgs) Checks ifLog.isDebugEnabled()
debug is enabled}, then wraps the message inString.format(String, Object...)
with the givenformatArgs
and logs it.protected void
logIfTraceOn
(String message, Object... formatArgs) Checks ifLog.isTraceEnabled()
trace is enabled}, then wraps the message inString.format(String, Object...)
with the givenformatArgs
and logs it.protected boolean
meetsMinimumSubtotal
(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 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.void
setOfferFactory
(com.broadleafcommerce.common.extension.TypeFactory offerFactory) protected boolean
shouldIncludeItem
(EnhancedOrderLineItem item, EnhancedOrder order, CandidateOrderOffer offer) protected boolean
shouldIncludeSegmentItem
(EnhancedOrderLineItem item, EnhancedOrder order, CandidateOrderOffer offer) Filters items that are part of the offer being processed.protected boolean
The 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:
findBestOrderOffersForPermutation
in interfaceOrderOfferProcessor
-
determineBestPermutationGivenEqualAdjustmentValues
protected OrderOfferPermutationResult determineBestPermutationGivenEqualAdjustmentValues(OrderOfferPermutationResult bestPermutation, OrderOfferPermutationResult result) -
applyOrderAdjustments
public void applyOrderAdjustments(OfferProcessingContext context, OrderOfferPermutationResult orderOfferPermutationResult) - Specified by:
applyOrderAdjustments
in 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
- theOrderOfferPermutationResult
to add theVoucher
toorderOffer
- thevoucher offer
to build theVoucher
from
-
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 theCodeResponse
to theOrderOfferPermutationResult
for 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 givenformatArgs
and logs it. -
logIfDebugOn
Checks ifLog.isDebugEnabled()
debug is enabled}, then wraps the message inString.format(String, Object...)
with the givenformatArgs
and 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)