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 Summary
Constructors Constructor Description DefaultOfferEngineService(OfferCandidateService offerCandidateService, OfferApplicationService offerApplicationService, OfferEngineResponseBuilder offerEngineResponseBuilder, ProrationService prorationService, com.broadleafcommerce.common.extension.TypeFactory offerFactory, OfferProcesingUtility offerProcessingUtility, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyAdjustments(EnhancedOrder order, OfferProcessingContext processingContext)Applies the offers to the order in a way that gives the best discount for the customer based on possible permutations.protected voidassertOrderNotNull(EnhancedOrder order)protected com.broadleafcommerce.promotion.offer.client.web.context.discounts.OrderResponsebuildResponse(EnhancedOrder order)com.broadleafcommerce.promotion.offer.client.web.context.discounts.OrderResponseexecuteOnOrderAndContext(EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)For the provided order and context, determines the candidate offers and applies them to the order in the permutation that gives the best discount.CandidateOffersgetCandidateOffers(EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Determines all of the candidate offers that can apply to the provided order for the given context.protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManagergetValidator()protected voidinitializeCurrency(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.protected booleaninitializeOrder(EnhancedOrder order)protected voidlogIfDebugOn(String message, Object... formatArgs)Checks ifLog.isDebugEnabled()debug is enabled}, then wraps the message inString.format(String, Object...)with the givenformatArgsand logs it.voidpopulateProratedFulfillmentGroupAdjustments(EnhancedOrder order)Populates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.FULFILLMENT_GROUPand add them onto the individual discountablefulfillment items, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments().voidpopulateProratedItemAdjustments(EnhancedOrder order)For anyOfferthat has aDiscount.prorationTypeofProrationType.TARGET_AND_QUALIFIER, this will populate all of theProratedItemOfferAdjustmentson theLineItemOfferDetailsmostly for the sake of reporting instruments.voidpopulateProratedOrderAdjustments(EnhancedOrder order)Populates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.ORDERand add them onto the individual discountableorder line items.OfferProcessingContextprepareOfferProcessingContext(EnhancedOrder order, CandidateOffers candidateOffers)This method takes in a set of candidate offers.voidprocessOfferPermutations(OfferProcessingContext context)
-
-
-
Constructor Detail
-
DefaultOfferEngineService
public DefaultOfferEngineService(OfferCandidateService offerCandidateService, OfferApplicationService offerApplicationService, OfferEngineResponseBuilder offerEngineResponseBuilder, ProrationService prorationService, com.broadleafcommerce.common.extension.TypeFactory offerFactory, OfferProcesingUtility offerProcessingUtility, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager validator)
-
-
Method Detail
-
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:OfferEngineServiceFor 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:
executeOnOrderAndContextin interfaceOfferEngineService- Parameters:
order- context information around the offercontextInfo- 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)
-
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:OfferEngineServiceDetermines all of the candidate offers that can apply to the provided order for the given context.- Specified by:
getCandidateOffersin interfaceOfferEngineService- Parameters:
order- context information around the offercontextInfo- 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:OfferEngineServiceApplies the offers to the order in a way that gives the best discount for the customer based on possible permutations.- Specified by:
applyAdjustmentsin interfaceOfferEngineService- Parameters:
order- the order to be considered forOfferdiscounts.processingContext- all permutations of orders that can be considered for the order
-
populateProratedItemAdjustments
public void populateProratedItemAdjustments(@NonNull EnhancedOrder order)Description copied from interface:OfferEngineServiceFor anyOfferthat has aDiscount.prorationTypeofProrationType.TARGET_AND_QUALIFIER, this will populate all of theProratedItemOfferAdjustmentson theLineItemOfferDetailsmostly for the sake of reporting instruments.- Specified by:
populateProratedItemAdjustmentsin interfaceOfferEngineService- Parameters:
order- theEnhancedOrderwhoseLineItemsmight haveProratedItemOfferAdjustments
-
populateProratedOrderAdjustments
public void populateProratedOrderAdjustments(@NonNull EnhancedOrder order)Description copied from interface:OfferEngineServicePopulates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.ORDERand add them onto the individual discountableorder line items.- Specified by:
populateProratedOrderAdjustmentsin interfaceOfferEngineService- Parameters:
order- theEnhancedOrderto populate the order offer adjustment prorations
-
populateProratedFulfillmentGroupAdjustments
public void populateProratedFulfillmentGroupAdjustments(@NonNull EnhancedOrder order)Description copied from interface:OfferEngineServicePopulates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.FULFILLMENT_GROUPand add them onto the individual discountablefulfillment items, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments().- Specified by:
populateProratedFulfillmentGroupAdjustmentsin interfaceOfferEngineService- Parameters:
order- theEnhancedOrderto populate the fulfillment group offer adjustment prorations
-
assertOrderNotNull
protected void assertOrderNotNull(EnhancedOrder order)
-
logIfDebugOn
protected void logIfDebugOn(String message, Object... formatArgs)
Checks ifLog.isDebugEnabled()debug is enabled}, then wraps the message inString.format(String, Object...)with the givenformatArgsand logs it.
-
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
-
-