Class DefaultOfferCandidateService<P extends Offer>
- All Implemented Interfaces:
OfferCandidateService<P>
- Author:
- Chad Harchar (charchar)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final OfferAuditDetailService<? extends OfferAuditDetail>protected final CandidateOfferUtilitystatic final Stringprotected static final Collector<ItemCriteriaRule,?, Map<ItemCriteriaRule, Collection<EnhancedFulfillmentLineItem>>> protected static final Stringprotected static final Collector<ItemCriteriaRule,?, Map<ItemCriteriaRule, Collection<EnhancedLineItem>>> protected OfferAndOfferCodeUsabilityServiceprotected final com.broadleafcommerce.common.extension.TypeFactoryprotected final OfferUserServicestatic final Stringprotected final com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationServiceprotected final OfferService<P> -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOfferCandidateService(OfferService<P> service, OfferAuditDetailService<? extends OfferAuditDetail> auditService, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.common.extension.TypeFactory offerFactory, OfferUserService offerUserService, CandidateOfferUtility candidateOfferUtility) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddNewCandidateFG(CandidateFulfillmentGroupOffer candidateOffer, EnhancedFulfillmentGroup fulfillmentGroup) protected voidaddNewCandidateFG(CandidateFulfillmentGroupOffer candidateOffer, EnhancedFulfillmentGroup fulfillmentGroup, Map<ItemCriteriaRule, Collection<EnhancedFulfillmentLineItem>> itemCriteriaMap) protected voidaddQualifiersToMap(BaseCandidateOffer candidateOffer, Map<ItemCriteriaRule, Collection<EnhancedLineItem>> itemCriteriaMap) protected voidbuildOfferUsablilityCodeResponses(EnhancedOrder order, List<P> offerList, OffersAndOfferCodesUsabilityInfo usabilityInfo) protected javax.money.MonetaryAmountcalculateStandardPriceSavings(EnhancedOrderLineItem item, CandidateItemOffer itemOffer) protected booleancanUseOrderLineItemsAsQualifiers(String targetType) booleancheckOfferActiveAndTimeCriteria(EnhancedOrder order, P offer) checkOfferUsability(Stream<P> offers, EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) constructCandidateOffer(@NonNull Offer offer, @NonNull EnhancedOrder order) Constructs aBaseCandidateOfferfor the givenOfferandEnhancedOrderaccording the offer'sDiscountTargetType.protected Optional<BaseCandidateOffer>constructCandidateOfferForCustomTargetType(@NonNull Offer offer, @NonNull EnhancedOrder order) Constructs aBaseCandidateOfferfor a customDiscountTargetType.createCandidateOffersFromOffers(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order) Creates aCandidateOffersobject by converting the providedoffersinto their corresponding DTO object based on theirDiscountTargetType.protected com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponsecreateCodeResponse(OfferNotAppliedReasonEnum notUsedReason) protected OfferCodeDataprotected final booleanevaluateAgainstRule(String rule, @NonNull Serializable rootObject) Runs theruleagainst the suppliedrootObjectvia theRuleEvaluationService.protected booleanevaluateFulfillmentItemCriteriaAgainstFulfillmentGroups(EnhancedOrder order, CandidateFulfillmentGroupOffer candidateOffer) protected booleanevaluateFulfillmentItemCriteriaAgainstOrder(@NonNull EnhancedOrder order, @NonNull Map<ItemCriteriaRule, Collection<EnhancedFulfillmentLineItem>> itemCriteriaMap, String connectiveOperator) protected Set<EnhancedFulfillmentLineItem>evaluateGroupForMatchingFulfillmentItems(EnhancedFulfillmentGroup fulfillmentGroup, ItemCriteriaRule itemCriteria) protected booleanevaluateOfferItemCriteriaAgainstOrder(@NonNull EnhancedOrder order, @NonNull BaseCandidateOffer offer, @NonNull Map<ItemCriteriaRule, Collection<EnhancedLineItem>> itemCriteriaMap, String connectiveOperator, boolean isCheckForQualifiers) Evaluates theItemCriteriaRulesfrom an order or order item targeting offer against theOrderto determine whether the offer is applicable.protected Set<EnhancedFulfillmentLineItem>evaluateOrderForMatchingFulfillmentItems(EnhancedOrder order, ItemCriteriaRule itemCriteria) protected Set<EnhancedLineItem>evaluateOrderForMatchingItems(@NonNull List<EnhancedOrderLineItem> orderLineItems, @NonNull ItemCriteriaRule itemCriteriaRule, boolean allowMatchesOnNonDiscountableItems) Evaluates theItemCriteriaRuleagainst theOrder's line itemsto determine if the order matches.protected booleanevaluateSubscriptionDiscountAgainstItems(@NonNull Offer offer, @NonNull Map<ItemCriteriaRule, Collection<EnhancedLineItem>> itemCriteriaMap) Determines if the items match a subscription discount.protected List<BaseCandidateOffer>expandOffersBySegment(BaseCandidateOffer offer, EnhancedOrder order) It is possible for a single offer to be activated using two separate codes that are restricted to different segments.filterDynamicOffers(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order) Filter the provided offer set to remove any dynamic offers for which there is not a correspondingEnhancedOrderattribute matching theOffer.getDynamicOfferKey().filterOffersByExternalDiscountCompatibility(Stream<P> offerSet, EnhancedOrder order) Filters out all Order discountOffersif theorder's external adjustments listis not empty.<T extends BaseCandidateOffer>
List<T>filterOffersByItemQualifiers(@NonNull List<T> candidateOffers, @NonNull EnhancedOrder order) Filter the provided offer set based on if the items of the provided order match as qualifiers.filterOffersByOptInStatus(@NonNull Stream<P> offers, @NonNull EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Filter the provided offer set based on theOffer.getOptInStatus()opt-in status} of the offerfilterOffersByOrderCurrency(Stream<P> offerSet, EnhancedOrder order) Filters out anyOfferswhoseOffer.getCurrency()doesn't match theEnhancedOrder.getCurrency(), if specified.filterOffersByOrderFlow(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order) Filters out anyOfferswhoseOffer.getFlow()doesn't match theEnhancedOrder.getFlow()if specified, unless the offer is an existing offer on the order from checkingEnhancedOrder.getExistingOffers()filterOffersByOrderSubscriptionState(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order) filterOffersByRequest(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order) Filter the provided offer set based on information in the given context of the order.filterOffersByTotalUses(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Filter the provided offer set based on thetotal usesof the offer as well asuser uses, while also factoring inOffer.getMaxUsesPerUserFrequency().filterOffersByUserTarget(Stream<P> offerSet, EnhancedOrder order) filterPaymentOffers(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order) Filter the provided offer set to remove any payment offers that are not relevant.protected OffersAndOfferCodesUsabilityInfogatherOfferAndOfferCodeUsabilityInfo(EnhancedOrder order, List<P> offerList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getAllOfferCodes(@NonNull List<com.broadleafcommerce.promotion.offer.client.web.context.OfferCodeDto> offerCodesDtos, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getAutomaticAndCodeAndCustomerOffers(@NonNull Set<String> offerIdsToFilterOn, @NonNull Set<String> campaignIdsToFilterOn, EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieve offers that are set to automatically be considered or that correspond to the provided offer code(s) or customer specific offers for the provided customer.getAutomaticAndCodeAndCustomerOffers(com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @NonNull com.broadleafcommerce.promotion.offer.client.web.context.Codes codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected intgetBundleItemQuantity(EnhancedFulfillmentLineItem fulfillmentItem) getCandidateOfferCodes(@NonNull EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getCandidateOffers(@NonNull EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Get the candidate offers for the provided order and context.getCandidateVoucherOffers(@NonNull EnhancedOrder order, boolean isPostCheckout, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Get the candidate voucher offers for the provided order and context.protected org.apache.commons.lang3.tuple.Pair<Set<EnhancedFulfillmentLineItem>,Integer> getFulfillmentItemMatchResults(String itemCriteriaRule, EnhancedFulfillmentGroup fulfillmentGroup) protected Map<ItemCriteriaRule,Collection<EnhancedFulfillmentLineItem>> getItemCriteriaCollectionMap(@NonNull ItemCriteria itemQualifierCriteria, @NonNull EnhancedFulfillmentGroup fulfillmentGroup) protected org.springframework.context.MessageSourceprotected OfferAndOfferCodeUsabilityServiceprotected OfferCodeService<OfferCode>protected @NotNull Map<String,List<OfferOptIn>> getOfferOptIns(EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, List<String> tenantOfferIds) getOffersForMessaging(Set<String> offerIds, EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieve offers that are automatically applied and applicable for marketing messaging.getOffersForSharedCodes(EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getOffersToFilter(@NonNull EnhancedOrder order, @NonNull Set<String> offerIdsToFilterOn, @NonNull Set<String> campaignIdsToFilterOn, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Get available offers that need to be filtered to become candidates.protected OfferOptInService<OfferOptIn>getVoucherOffers(com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @NonNull List<com.broadleafcommerce.promotion.offer.client.web.context.OfferCodeDto> offerCodeDtos, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieve voucher offers that are set to automatically be considered or that correspond to the provided offer code(s) or customer specific offers for the provided customer.protected voidinitializeSubscriptionRelatedOfferBasedOnExistingSubscription(@NonNull EnhancedOrder order, @NonNull BaseCandidateOffer candidateOffer) Initializes subscription related offer based on the existing subscription.voidinitializeWithCodeProperties(@NonNull EnhancedOrder order, @NonNull CandidateOffers candidateOffers, @NonNull BaseCandidateOffer candidateOffer) protected final booleanisAnyMatchCriteria(String connectiveOperator) Checks whether the operator matchesDefaultConnectiveOperatorType.OR, meaning that only 1 of theItemCriteria's rulesneed be matched.protected booleanisAnyMatchFoundAcrossAllItems(@NonNull EnhancedOrder order, @NonNull CandidateFulfillmentGroupOffer candidateOffer, @NonNull Offer offer) protected booleanisAnyMatchFoundInAnyFulfillmentGroup(EnhancedOrder order, CandidateFulfillmentGroupOffer candidateOffer, Offer offer) protected booleanisCanUseOfferCodes(OffersAndOfferCodesUsabilityInfo usabilityInfo, P offer) protected booleanisFreeGiftItem(@NonNull EnhancedLineItem orderItem) Determines if the givenEnhancedLineItemis a free gift item.protected booleanisMinSubtotalMet(javax.money.MonetaryAmount minSubtotalRequired, Set<? extends EnhancedLineItem> itemsToSum) protected booleanmatchIsAllowedForItem(@NonNull EnhancedLineItem orderItem, boolean allowMatchesOnNonDiscountableItems) Determine whether or not a match is allowed for the line item.populateOrRemoveByFulfillmentGroupTargets(@NonNull List<CandidateFulfillmentGroupOffer> candidateOfferList, EnhancedOrder order) Filter the provided offer set based on if the provided fulfillment groups of the order match as shipping targets.populateOrRemoveCandidateOffers(@NonNull Stream<P> offerSet, @NonNull EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Filter out the provided offer set by matching their configurations against the information on the provided context and order.populateOrRemoveOffersByFulfillmentGroupQualifiers(@NonNull List<CandidateFulfillmentGroupOffer> candidateOfferSet, @NonNull EnhancedOrder order) Filter the provided offer set based on if the items of the provided order match as qualifiers.populateOrRemoveOffersByFulfillmentItemQualifiers(@NonNull List<CandidateItemOffer> candidateOfferSet, @NonNull EnhancedOrder order) Filter the provided offer set based on if the fulfillment items of the provided order match as qualifiers.populateOrRemoveOffersByFulfillmentItemTargets(@NonNull List<CandidateItemOffer> candidateOfferSet, @NonNull EnhancedOrder order) Filter the provided offer set based on if the provided fulfillment items of the order match as shipping targets.populateOrRemoveOffersByItemTargets(@NonNull List<CandidateItemOffer> candidateOfferSet, @NonNull EnhancedOrder order) Filter the provided offer set based on if the items of the provided order match as targets.voidsetMessageSource(org.springframework.context.MessageSource messageSource) voidsetOfferAndOfferCodeUsabilityService(OfferAndOfferCodeUsabilityService offerAndOfferCodeUsabilityService) voidsetOfferCodeService(OfferCodeService<OfferCode> offerCodeService) voidsetOptInService(OfferOptInService<OfferOptIn> optInService) protected booleanshouldIncludeItem(EnhancedOrderLineItem item, EnhancedOrder order, BaseCandidateOffer offer) Deprecated, for removal: This API element is subject to removal in a future version.protected booleanshouldIncludeItem(EnhancedOrderLineItem item, EnhancedOrder order, BaseCandidateOffer offer, boolean isCheckForQualifiers) Whether the givenEnhancedOrderLineItemshould be considered when evaluating anItemCriteriaRule.protected booleanshouldIncludeOnSaleItem(EnhancedOrderLineItem item, BaseCandidateOffer candidateOffer) protected voidupdateNotFoundCodes(EnhancedOrder order, List<OfferCode> offerCodes, List<P> sharedCodeOffers) protected voidupdateReasonResponsesForTargetNotMet(@NotNull EnhancedOrder order, Offer offer)
-
Field Details
-
ITEM_CRITERIA_MAP_COLLECTOR
protected static final Collector<ItemCriteriaRule,?, ITEM_CRITERIA_MAP_COLLECTORMap<ItemCriteriaRule, Collection<EnhancedLineItem>>> -
FULFILLMENT_ITEM_CRITERIA_MAP_COLLECTOR
protected static final Collector<ItemCriteriaRule,?, FULFILLMENT_ITEM_CRITERIA_MAP_COLLECTORMap<ItemCriteriaRule, Collection<EnhancedFulfillmentLineItem>>> -
IS_FREE_GIFT_ITEM
- See Also:
-
DYNAMIC_OFFER_MAP
- See Also:
-
PAYMENTS_LIST
- See Also:
-
service
-
auditService
-
ruleEvaluationService
protected final com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService -
offerFactory
protected final com.broadleafcommerce.common.extension.TypeFactory offerFactory -
offerUserService
-
candidateOfferUtility
-
offerAndOfferCodeUsabilityService
-
-
Constructor Details
-
DefaultOfferCandidateService
public DefaultOfferCandidateService(OfferService<P> service, OfferAuditDetailService<? extends OfferAuditDetail> auditService, com.broadleafcommerce.rulesengine.expression.service.RuleEvaluationService ruleEvaluationService, com.broadleafcommerce.common.extension.TypeFactory offerFactory, OfferUserService offerUserService, CandidateOfferUtility candidateOfferUtility)
-
-
Method Details
-
getCandidateOffers
@NonNull public CandidateOffers getCandidateOffers(@NonNull @NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceGet the candidate offers for the provided order and context.- Specified by:
getCandidateOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
order- context information around the offercontextInfo- context information around sandbox and multitenant state- Returns:
- the list of offers that are candidates to be applied to the provided order.
-
updateNotFoundCodes
protected void updateNotFoundCodes(EnhancedOrder order, List<OfferCode> offerCodes, List<P> sharedCodeOffers) -
createCodeResponse
protected com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponse createCodeResponse(OfferNotAppliedReasonEnum notUsedReason) -
createOfferCodeData
-
getCandidateOfferCodes
protected List<OfferCode> getCandidateOfferCodes(@NonNull @NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getCandidateVoucherOffers
@NonNull public List<CandidateOrderOffer> getCandidateVoucherOffers(@NonNull @NonNull EnhancedOrder order, boolean isPostCheckout, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceGet the candidate voucher offers for the provided order and context.- Specified by:
getCandidateVoucherOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
order- context information around the offercontextInfo- context information around sandbox and multitenant state- Returns:
- the list of voucher offers that are candidates to be applied to the provided order.
-
getOffersToFilter
@NonNull public Stream<P> getOffersToFilter(@NonNull @NonNull EnhancedOrder order, @NonNull @NonNull Set<String> offerIdsToFilterOn, @NonNull @NonNull Set<String> campaignIdsToFilterOn, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceGet available offers that need to be filtered to become candidates. This gets offers by user, codes, and automatic offers.- Specified by:
getOffersToFilterin interfaceOfferCandidateService<P extends Offer>- Parameters:
order- context information around the offercontextInfo- context information around sandbox and multitenant state- Returns:
- a set of all available offers that need to be filtered down to become candidates.
-
getOffersForMessaging
@NonNull public List<P> getOffersForMessaging(Set<String> offerIds, @Nullable EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceRetrieve offers that are automatically applied and applicable for marketing messaging. The implementation will utilize the order to filter the returned offers.- Specified by:
getOffersForMessagingin interfaceOfferCandidateService<P extends Offer>order- the order to determine context information around the customer and other filterscontextInfo- context information around sandbox and multitenant state- Returns:
- list of offers for automatic consideration or customer specific for the provided customer or that correspond to the provided offer code(s).
-
getAutomaticAndCodeAndCustomerOffers
@NonNull public Stream<P> getAutomaticAndCodeAndCustomerOffers(@Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @NonNull @NonNull com.broadleafcommerce.promotion.offer.client.web.context.Codes codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
getAutomaticAndCodeAndCustomerOffersin interfaceOfferCandidateService<P extends Offer>
-
getAutomaticAndCodeAndCustomerOffers
@NonNull public Stream<P> getAutomaticAndCodeAndCustomerOffers(@NonNull @NonNull Set<String> offerIdsToFilterOn, @NonNull @NonNull Set<String> campaignIdsToFilterOn, @Nullable EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceRetrieve offers that are set to automatically be considered or that correspond to the provided offer code(s) or customer specific offers for the provided customer.- Specified by:
getAutomaticAndCodeAndCustomerOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
offerIdsToFilterOn- List of relevant offer Ids to filter query on.campaignIdsToFilterOn- List of relevant campaign Ids to filter query on.order- the order to determine context information around the customer and other filterscontextInfo- context information around sandbox and multitenant state- Returns:
- list of offers for automatic consideration or customer specific for the provided customer or that correspond to the provided offer code(s).
-
getVoucherOffers
@NonNull public Stream<P> getVoucherOffers(@Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @NonNull @NonNull List<com.broadleafcommerce.promotion.offer.client.web.context.OfferCodeDto> offerCodeDtos, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceRetrieve voucher offers that are set to automatically be considered or that correspond to the provided offer code(s) or customer specific offers for the provided customer.- Specified by:
getVoucherOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
customerContext- context information around the customerofferCodeDtos- DTO containing relevant codes such asshared codesand Campaign tracking IDs.contextInfo- context information around sandbox and multitenant state- Returns:
- list of voucher offers based on the customer context or the provided offer codes
-
getAllOfferCodes
-
populateOrRemoveCandidateOffers
@NonNull public CandidateOffers populateOrRemoveCandidateOffers(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceFilter out the provided offer set by matching their configurations against the information on the provided context and order. For matching offers, associate the relevant item qualifiers and targets that might be used for the offer.- Specified by:
populateOrRemoveCandidateOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
offerSet- filtered offer set that can apply to the order for the context.order- context information around the ordercontextInfo- context information around sandbox and multitenant state
-
createCandidateOffersFromOffers
@NonNull public CandidateOffers createCandidateOffersFromOffers(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceCreates aCandidateOffersobject by converting the providedoffersinto their corresponding DTO object based on theirDiscountTargetType. The DTO objects areCandidateOrderOffer,CandidateItemOffer, andCandidateFulfillmentGroupOffer- Specified by:
createCandidateOffersFromOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
offerSet- The set of offers to use to create aCandidateOffersorder- order context to pupulate the candidate offers onCandidateOffers- Returns:
- the
CandidateOffersbuilt from the provided offer set
-
initializeWithCodeProperties
public void initializeWithCodeProperties(@NonNull @NonNull EnhancedOrder order, @NonNull @NonNull CandidateOffers candidateOffers, @NonNull @NonNull BaseCandidateOffer candidateOffer) -
constructCandidateOffer
public Optional<BaseCandidateOffer> constructCandidateOffer(@NonNull @NonNull Offer offer, @NonNull @NonNull EnhancedOrder order) Constructs aBaseCandidateOfferfor the givenOfferandEnhancedOrderaccording the offer'sDiscountTargetType.- Parameters:
offer- the offer for which to construct a candidate offer.order- the order that may receive discounts.- Returns:
- the
BaseCandidateOfferfor the given offer, or an empty if not handled. - See Also:
-
initializeSubscriptionRelatedOfferBasedOnExistingSubscription
protected void initializeSubscriptionRelatedOfferBasedOnExistingSubscription(@NonNull @NonNull EnhancedOrder order, @NonNull @NonNull BaseCandidateOffer candidateOffer) Initializes subscription related offer based on the existing subscription.For
Subscription Offers, it initializes theOffer.getSubscriptionDiscount()'sSubscriptionDiscount.getBeginPeriod()andSubscriptionDiscount.getEndPeriod()based on the current state of the subscription.This is only relevant for post-purchase subscription flows such as
DefaultOrderFlow.SUBSCRIPTION_EDITorDefaultOrderFlow.SUBSCRIPTION_UPGRADE, and notDefaultOrderFlow.SUBSCRIPTION_CREATE.For example, let's say there is an offer targeting the
DefaultOrderFlow.SUBSCRIPTION_UPGRADEflow for 20% off for the first 3 months of upgrade. If a user has had a subscription active for 3 months (theEnhancedOrder.getSubscriptionNextPeriod()would be 4) and then upgrade, the newly applied offer should apply for the next 3 months and should have a beginPeriod of 4 and endPeriod of 6.If the offer is an
Existing Offer, nothing needs to be done as the begin and end period should already be set correctly.- Parameters:
order- theEnhancedOrdercontaining the existing subscription detailscandidateOffer- theBaseCandidateOfferto initialize the subscription discount- Since:
- Offer Services 3.2.0, Release Train 2.3.0
-
constructCandidateOfferForCustomTargetType
protected Optional<BaseCandidateOffer> constructCandidateOfferForCustomTargetType(@NonNull @NonNull Offer offer, @NonNull @NonNull EnhancedOrder order) Constructs aBaseCandidateOfferfor a customDiscountTargetType.- Parameters:
offer- The offer for which to construct a candidate offer.order- The order that may receive discounts.- Returns:
- The
BaseCandidateOfferfor the custom target type, or an empty if not handled. - Since:
- Offer Services 3.2.0, Release Train 2.3.0
- See Also:
-
expandOffersBySegment
protected List<BaseCandidateOffer> expandOffersBySegment(BaseCandidateOffer offer, EnhancedOrder order) It is possible for a single offer to be activated using two separate codes that are restricted to different segments. In this case, the process copies the offer which is processed separately for each segment.- Parameters:
offer-- Returns:
-
filterDynamicOffers
public Stream<P> filterDynamicOffers(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set to remove any dynamic offers for which there is not a correspondingEnhancedOrderattribute matching theOffer.getDynamicOfferKey().- Specified by:
filterDynamicOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
offerSet- filtered offer set that can apply to the order for the context.order- the order with which to evaluate request criteria against- Returns:
- the offers after filtering
-
filterPaymentOffers
public Stream<P> filterPaymentOffers(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set to remove any payment offers that are not relevant.- Specified by:
filterPaymentOffersin interfaceOfferCandidateService<P extends Offer>- Parameters:
offerSet- filtered offer set that can apply to the order for the context.order- the order with which to evaluate request criteria against- Returns:
- the offers after filtering
-
filterOffersByRequest
public Stream<P> filterOffersByRequest(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on information in the given context of the order. This evaluates theEnhancedOrderagainst the offer'sorder criteriaandOffer.getTargetItemCriteria().- Specified by:
filterOffersByRequestin interfaceOfferCandidateService<P extends Offer>- Parameters:
offerSet- filtered offer set that can apply to the order for the context.order- the order with which to evaluate request criteria against- Returns:
- the filtered offer set that can apply to the order.
-
checkOfferActiveAndTimeCriteria
-
filterOffersByTotalUses
public Stream<P> filterOffersByTotalUses(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on thetotal usesof the offer as well asuser uses, while also factoring inOffer.getMaxUsesPerUserFrequency().- Specified by:
filterOffersByTotalUsesin interfaceOfferCandidateService<P extends Offer>- Parameters:
offerSet- filtered offer set that can apply to the order.order- context information around the ordercontextInfo- context information around sandbox and multitenant state- Returns:
- the filtered offer set that can apply to the order.
-
filterOffersByUserTarget
-
filterOffersByOrderCurrency
Filters out anyOfferswhoseOffer.getCurrency()doesn't match theEnhancedOrder.getCurrency(), if specified.- Parameters:
offerSet- the set of offers to filterorder- theEnhancedOrderto check the currency against- Returns:
- a filtered stream of offers where the specified currency is null or matches
EnhancedOrder.getCurrency() - See Also:
-
filterOffersByOrderFlow
protected Stream<P> filterOffersByOrderFlow(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order) Filters out anyOfferswhoseOffer.getFlow()doesn't match theEnhancedOrder.getFlow()if specified, unless the offer is an existing offer on the order from checkingEnhancedOrder.getExistingOffers()The check for existing offers is to ensure that they are not lost in post-purchase flows. For example, if an order has an offer applied for 10% off the VPN products, if the user upgrades from VPN-BASIC to VPN-PLUS, the existing offer should still be applied.
If the
Offer.getFlow()isnullorDefaultOrderFlow.ANY, then it is applicable to any flows.- Parameters:
offerSet- the set of offers to filterorder- theEnhancedOrderto check the flow against- Returns:
- a filtered stream of offers where the specified flow is null or
DefaultOrderFlow.ANYor matchesEnhancedOrder.getFlow() - Since:
- Offer Services 3.2.0, Release Train 2.3.0
- See Also:
-
filterOffersByExternalDiscountCompatibility
protected Stream<P> filterOffersByExternalDiscountCompatibility(@NonNull Stream<P> offerSet, EnhancedOrder order) Filters out all Order discountOffersif theorder's external adjustments listis not empty.- Parameters:
offerSet- the set of offers to filterorder- theEnhancedOrderwith theexternal adjustments list- Returns:
- a filtered stream of offers that will either be non-order discount offers if there are external adjustments or return the same stream if there are none
-
filterOffersByOrderSubscriptionState
protected Stream<P> filterOffersByOrderSubscriptionState(@NonNull @NonNull Stream<P> offerSet, @NonNull @NonNull EnhancedOrder order) -
checkOfferUsability
protected Stream<P> checkOfferUsability(Stream<P> offers, EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
filterOffersByOptInStatus
public Stream<P> filterOffersByOptInStatus(@NonNull @NonNull Stream<P> offers, @NonNull @NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on theOffer.getOptInStatus()opt-in status} of the offer- Specified by:
filterOffersByOptInStatusin interfaceOfferCandidateService<P extends Offer>- Parameters:
offers- filtered offer set that can apply to the order.order- context information around the ordercontextInfo- context information around sandbox and multitenant state- Returns:
- the filtered offer set that can apply to the order.
-
getOfferOptIns
@NotNull protected @NotNull Map<String,List<OfferOptIn>> getOfferOptIns(EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, List<String> tenantOfferIds) -
isCanUseOfferCodes
-
buildOfferUsablilityCodeResponses
protected void buildOfferUsablilityCodeResponses(EnhancedOrder order, List<P> offerList, OffersAndOfferCodesUsabilityInfo usabilityInfo) -
gatherOfferAndOfferCodeUsabilityInfo
protected OffersAndOfferCodesUsabilityInfo gatherOfferAndOfferCodeUsabilityInfo(EnhancedOrder order, List<P> offerList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
filterOffersByItemQualifiers
public <T extends BaseCandidateOffer> List<T> filterOffersByItemQualifiers(@NonNull @NonNull List<T> candidateOffers, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on if the items of the provided order match as qualifiers. For each of theOffer.getItemQualifierCriteria(), a quantity of at leastItemCriteriaRule.getNumberOfMatchesRequired()items must match againstItemCriteriaRule.getRule(). In addition, the summed price of these items must be at leastOffer.getMinTotalOfQualifierPrices().- Specified by:
filterOffersByItemQualifiersin interfaceOfferCandidateService<P extends Offer>- Parameters:
candidateOffers- filtered offer set that can apply to the order.order- the order with which to evaluate items against- Returns:
- the filtered offer set that can apply to the order.
-
populateOrRemoveOffersByFulfillmentGroupQualifiers
public List<CandidateFulfillmentGroupOffer> populateOrRemoveOffersByFulfillmentGroupQualifiers(@NonNull @NonNull List<CandidateFulfillmentGroupOffer> candidateOfferSet, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on if the items of the provided order match as qualifiers. For each of theOffer.getItemQualifierCriteria(), a quantity of at leastItemCriteriaRule.getNumberOfMatchesRequired()items must match againstItemCriteriaRule.getRule(). In addition, the summed price of these items must be at leastOffer.getMinTotalOfQualifierPrices().- Specified by:
populateOrRemoveOffersByFulfillmentGroupQualifiersin interfaceOfferCandidateService<P extends Offer>- Parameters:
candidateOfferSet- filtered offer set that can apply to the order.order- the order with which to evaluate items against- Returns:
- the filtered offer set that can apply to the order.
-
canUseOrderLineItemsAsQualifiers
-
addQualifiersToMap
protected void addQualifiersToMap(BaseCandidateOffer candidateOffer, Map<ItemCriteriaRule, Collection<EnhancedLineItem>> itemCriteriaMap) -
evaluateFulfillmentItemCriteriaAgainstFulfillmentGroups
protected boolean evaluateFulfillmentItemCriteriaAgainstFulfillmentGroups(EnhancedOrder order, CandidateFulfillmentGroupOffer candidateOffer) -
isAnyMatchFoundInAnyFulfillmentGroup
protected boolean isAnyMatchFoundInAnyFulfillmentGroup(EnhancedOrder order, CandidateFulfillmentGroupOffer candidateOffer, Offer offer) -
isAnyMatchFoundAcrossAllItems
protected boolean isAnyMatchFoundAcrossAllItems(@NonNull @NonNull EnhancedOrder order, @NonNull @NonNull CandidateFulfillmentGroupOffer candidateOffer, @NonNull @NonNull Offer offer) -
getItemCriteriaCollectionMap
protected Map<ItemCriteriaRule,Collection<EnhancedFulfillmentLineItem>> getItemCriteriaCollectionMap(@NonNull @NonNull ItemCriteria itemQualifierCriteria, @NonNull @NonNull EnhancedFulfillmentGroup fulfillmentGroup) -
addNewCandidateFG
protected void addNewCandidateFG(CandidateFulfillmentGroupOffer candidateOffer, EnhancedFulfillmentGroup fulfillmentGroup) -
addNewCandidateFG
protected void addNewCandidateFG(CandidateFulfillmentGroupOffer candidateOffer, EnhancedFulfillmentGroup fulfillmentGroup, @Nullable Map<ItemCriteriaRule, Collection<EnhancedFulfillmentLineItem>> itemCriteriaMap) -
evaluateOrderForMatchingItems
protected Set<EnhancedLineItem> evaluateOrderForMatchingItems(@NonNull @NonNull List<EnhancedOrderLineItem> orderLineItems, @NonNull @NonNull ItemCriteriaRule itemCriteriaRule, boolean allowMatchesOnNonDiscountableItems) Evaluates theItemCriteriaRuleagainst theOrder's line itemsto determine if the order matches.- Parameters:
orderLineItems- Line item to evaluate theitemCriteriaRuleagainstitemCriteriaRule- Rule to evaluateallowMatchesOnNonDiscountableItems- Whether or not matches will be allowed for non-discountable items. For target rule evaluation, we expect this value to be false. For qualifier rule evaluation, we expect this value to be true.- Returns:
- The
order line itemsthat matched the criteria or empty if none.
-
matchIsAllowedForItem
protected boolean matchIsAllowedForItem(@NonNull @NonNull EnhancedLineItem orderItem, boolean allowMatchesOnNonDiscountableItems) Determine whether or not a match is allowed for the line item.By default, free gift items are not allowed to match the criteria. Additionally, items that are not free gifts and not discountable are only allowed to match the criteria if allowMatchesOnNonDiscountableItems is true. This allows us to block the matching of offer target criteria against items that are not eligible to receive a discount. For offer qualifying criteria, it doesn't matter whether or not the item is discountable. Therefore, we'd expect allowMatchesOnNonDiscountableItems to be true when evaluating qualifier rules.
- Parameters:
orderItem- The item who's being evaluated as a match to the promotion's criteriaallowMatchesOnNonDiscountableItems- Whether or not matches will be allowed for non-discountable items. For target rule evaluation, we expect this value to be false. For qualifier rule evaluation, we expect this value to be true.- Returns:
- Whether or not the criteria should be evaluated against the item
-
isFreeGiftItem
Determines if the givenEnhancedLineItemis a free gift item.- Parameters:
orderItem- theEnhancedLineItemto check against- Returns:
- true if the given
EnhancedLineItemis a free gift item, otherwise false
-
populateOrRemoveOffersByItemTargets
public List<CandidateItemOffer> populateOrRemoveOffersByItemTargets(@NonNull @NonNull List<CandidateItemOffer> candidateOfferSet, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on if the items of the provided order match as targets. For each of theOffer.getTargetItemCriteria(), a quantity of at leastItemCriteriaRule.getNumberOfMatchesRequired()items must match againstItemCriteriaRule.getRule(). In addition, the summed price of these items must be at leastOffer.getMinTotalOfTargetPrices().- Specified by:
populateOrRemoveOffersByItemTargetsin interfaceOfferCandidateService<P extends Offer>- Parameters:
candidateOfferSet- filtered offer set that can apply to the order.order- the order with which to evaluate items against- Returns:
- the filtered offer set that can apply to the order.
-
updateReasonResponsesForTargetNotMet
protected void updateReasonResponsesForTargetNotMet(@NotNull @NotNull EnhancedOrder order, Offer offer) -
evaluateSubscriptionDiscountAgainstItems
protected boolean evaluateSubscriptionDiscountAgainstItems(@NonNull @NonNull Offer offer, @NonNull @NonNull Map<ItemCriteriaRule, Collection<EnhancedLineItem>> itemCriteriaMap) Determines if the items match a subscription discount. Also returns true if the offer is not a subscription discount.- Parameters:
offer- The offer being evaluateditemCriteriaMap- The item criteria- Returns:
- Whether the subscription offer has any valid targets.
-
isMinSubtotalMet
protected boolean isMinSubtotalMet(javax.money.MonetaryAmount minSubtotalRequired, Set<? extends EnhancedLineItem> itemsToSum) -
evaluateOfferItemCriteriaAgainstOrder
protected boolean evaluateOfferItemCriteriaAgainstOrder(@NonNull @NonNull EnhancedOrder order, @NonNull @NonNull BaseCandidateOffer offer, @NonNull @NonNull Map<ItemCriteriaRule, Collection<EnhancedLineItem>> itemCriteriaMap, String connectiveOperator, boolean isCheckForQualifiers) Evaluates theItemCriteriaRulesfrom an order or order item targeting offer against theOrderto determine whether the offer is applicable.- Parameters:
order- Order to evaluate the rules againstoffer- Offer the Offer being evaluateditemCriteriaMap- Map containing the rules as keys to be populated with the matching line items as valuesconnectiveOperator- How the rules should be connected logically. This is usually "and" or "or" and determines whether all must match or just any. SeeItemCriteria.getConnectiveOperator().isCheckForQualifiers- Whether matches are being made for qualifier rather than target items. For qualifiers, we allow matches against non-discountable items and items whose currencies don't match.Non-discountable includes dependent items when the offer does not allow discounting dependents:
Discount.isApplicableToDependentItems().- Returns:
- Whether enough of the offer's criteria were satisfied by the
order.
-
shouldIncludeItem
@Deprecated(forRemoval=true) protected boolean shouldIncludeItem(EnhancedOrderLineItem item, EnhancedOrder order, BaseCandidateOffer offer) Deprecated, for removal: This API element is subject to removal in a future version. -
shouldIncludeItem
protected boolean shouldIncludeItem(EnhancedOrderLineItem item, EnhancedOrder order, BaseCandidateOffer offer, boolean isCheckForQualifiers) Whether the givenEnhancedOrderLineItemshould be considered when evaluating anItemCriteriaRule.- Parameters:
item- The item to determine whether to include for evaluation.order- The parent orderoffer- The parent of theItemCriteriaRulethat will be evaluated.isCheckForQualifiers- Whether matches are being made for qualifier rather than target items. For qualifiers, we allow matches against non-discountable items and items whose currencies don't match.Non-discountable includes dependent items when the offer does not allow discounting dependents:
Discount.isApplicableToDependentItems().- Returns:
- Whether the given
EnhancedOrderLineItemshould be considered when evaluating anItemCriteriaRule.
-
shouldIncludeOnSaleItem
protected boolean shouldIncludeOnSaleItem(EnhancedOrderLineItem item, BaseCandidateOffer candidateOffer) -
calculateStandardPriceSavings
protected javax.money.MonetaryAmount calculateStandardPriceSavings(@NonNull EnhancedOrderLineItem item, CandidateItemOffer itemOffer) -
populateOrRemoveByFulfillmentGroupTargets
public List<CandidateFulfillmentGroupOffer> populateOrRemoveByFulfillmentGroupTargets(@NonNull @NonNull List<CandidateFulfillmentGroupOffer> candidateOfferList, EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on if the provided fulfillment groups of the order match as shipping targets. Thefulfillment group'sdetails are evaluated against theoffer's fulfillment group criteria.- Specified by:
populateOrRemoveByFulfillmentGroupTargetsin interfaceOfferCandidateService<P extends Offer>- Parameters:
candidateOfferList- filtered offer set that can apply to the order.order- the order with which to evaluate items against- Returns:
- the filtered offer set that can apply to the order.
-
populateOrRemoveOffersByFulfillmentItemQualifiers
public List<CandidateItemOffer> populateOrRemoveOffersByFulfillmentItemQualifiers(@NonNull @NonNull @NonNull List<CandidateItemOffer> candidateOfferSet, @NonNull @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on if the fulfillment items of the provided order match as qualifiers. For each of theOffer.getItemQualifierCriteria(), a quantity of at leastItemCriteriaRule.getNumberOfMatchesRequired()items must match againstItemCriteriaRule.getRule(). In addition, the summed price of these items must be at leastOffer.getMinTotalOfQualifierPrices().- Specified by:
populateOrRemoveOffersByFulfillmentItemQualifiersin interfaceOfferCandidateService<P extends Offer>- Parameters:
candidateOfferSet- filtered offer set that can apply to the order.order- the order with which to evaluate items against- Returns:
- the filtered offer set that can apply to the order.
-
populateOrRemoveOffersByFulfillmentItemTargets
public List<CandidateItemOffer> populateOrRemoveOffersByFulfillmentItemTargets(@NonNull @NonNull List<CandidateItemOffer> candidateOfferSet, @NonNull @NonNull EnhancedOrder order) Description copied from interface:OfferCandidateServiceFilter the provided offer set based on if the provided fulfillment items of the order match as shipping targets. At least oneEnhancedFulfillmentLineItemmust match the offer'sItemCriteriaRule.getRule()with the total quantity matchingItemCriteriaRule.getNumberOfMatchesRequired().- Specified by:
populateOrRemoveOffersByFulfillmentItemTargetsin interfaceOfferCandidateService<P extends Offer>- Parameters:
candidateOfferSet- filtered offer set that can apply to the order.order- the order with which to evaluate items against- Returns:
- the filtered offer set that can apply to the order.
-
evaluateAgainstRule
protected final boolean evaluateAgainstRule(@Nullable String rule, @NonNull @NonNull Serializable rootObject) Runs theruleagainst the suppliedrootObjectvia theRuleEvaluationService.- Parameters:
rule- Rule to evaluaterootObject- Object against which to evaluaterule- Returns:
- Whether the
rootObjectsatisfied therule
-
evaluateFulfillmentItemCriteriaAgainstOrder
protected boolean evaluateFulfillmentItemCriteriaAgainstOrder(@NonNull @NonNull EnhancedOrder order, @NonNull @NonNull Map<ItemCriteriaRule, Collection<EnhancedFulfillmentLineItem>> itemCriteriaMap, String connectiveOperator) -
evaluateOrderForMatchingFulfillmentItems
protected Set<EnhancedFulfillmentLineItem> evaluateOrderForMatchingFulfillmentItems(EnhancedOrder order, ItemCriteriaRule itemCriteria) -
getFulfillmentItemMatchResults
protected org.apache.commons.lang3.tuple.Pair<Set<EnhancedFulfillmentLineItem>,Integer> getFulfillmentItemMatchResults(String itemCriteriaRule, EnhancedFulfillmentGroup fulfillmentGroup) -
getBundleItemQuantity
-
evaluateGroupForMatchingFulfillmentItems
protected Set<EnhancedFulfillmentLineItem> evaluateGroupForMatchingFulfillmentItems(EnhancedFulfillmentGroup fulfillmentGroup, ItemCriteriaRule itemCriteria) -
isAnyMatchCriteria
Checks whether the operator matchesDefaultConnectiveOperatorType.OR, meaning that only 1 of theItemCriteria's rulesneed be matched.- Parameters:
connectiveOperator- AItemCriteria.getConnectiveOperator()from an offer whose criteria is to be evaluated- Returns:
- whether the operator matches
DefaultConnectiveOperatorType.OR, meaning that only 1 of theItemCriteria's rulesneed be matched.
-
getOfferAndOfferCodeUsabilityService
-
setOfferAndOfferCodeUsabilityService
@Autowired public void setOfferAndOfferCodeUsabilityService(OfferAndOfferCodeUsabilityService offerAndOfferCodeUsabilityService) -
getOfferCodeService
-
setOfferCodeService
-
getOptInService
-
setOptInService
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
setMessageSource
@Autowired public void setMessageSource(org.springframework.context.MessageSource messageSource)
-
shouldIncludeItem(EnhancedOrderLineItem, EnhancedOrder, BaseCandidateOffer, boolean).