Class DefaultOfferEngineService

java.lang.Object
com.broadleafcommerce.promotion.offer.service.engine.DefaultOfferEngineService
All Implemented Interfaces:
OfferEngineService

public class DefaultOfferEngineService extends Object implements OfferEngineService
Author:
Chad Harchar (charchar)
  • Constructor Details

  • Method Details

    • executeOnOrderAndContext

      public com.broadleafcommerce.promotion.offer.client.web.context.discounts.OrderResponse executeOnOrderAndContext(@NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: OfferEngineService
      For the provided order and context, determines the candidate offers and applies them to the order in the permutation that gives the best discount.
      Specified by:
      executeOnOrderAndContext in interface OfferEngineService
      Parameters:
      order - context information around the offer
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      A response DTO that details the adjustments and their discounts applied to the order
    • processOfferPermutations

      public void processOfferPermutations(OfferProcessingContext context)
    • modifyEvaluateOffersResponse

      public com.broadleafcommerce.promotion.offer.client.web.context.discounts.OrderResponse modifyEvaluateOffersResponse(@NonNull com.broadleafcommerce.promotion.offer.client.web.context.discounts.OrderResponse response, @NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: OfferEngineService
      Hook point to add custom logic for the evaluate offer response.
      Specified by:
      modifyEvaluateOffersResponse in interface OfferEngineService
      Parameters:
      response - a response DTO that details the adjustments and their discounts applied to the order
      order - context information around the offer
      contextInfo - context information around sandbox and multitenant state
      Returns:
      the modified response DTO that details the adjustments and their discounts applied to the order
    • initializeOrder

      protected boolean initializeOrder(EnhancedOrder order)
    • prepareOfferProcessingContext

      public OfferProcessingContext prepareOfferProcessingContext(EnhancedOrder order, CandidateOffers candidateOffers)
      This method takes in a set of candidate offers. The offers are updated with relevant combinability data which are then used to construct an OfferProcessingContext.
      Parameters:
      order -
      candidateOffers -
      Returns:
    • initializeCurrency

      protected void initializeCurrency(EnhancedOrder order)
      Orders should already have a currency but if one is not present on the order, this method will populate it with the system default.
      Parameters:
      order -
    • buildResponse

      protected com.broadleafcommerce.promotion.offer.client.web.context.discounts.OrderResponse buildResponse(@NonNull EnhancedOrder order)
    • getCandidateOffers

      @NonNull public CandidateOffers getCandidateOffers(@NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: OfferEngineService
      Determines all of the candidate offers that can apply to the provided order for the given context.
      Specified by:
      getCandidateOffers in interface OfferEngineService
      Parameters:
      order - context information around the offer
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      The list of offers that can apply to the provided order and context.
    • applyAdjustments

      public void applyAdjustments(@NonNull EnhancedOrder order, @NonNull OfferProcessingContext processingContext)
      Description copied from interface: OfferEngineService
      Applies the offers to the order in a way that gives the best discount for the customer based on possible permutations.
      Specified by:
      applyAdjustments in interface OfferEngineService
      Parameters:
      order - the order to be considered for Offer discounts.
      processingContext - all permutations of orders that can be considered for the order
    • populateProratedItemAdjustments

      public void populateProratedItemAdjustments(@NonNull EnhancedOrder order, OfferProcessingContext context)
      Description copied from interface: OfferEngineService
      For any Offer that has a Discount.prorationType of ProrationType.TARGET_AND_QUALIFIER, this will populate all of the ProratedItemOfferAdjustments on the LineItemOfferDetails mostly for the sake of reporting instruments.
      Specified by:
      populateProratedItemAdjustments in interface OfferEngineService
      Parameters:
      order - the EnhancedOrder whose LineItems might have ProratedItemOfferAdjustments
    • populateProratedOrderAdjustments

      public void populateProratedOrderAdjustments(@NonNull EnhancedOrder order, OfferProcessingContext context)
      Description copied from interface: OfferEngineService
      Populates all of the EnhancedProratedOfferAdjustments for any Offer that has a Discount.getTargetType() of DiscountTargetType.ORDER and add them onto the individual discountable order line items.
      Specified by:
      populateProratedOrderAdjustments in interface OfferEngineService
      Parameters:
      order - the EnhancedOrder to populate the order offer adjustment prorations
    • populateProratedFulfillmentGroupAdjustments

      public void populateProratedFulfillmentGroupAdjustments(@NonNull EnhancedOrder order)
      Description copied from interface: OfferEngineService
      Populates all of the EnhancedProratedOfferAdjustments for any Offer that has a Discount.getTargetType() of DiscountTargetType.FULFILLMENT_GROUP and add them onto the individual discountable fulfillment items, as well as populating EnhancedFulfillmentGroup.getProratedFulfillmentAdjustments().
      Specified by:
      populateProratedFulfillmentGroupAdjustments in interface OfferEngineService
      Parameters:
      order - the EnhancedOrder to populate the fulfillment group offer adjustment prorations
    • assertOrderNotNull

      protected void assertOrderNotNull(EnhancedOrder order)
    • logIfDebugOn

      protected void logIfDebugOn(String message, Object... formatArgs)
      Checks if Log.isDebugEnabled() debug is enabled}, then wraps the message in String.format(String, Object...) with the given formatArgs and logs it.
    • provideExternalOffers

      protected EnhancedOrder provideExternalOffers(@NonNull EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      A hook point for calling the configured external offer provider that can populate the order using custom offer logic.
      Parameters:
      order - the order to populate with external offer data
      contextInfo - context information around the sandbox and multitenant state
      Returns:
      the order populated with external offer data
    • getValidator

      @NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
    • setExternalOfferProvider

      @Autowired(required=false) public void setExternalOfferProvider(ExternalOfferProvider externalOfferProvider)
    • getExternalOfferProvider

      @Nullable protected ExternalOfferProvider getExternalOfferProvider()
    • getProperties

      @NonNull protected OfferServiceProperties getProperties()
    • setProperties

      @Autowired public void setProperties(OfferServiceProperties properties)