Class DefaultMarketingMessageResolver<P extends MarketingMessage,O extends Offer>
java.lang.Object
com.broadleafcommerce.promotion.offer.service.DefaultMarketingMessageResolver<P,O>
- All Implemented Interfaces:
MarketingMessageResolver<P,
O>
public class DefaultMarketingMessageResolver<P extends MarketingMessage,O extends Offer>
extends Object
implements MarketingMessageResolver<P,O>
- Author:
- Jon Fleschler (jfleschler)
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected final MarketingMessageOfferCandidateService<O>
protected final MarketingMessageService<P>
protected final OfferCandidateService<O>
protected final OfferService<O>
protected final com.broadleafcommerce.common.extension.TypeFactory
-
Constructor Summary
ConstructorDescriptionDefaultMarketingMessageResolver
(MarketingMessageService<P> marketingMessageService, OfferCandidateService<O> offerCandidateService, OfferService<O> offerService, MarketingMessageOfferCandidateService<O> marketingMessageOfferCandidateService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addMessageToResponse
(MarketingMessageRequest request, MarketingMessageResponse<P> response, P message, List<String> productIds) protected EnhancedOrder
buildEnhancedOrderForMarketingMessageRequest
(MarketingMessageRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Build a simple order to use for offer filtering based on customer if neededprotected MarketingMessageResponse<P>
buildMarketingMessageResponse
(MarketingMessageRequest request, List<P> messages, Map<String, O> offerMap) Removes messages that are targeted to specific qualifiers or targets with no matching items before populating the response structures.buildOfferMap
(List<P> marketingMessages, MarketingMessageRequest marketingMessageRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a Map of offerId to offer for the passed in marketing messages based on theMarketingMessage.getOfferId()
The list will filter out offers that are not valid based on active dates and customer context.checkForMatchingProducts
(O offer, List<EnhancedLineItem> lineItems, boolean includeTargets, boolean includeQualifiers) filterMessages
(List<P> messageList, MarketingMessageRequest request, Map<String, O> offerMap) filterMessagesByAppliedOffers
(Stream<P> messageSet, MarketingMessageRequest request) filterMessagesByCartSubtotal
(Stream<P> messageSet, MarketingMessageRequest request) filterMessagesWithoutActiveOffer
(Stream<P> messageSet, MarketingMessageRequest request, Map<String, O> offerMap) findAllMarketingMessagesForRequest
(MarketingMessageRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds all of theMarketingMessages
for the providedMarketingMessageRequest
.findRelevantMessages
(MarketingMessageRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Default implementation that is tuned for full message repository caching and assumes a relatively small number of active messages (e.g.protected boolean
isItemOffer
(Offer offer) Checks if theOffer
targets an order or fulfillment group item.protected boolean
isItemQualifier
(Offer offer, EnhancedLineItem item) Checks if any of the rules inOffer.getItemQualifierCriteria()
matches the line item on this request in order to determine if the line item can be used to qualify for the offer.protected boolean
isItemTarget
(Offer offer, EnhancedLineItem item) If this is an item offer, checks if any of the rules inOffer.getTargetItemCriteria()
matches the line item on this request in order to determine if the line item can be used as the target for the offer.protected ItemCriteria
modifyItemCriteria
(Offer offer, ItemCriteria itemCriteria) In certain cases (i.e.protected void
-
Field Details
-
ATTRIBUTES_ORDER_LINE_ITEM
- See Also:
-
marketingMessageService
-
offerCandidateService
-
offerService
-
marketingMessageOfferCandidateService
protected final MarketingMessageOfferCandidateService<O extends Offer> marketingMessageOfferCandidateService -
typeFactory
protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory
-
-
Constructor Details
-
DefaultMarketingMessageResolver
public DefaultMarketingMessageResolver(MarketingMessageService<P> marketingMessageService, OfferCandidateService<O> offerCandidateService, OfferService<O> offerService, MarketingMessageOfferCandidateService<O> marketingMessageOfferCandidateService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
findAllMarketingMessagesForRequest
public MarketingMessageResponse<P> findAllMarketingMessagesForRequest(MarketingMessageRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:MarketingMessageResolver
Finds all of theMarketingMessages
for the providedMarketingMessageRequest
. This will find all the activeOffers
first, then split them into two, filtered groups: Those that treat theMarketingMessageRequest.getLineItems()
as a target and those that treat it as a qualifier. Then, it will fetch all messages for those offers, grouping byMarketingMessageLocationType
, filter by active date range and sort them by priority.- Specified by:
findAllMarketingMessagesForRequest
in interfaceMarketingMessageResolver<P extends MarketingMessage,
O extends Offer> - Parameters:
request
- anMarketingMessageRequest
containing the parameters by which the results will be filteredcontextInfo
- the context information around sandboxing and multitenant state- Returns:
- the marketing messages for the given item in priority order
-
findRelevantMessages
protected List<P> findRelevantMessages(MarketingMessageRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Default implementation that is tuned for full message repository caching and assumes a relatively small number of active messages (e.g. 100s per tenant/app context). This method is intentionally designed to allow for a custom hook for tuning more extreme cases. The default implementation benefits from archiving (or setting an ACTIVE_END_DATE) on old messages. The logic of this method is: - Finds all messages whoseMarketingMessage.activeEndDate
is null or after NOW. - Find all related, active offers by ID usingMarketingMessage.getOfferId()
- Filter the returned list to only include active messages using offer and message dates- Parameters:
request
- theMarketingMessageRequest
contextInfo
- context information around sandbox and multitenant state- Returns:
-
buildOfferMap
protected Map<String,O> buildOfferMap(List<P> marketingMessages, MarketingMessageRequest marketingMessageRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a Map of offerId to offer for the passed in marketing messages based on theMarketingMessage.getOfferId()
The list will filter out offers that are not valid based on active dates and customer context.- Parameters:
marketingMessages
- - the list of marketing messages that are valid for the requestmarketingMessageRequest
- - the incoming request to the APIcontextInfo
- context information around sandbox and multitenant state- Returns:
- a Map of offerId to offer for the passed in marketing messages
- See Also:
-
buildEnhancedOrderForMarketingMessageRequest
protected EnhancedOrder buildEnhancedOrderForMarketingMessageRequest(MarketingMessageRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Build a simple order to use for offer filtering based on customer if needed- Parameters:
request
- theMarketingMessageRequest
contextInfo
- context information around sandbox and multitenant state- Returns:
- a skeleton EnhancedOrder based off of the
MarketingMessageRequest
-
filterMessages
-
filterMessagesByAppliedOffers
protected Stream<P> filterMessagesByAppliedOffers(Stream<P> messageSet, MarketingMessageRequest request) -
filterMessagesByCartSubtotal
protected Stream<P> filterMessagesByCartSubtotal(Stream<P> messageSet, MarketingMessageRequest request) -
filterMessagesWithoutActiveOffer
-
addMessageToResponse
protected void addMessageToResponse(MarketingMessageRequest request, MarketingMessageResponse<P> response, P message, List<String> productIds) -
updateProductMessageMap
-
buildMarketingMessageResponse
protected MarketingMessageResponse<P> buildMarketingMessageResponse(MarketingMessageRequest request, List<P> messages, Map<String, O> offerMap) Removes messages that are targeted to specific qualifiers or targets with no matching items before populating the response structures. -
checkForMatchingProducts
protected List<String> checkForMatchingProducts(O offer, List<EnhancedLineItem> lineItems, boolean includeTargets, boolean includeQualifiers) -
isItemOffer
Checks if theOffer
targets an order or fulfillment group item.- Parameters:
offer
- theOffer
to check- Returns:
- true if the offer targets an order or fulfillment group item
-
isItemQualifier
Checks if any of the rules inOffer.getItemQualifierCriteria()
matches the line item on this request in order to determine if the line item can be used to qualify for the offer.- Parameters:
offer
- theOffer
to checkitem
- theEnhancedLineItem
to check- Returns:
- true if a match is found in the qualifier criteria
-
isItemTarget
If this is an item offer, checks if any of the rules inOffer.getTargetItemCriteria()
matches the line item on this request in order to determine if the line item can be used as the target for the offer. If the offer discount cannot apply to the sales price and the line item is on sale, then the item will not qualify as the offer target.- Parameters:
offer
- theOffer
to checkitem
- theEnhancedLineItem
to check- Returns:
- true if the line item can qualify as the target of the offer
-
modifyItemCriteria
In certain cases (i.e. Fulfillment Group Item Offers) we need modify the rules so that they can be evaluated.- Parameters:
offer
- theOffer
to checkitemCriteria
- theItemCriteria
to modify- Returns:
- the potentially modified item criteria
-