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 Details

  • Constructor Details

  • 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 the MarketingMessages for the provided MarketingMessageRequest. This will find all the active Offers first, then split them into two, filtered groups: Those that treat the MarketingMessageRequest.getLineItems() as a target and those that treat it as a qualifier. Then, it will fetch all messages for those offers, grouping by MarketingMessageLocationType, filter by active date range and sort them by priority.
      Specified by:
      findAllMarketingMessagesForRequest in interface MarketingMessageResolver<P extends MarketingMessage,O extends Offer>
      Parameters:
      request - an MarketingMessageRequest containing the parameters by which the results will be filtered
      contextInfo - 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 whose MarketingMessage.activeEndDate is null or after NOW. - Find all related, active offers by ID using MarketingMessage.getOfferId() - Filter the returned list to only include active messages using offer and message dates
      Parameters:
      request - the MarketingMessageRequest
      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 the MarketingMessage.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 request
      marketingMessageRequest - - the incoming request to the API
      contextInfo - 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 - the MarketingMessageRequest
      contextInfo - context information around sandbox and multitenant state
      Returns:
      a skeleton EnhancedOrder based off of the MarketingMessageRequest
    • filterMessages

      protected List<P> filterMessages(List<P> messageList, MarketingMessageRequest request, Map<String,O> offerMap)
    • filterMessagesByAppliedOffers

      protected Stream<P> filterMessagesByAppliedOffers(Stream<P> messageSet, MarketingMessageRequest request)
    • filterMessagesByCartSubtotal

      protected Stream<P> filterMessagesByCartSubtotal(Stream<P> messageSet, MarketingMessageRequest request)
    • filterMessagesWithoutActiveOffer

      protected Stream<P> filterMessagesWithoutActiveOffer(Stream<P> messageSet, MarketingMessageRequest request, Map<String,O> offerMap)
    • addMessageToResponse

      protected void addMessageToResponse(MarketingMessageRequest request, MarketingMessageResponse<P> response, P message, List<String> productIds)
    • updateProductMessageMap

      protected void updateProductMessageMap(Map<String,List<P>> itemMessageMap, P message, List<String> productIds)
    • 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

      protected boolean isItemOffer(Offer offer)
      Checks if the Offer targets an order or fulfillment group item.
      Parameters:
      offer - the Offer to check
      Returns:
      true if the offer targets an order or fulfillment group item
    • isItemQualifier

      protected boolean isItemQualifier(Offer offer, EnhancedLineItem item)
      Checks if any of the rules in Offer.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 - the Offer to check
      item - the EnhancedLineItem to check
      Returns:
      true if a match is found in the qualifier criteria
    • isItemTarget

      protected boolean isItemTarget(Offer offer, EnhancedLineItem item)
      If this is an item offer, checks if any of the rules in Offer.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 - the Offer to check
      item - the EnhancedLineItem to check
      Returns:
      true if the line item can qualify as the target of the offer
    • modifyItemCriteria

      protected ItemCriteria modifyItemCriteria(Offer offer, @Nullable ItemCriteria itemCriteria)
      In certain cases (i.e. Fulfillment Group Item Offers) we need modify the rules so that they can be evaluated.
      Parameters:
      offer - the Offer to check
      itemCriteria - the ItemCriteria to modify
      Returns:
      the potentially modified item criteria