Class DefaultProrationService
java.lang.Object
com.broadleafcommerce.promotion.offer.service.engine.proration.DefaultProrationService
- All Implemented Interfaces:
ProrationService
- Author:
- Nathan Moore (nathanmoore).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.broadleafcommerce.common.extension.TypeFactory -
Constructor Summary
ConstructorsConstructorDescriptionDefaultProrationService(com.broadleafcommerce.common.extension.TypeFactory offerFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddProratedItemOfferAdjustmentsToParentOfferDetails(Collection<? extends EnhancedProratedItemOfferAdjustment> proratedAdjustments) Adds theProratedItemOfferAdjustmentsto their parentLineItemOfferDetailsbuildProratedOrderAdjustments(OrderOfferAdjustment offerAdjustment, List<? extends EnhancedLineItem> lineItems, DiscountableItemInfo discountableItemInfo) Builds a list ofEnhancedProratedOfferAdjustmentsthat prorates the adjustment value of the passed inOrderOfferAdjustmentto the passed in list of relevantEnhancedLineItemsprotected javax.money.MonetaryAmountcalculateProratedAmount(ItemOfferAdjustment adjustment, int itemQty) For anyOfferthat has aDiscount.prorationTypeofProrationType.TARGET_AND_QUALIFIER, this will populate all of theProratedItemOfferAdjustmentson theLineItemOfferDetailsmostly for the sake of reporting instruments.protected EnhancedProratedItemOfferAdjustmentcalculateProrationItemAdjustment(ItemOfferAdjustment adjustment) protected com.broadleafcommerce.promotion.offer.client.web.context.info.LineItemRefcreateLineItemRef(EnhancedLineItem lineItem) protected com.broadleafcommerce.promotion.offer.client.web.context.info.OfferRefcreateOfferRef(Offer offer) protected EnhancedProratedItemOfferAdjustmentcreateProratedAdjustment(Offer offer, EnhancedLineItem lineItem, LineItemOfferDetail parentDetail, javax.money.MonetaryAmount proratedAmt, int quantity) protected Set<ItemOfferAdjustment>getAllAdjustments(EnhancedOrder order) protected StringgetCustomLineItemType(EnhancedLineItem lineItem) protected javax.money.MonetaryAmountgetDiscountableItemsTotal(javax.money.MonetaryAmount startingAmount, List<? extends EnhancedLineItem> lineItems) Gets the discountable total for the givenEnhancedLineItems.protected StringgetLineItemType(EnhancedLineItem lineItem) protected MoneyRoundingHelperprotected booleanisMatchingQualifier(Offer offer, OfferQualifier qualifier) protected booleanisProrationRequiredForAdjustment(ItemOfferAdjustment adjustment) protected voidpopulateItemQuantitesProrationDetails(@NonNull Set<EnhancedProratedOfferAdjustment> proratedOfferAdjustments) PopulatesItemProrationDetailsto represent how anEnhancedProratedOfferAdjustmentcan be prorated down to an item quantity level.protected voidPopulates the prorated fulfillment group adjustments for the givenEnhancedFulfillmentGroup.voidPopulates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.FULFILLMENT_GROUPand add them onto the individual discountablefulfillment items, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments().protected voidpopulateProratedFulfillmentGroupAdjustments(FulfillmentGroupAdjustment fgAdjustment, EnhancedFulfillmentGroup group) Populates the prorated fulfillment group adjustments from the givenFulfillmentGroupAdjustmentacross the givenfulfillment itemsand the givenEnhancedFulfillmentGroup.voidpopulateProratedOrderAdjustments(EnhancedOrder order, OfferProcessingContext context) Populates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.ORDERand add them onto the individual discountablefulfillment items, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments().protected Set<EnhancedProratedOfferAdjustment>prorateAdjustmentAmongItems(Offer offer, javax.money.MonetaryAmount adjustmentAmount, DiscountableItemInfo discountableItemInfo, List<? extends EnhancedLineItem> lineItems, boolean updateItem) Prorates the given adjustment across the givenEnhancedLineItems.voidsetMoneyRoundingHelper(MoneyRoundingHelper moneyRoundingHelper) protected booleanshouldProrateAdjustment(FulfillmentGroupAdjustment adjustment) Determines whether the givenFulfillmentGroupAdjustmentshould be prorated across the fulfillment items.protected booleanshouldProrateAdjustment(OrderOfferAdjustment adjustment) Determines whether the givenOrderOfferAdjustmentshould be prorated across the order line items.protected final javax.money.MonetaryAmountzeroIfNull(javax.money.MonetaryAmount amount, javax.money.CurrencyUnit currency) Defaults theamountto zero if null.
-
Field Details
-
offerFactory
protected final com.broadleafcommerce.common.extension.TypeFactory offerFactory
-
-
Constructor Details
-
DefaultProrationService
public DefaultProrationService(com.broadleafcommerce.common.extension.TypeFactory offerFactory)
-
-
Method Details
-
addProratedItemOfferAdjustmentsToParentOfferDetails
public void addProratedItemOfferAdjustmentsToParentOfferDetails(@NonNull Collection<? extends EnhancedProratedItemOfferAdjustment> proratedAdjustments) Description copied from interface:ProrationServiceAdds theProratedItemOfferAdjustmentsto their parentLineItemOfferDetails- Specified by:
addProratedItemOfferAdjustmentsToParentOfferDetailsin interfaceProrationService- Parameters:
proratedAdjustments-ProratedItemOfferAdjustmentsto be added
-
calculateProratedItemAdjustments
@NonNull public Set<EnhancedProratedItemOfferAdjustment> calculateProratedItemAdjustments(@NonNull EnhancedOrder order) Description copied from interface:ProrationServiceFor anyOfferthat has aDiscount.prorationTypeofProrationType.TARGET_AND_QUALIFIER, this will populate all of theProratedItemOfferAdjustmentson theLineItemOfferDetailsmostly for the sake of reporting instruments.- Specified by:
calculateProratedItemAdjustmentsin interfaceProrationService- Parameters:
order- theEnhancedOrderwhose items may needProratedItemOfferAdjustments- Returns:
- all of the
ProratedItemOfferAdjustmentsfor thisOrder'sorder and fulfillmentLineItems.
-
populateProratedOrderAdjustments
public void populateProratedOrderAdjustments(@NonNull EnhancedOrder order, OfferProcessingContext context) Description copied from interface:ProrationServicePopulates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.ORDERand add them onto the individual discountablefulfillment items, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments().- Specified by:
populateProratedOrderAdjustmentsin interfaceProrationService- Parameters:
order- theEnhancedOrderto populate the fulfillment group offer adjustment prorations
-
populateProratedFulfillmentGroupAdjustments
Description copied from interface:ProrationServicePopulates 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 interfaceProrationService- Parameters:
order- theEnhancedOrderto populate the fulfillment group offer adjustment prorations
-
getAllAdjustments
-
isProrationRequiredForAdjustment
-
shouldProrateAdjustment
Determines whether the givenOrderOfferAdjustmentshould be prorated across the order line items.Returns
trueby default, any custom logic should be added here.- Parameters:
adjustment- theOrderOfferAdjustmentto check against- Returns:
- true if the given
OrderOfferAdjustmentshould be prorated across the order line items
-
shouldProrateAdjustment
Determines whether the givenFulfillmentGroupAdjustmentshould be prorated across the fulfillment items.Returns
trueby default, any custom logic should be added here.- Parameters:
adjustment- theFulfillmentGroupAdjustmentto check against- Returns:
- true if the given
FulfillmentGroupAdjustmentshould be prorated across the fulfillment items
-
calculateProrationItemAdjustment
protected EnhancedProratedItemOfferAdjustment calculateProrationItemAdjustment(ItemOfferAdjustment adjustment) -
buildProratedOrderAdjustments
public Set<EnhancedProratedOfferAdjustment> buildProratedOrderAdjustments(@NonNull OrderOfferAdjustment offerAdjustment, @NonNull List<? extends EnhancedLineItem> lineItems, DiscountableItemInfo discountableItemInfo) Description copied from interface:ProrationServiceBuilds a list ofEnhancedProratedOfferAdjustmentsthat prorates the adjustment value of the passed inOrderOfferAdjustmentto the passed in list of relevantEnhancedLineItems- Specified by:
buildProratedOrderAdjustmentsin interfaceProrationService- Parameters:
offerAdjustment- theOrderOfferAdjustmentto prorate.lineItems- the list of relevantEnhancedLineItemsto- Returns:
- the list of
EnhancedProratedOfferAdjustments
-
populateProratedFulfillmentGroupAdjustments
Populates the prorated fulfillment group adjustments for the givenEnhancedFulfillmentGroup.- Parameters:
group- theEnhancedFulfillmentGroupto populate the prorations for
-
populateProratedFulfillmentGroupAdjustments
protected void populateProratedFulfillmentGroupAdjustments(FulfillmentGroupAdjustment fgAdjustment, EnhancedFulfillmentGroup group) Populates the prorated fulfillment group adjustments from the givenFulfillmentGroupAdjustmentacross the givenfulfillment itemsand the givenEnhancedFulfillmentGroup.- Parameters:
fgAdjustment- theFulfillmentGroupAdjustmentto prorate across theEnhancedFulfillmentGroupandfulfillment itemsgroup- theEnhancedFulfillmentGroupto populate the prorations for
-
getDiscountableItemsTotal
protected javax.money.MonetaryAmount getDiscountableItemsTotal(javax.money.MonetaryAmount startingAmount, List<? extends EnhancedLineItem> lineItems) Gets the discountable total for the givenEnhancedLineItems.- Parameters:
startingAmount- the amount to start withlineItems- theEnhancedLineItemsto calculate the discountable total for- Returns:
- the discountable total for the given
EnhancedLineItems
-
prorateAdjustmentAmongItems
protected Set<EnhancedProratedOfferAdjustment> prorateAdjustmentAmongItems(Offer offer, javax.money.MonetaryAmount adjustmentAmount, DiscountableItemInfo discountableItemInfo, List<? extends EnhancedLineItem> lineItems, boolean updateItem) Prorates the given adjustment across the givenEnhancedLineItems.- Parameters:
offer- theOfferwhere the adjustment came fromadjustmentAmount- the adjustment amount to proratediscountableItemInfo- structure with item discount informationlineItems- theEnhancedLineItemsto prorate across- Returns:
- the populated adjustment prorations added to the given
EnhancedLineItems. The list can be used later on for rounding
-
populateItemQuantitesProrationDetails
protected void populateItemQuantitesProrationDetails(@NonNull @NonNull Set<EnhancedProratedOfferAdjustment> proratedOfferAdjustments) PopulatesItemProrationDetailsto represent how anEnhancedProratedOfferAdjustmentcan be prorated down to an item quantity level.For example, if a
EnhancedProratedOfferAdjustment.getAmount()is $5 and the item's quantity is 3, this method will produce twoItemProrationDetailsrepresenting how the discount would be prorated based on the item's quantity, one with quantity of 2 and amount of $1.67, and one with quantity of 1 and amount of $1.66, totaling to $5- Parameters:
proratedOfferAdjustments- theEnhancedProratedOfferAdjustmentsto prorate
-
isMatchingQualifier
-
calculateProratedAmount
protected javax.money.MonetaryAmount calculateProratedAmount(ItemOfferAdjustment adjustment, int itemQty) -
createProratedAdjustment
protected EnhancedProratedItemOfferAdjustment createProratedAdjustment(Offer offer, EnhancedLineItem lineItem, LineItemOfferDetail parentDetail, javax.money.MonetaryAmount proratedAmt, int quantity) -
createLineItemRef
protected com.broadleafcommerce.promotion.offer.client.web.context.info.LineItemRef createLineItemRef(EnhancedLineItem lineItem) -
getLineItemType
-
getCustomLineItemType
-
createOfferRef
protected com.broadleafcommerce.promotion.offer.client.web.context.info.OfferRef createOfferRef(Offer offer) -
zeroIfNull
protected final javax.money.MonetaryAmount zeroIfNull(@Nullable javax.money.MonetaryAmount amount, @Nullable javax.money.CurrencyUnit currency) Defaults theamountto zero if null.- Parameters:
amount- TheMonetaryAmountto default to zerocurrency- Theamount'sCurrencyUnit- Returns:
- The
amountor zero if null.
-
getMoneyRoundingHelper
-
setMoneyRoundingHelper
-