Class OfferProcessingContext
java.lang.Object
com.broadleafcommerce.promotion.offer.service.dto.OfferProcessingContext
- All Implemented Interfaces:
Serializable
This object manages the full list of permutations for a given execution of the offer engine and
provides methods to determine the correct mix of offers for the final result.
- Author:
- Brian Polster (bpolster)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddToListIfPresent(List<Set<OfferCombinabilityCriteria>> criteriaByTypeList, Map<OfferCombinabilityCriteriaKey, OfferCombinabilityCriteria> permutationMap) Each element in the list represents a single offer type and the unique set ofOfferCombinabilityCriteriaobjects.protected voidThis method builds all compatible permutations of offers in a tree structure.protected booleancheckCompatability(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherCandidateOffer, CompatibleOfferNode node) protected booleancheckForCombinable(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherOffer) protected booleancheckForExplicitExclusions(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherCandidateOffer) protected booleancheckForStackable(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherOffer) protected booleancheckSegmentCombinable(BaseCandidateOffer offer, CompatibleOfferNode currentNode) If this is an order offer and the segment is unique with the node path, then this offer can be combined.protected voidprotected com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponsecreateCodeResponse(OfferNotAppliedReasonEnum notUsedReason, com.broadleafcommerce.common.extension.TypeFactory offerFactory, org.springframework.context.MessageSource messageSource) voidcreatePathsForNode(CompatibleOfferNode currentNode, List<BaseCandidateOffer> theOffers, Set<CompatibleOfferNode> allNodes) filterIncompatibleOffers(BaseCandidateOffer offer, CompatibleOfferNode node, List<BaseCandidateOffer> otherOffers) Filters the passed in list, removing all incompatible offersfindFirstCompatibleOffer(BaseCandidateOffer offer, CompatibleOfferNode node, List<BaseCandidateOffer> otherOffers) findFirstIncompatibleOffer(BaseCandidateOffer offer, CompatibleOfferNode node, List<BaseCandidateOffer> otherOffers) Based on the compatible flag, return the first compatible or incompatible item from the passed in listMethod facilitates unit testing.Builds a list consisting of the sets of OfferCombinabilityCriteria for each offer type.getOrder()booleanvoidinitialize(EnhancedOrder order, CandidateOffers offers) Initializes the core fields of the context.voidBuild unique permutations by offer type where a permutation is grouped by how the permutation can combine with other offer typesprotected voidinitializePermutations(List<? extends BaseCandidateOffer> offers, Map<OfferCombinabilityCriteriaKey, OfferCombinabilityCriteria> permutationMap) booleanprotected booleanisNotAppliedOffer(Set<Offer> appliedOffers, Offer offer) voidsetBestOfferPermutation(CombinedTypesOfferPermutation bestOfferPermutation) voidvoidupdateOfferNotAppliedResponses(com.broadleafcommerce.common.extension.TypeFactory offerFactory, org.springframework.context.MessageSource messageSource)
-
Constructor Details
-
OfferProcessingContext
-
OfferProcessingContext
public OfferProcessingContext()
-
-
Method Details
-
initialize
Initializes the core fields of the context.- Parameters:
order- The sourceEnhancedOrderoffers- Thecandidate offers- Since:
- Offer Service 3.1.0, Release Train 2.2.0
-
hasOffers
public boolean hasOffers() -
getCandidateOrderItemOffers
-
getCandidateFulfillmentItemOffers
-
initializePermutations
public void initializePermutations()Build unique permutations by offer type where a permutation is grouped by how the permutation can combine with other offer types- See Also:
-
initializePermutations
protected void initializePermutations(List<? extends BaseCandidateOffer> offers, Map<OfferCombinabilityCriteriaKey, OfferCombinabilityCriteria> permutationMap) -
buildOfferPermutationsForCriteria
This method builds all compatible permutations of offers in a tree structure. Each path of this tree represents a unique offer permutation.- Parameters:
criteria- OfferCombinabilityCriteria to group offers by
-
createPathsForNode
public void createPathsForNode(CompatibleOfferNode currentNode, List<BaseCandidateOffer> theOffers, Set<CompatibleOfferNode> allNodes) -
filterIncompatibleOffers
public List<BaseCandidateOffer> filterIncompatibleOffers(BaseCandidateOffer offer, CompatibleOfferNode node, List<BaseCandidateOffer> otherOffers) Filters the passed in list, removing all incompatible offers -
findFirstIncompatibleOffer
public BaseCandidateOffer findFirstIncompatibleOffer(BaseCandidateOffer offer, CompatibleOfferNode node, List<BaseCandidateOffer> otherOffers) Based on the compatible flag, return the first compatible or incompatible item from the passed in list -
findFirstCompatibleOffer
public BaseCandidateOffer findFirstCompatibleOffer(BaseCandidateOffer offer, CompatibleOfferNode node, List<BaseCandidateOffer> otherOffers) -
checkCompatability
protected boolean checkCompatability(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherCandidateOffer, CompatibleOfferNode node) -
checkSegmentCombinable
If this is an order offer and the segment is unique with the node path, then this offer can be combined. -
checkForExplicitExclusions
protected boolean checkForExplicitExclusions(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherCandidateOffer) -
checkForStackable
protected boolean checkForStackable(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherOffer) -
checkForCombinable
protected boolean checkForCombinable(BaseCandidateOffer candidateOffer, BaseCandidateOffer otherOffer) -
getCriteriaSetsByType
Builds a list consisting of the sets of OfferCombinabilityCriteria for each offer type. Each index in the list represents a level in the tree of possible offer combinations. The order is important as the permutations will first compute item offers which can impact the overall order subtotal and other offer eligibility. The list will only contain offer types that have relevant offers and they will be in the following order: Item, Order, Voucher, Fulfillment Item, Fulfillment Order- Returns:
-
addToListIfPresent
protected void addToListIfPresent(List<Set<OfferCombinabilityCriteria>> criteriaByTypeList, Map<OfferCombinabilityCriteriaKey, OfferCombinabilityCriteria> permutationMap) Each element in the list represents a single offer type and the unique set ofOfferCombinabilityCriteriaobjects. This structure supports the ability to find the best cross-type combination of offers.- Parameters:
criteriaByTypeList- The list to populatepermutationMap-
-
getBestOfferPermutation
-
updateBestCombinedTypesPermutation
public void updateBestCombinedTypesPermutation() -
updateOfferNotAppliedResponses
public void updateOfferNotAppliedResponses(@NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory, @NonNull org.springframework.context.MessageSource messageSource) -
copyBestPermutationCodeResponses
protected void copyBestPermutationCodeResponses() -
isNotAppliedOffer
-
getAppliedFulfillmentGroupOffers
-
getAppliedOrderOffers
-
getAppliedOrderItemOffers
-
getAppliedFulfillmentItemOffers
-
createCodeResponse
protected com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponse createCodeResponse(OfferNotAppliedReasonEnum notUsedReason, @NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory, @NonNull org.springframework.context.MessageSource messageSource) -
getItemProratedAdjustmentsMap
-
getBestOrderAdjustmentsForTesting
Method facilitates unit testing. This method would not be reliable outside of tests as it does not properly null check the bestOfferPermutation -
getOrderOfferCriteriaMap
-
getItemOfferCriteriaMap
-
getFulfillmentGroupCriteriaMap
public Map<OfferCombinabilityCriteriaKey,OfferCombinabilityCriteria> getFulfillmentGroupCriteriaMap() -
getFulfillmentItemCriteriaMap
public Map<OfferCombinabilityCriteriaKey,OfferCombinabilityCriteria> getFulfillmentItemCriteriaMap() -
getVoucherCriteriaMap
-
getCombinedTypesOfferPermutations
-
isHasOffers
public boolean isHasOffers() -
getOrder
-
getCandidateOffers
-
setBestOfferPermutation
-