Class DefaultProrationService
- java.lang.Object
-
- com.broadleafcommerce.promotion.offer.service.engine.proration.DefaultProrationService
-
- All Implemented Interfaces:
ProrationService
public class DefaultProrationService extends Object implements ProrationService
- Author:
- Nathan Moore (nathanmoore).
-
-
Field Summary
Fields Modifier and Type Field Description protected com.broadleafcommerce.common.extension.TypeFactoryofferFactory
-
Constructor Summary
Constructors Constructor Description DefaultProrationService(com.broadleafcommerce.common.extension.TypeFactory offerFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProratedItemOfferAdjustmentsToParentOfferDetails(Collection<? extends EnhancedProratedItemOfferAdjustment> proratedAdjustments)Adds theProratedItemOfferAdjustmentsto their parentLineItemOfferDetailsprotected javax.money.MonetaryAmountcalculateProratedAmount(ItemOfferAdjustment adjustment, int itemQty)Set<EnhancedProratedItemOfferAdjustment>calculateProratedItemAdjustments(EnhancedOrder order)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 MoneyRoundingHelpergetMoneyRoundingHelper()protected booleanisMatchingQualifier(Offer offer, OfferQualifier qualifier)protected booleanisProrationRequiredForAdjustment(ItemOfferAdjustment adjustment)protected voidpopulateProratedFulfillmentGroupAdjustments(EnhancedFulfillmentGroup group)Populates the prorated fulfillment group adjustments for the givenEnhancedFulfillmentGroup.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().protected voidpopulateProratedFulfillmentGroupAdjustments(FulfillmentGroupAdjustment fgAdjustment, EnhancedFulfillmentGroup group)Populates the prorated fulfillment group adjustments from the givenFulfillmentGroupAdjustmentacross the givenfulfillment itemsand the givenEnhancedFulfillmentGroup.voidpopulateProratedOrderAdjustments(EnhancedOrder order)Populates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.ORDERand add them onto the individual discountableorder line items.protected voidpopulateProratedOrderAdjustments(OrderOfferAdjustment orderAdjustment, List<? extends EnhancedLineItem> lineItems)Populates the prorated order adjustments from the givenOrderOfferAdjustmentacross the givenline items.protected Set<EnhancedProratedOfferAdjustment>prorateAdjustmentAmongItems(Offer offer, javax.money.MonetaryAmount adjustmentAmount, javax.money.MonetaryAmount totalOfAllDiscountableItems, List<? extends EnhancedLineItem> lineItems)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 javax.money.MonetaryAmountzeroIfNull(javax.money.MonetaryAmount amount, javax.money.CurrencyUnit currency)Defaults theamountto zero if null.
-
-
-
Method Detail
-
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
@NonNull public void populateProratedOrderAdjustments(@NonNull EnhancedOrder order)Description copied from interface:ProrationServicePopulates all of theEnhancedProratedOfferAdjustmentsfor anyOfferthat has aDiscount.getTargetType()ofDiscountTargetType.ORDERand add them onto the individual discountableorder line items.- Specified by:
populateProratedOrderAdjustmentsin interfaceProrationService- Parameters:
order- theEnhancedOrderto populate the order offer adjustment prorations
-
populateProratedFulfillmentGroupAdjustments
@NonNull public void populateProratedFulfillmentGroupAdjustments(@NonNull EnhancedOrder order)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
protected Set<ItemOfferAdjustment> getAllAdjustments(EnhancedOrder order)
-
isProrationRequiredForAdjustment
protected boolean isProrationRequiredForAdjustment(ItemOfferAdjustment adjustment)
-
shouldProrateAdjustment
protected boolean shouldProrateAdjustment(OrderOfferAdjustment adjustment)
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
protected boolean shouldProrateAdjustment(FulfillmentGroupAdjustment adjustment)
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)
-
populateProratedOrderAdjustments
protected void populateProratedOrderAdjustments(OrderOfferAdjustment orderAdjustment, List<? extends EnhancedLineItem> lineItems)
Populates the prorated order adjustments from the givenOrderOfferAdjustmentacross the givenline items.- Parameters:
orderAdjustment- theOrderOfferAdjustmentto proratelineItems- theline itemsto prorate the order-level adjustment across
-
populateProratedFulfillmentGroupAdjustments
protected void populateProratedFulfillmentGroupAdjustments(EnhancedFulfillmentGroup group)
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, javax.money.MonetaryAmount totalOfAllDiscountableItems, List<? extends EnhancedLineItem> lineItems)
Prorates the given adjustment across the givenEnhancedLineItems.- Parameters:
offer- theOfferwhere the adjustment came fromadjustmentAmount- the adjustment amount to proratetotalOfAllDiscountableItems- the total of the discountable itemslineItems- theEnhancedLineItemsto prorate across- Returns:
- the populated adjustment prorations added to the given
EnhancedLineItems. The list can be used later on for rounding
-
isMatchingQualifier
protected boolean isMatchingQualifier(Offer offer, OfferQualifier qualifier)
-
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
protected String getLineItemType(EnhancedLineItem lineItem)
-
getCustomLineItemType
protected String getCustomLineItemType(EnhancedLineItem lineItem)
-
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
protected MoneyRoundingHelper getMoneyRoundingHelper()
-
setMoneyRoundingHelper
@Autowired public void setMoneyRoundingHelper(MoneyRoundingHelper moneyRoundingHelper)
-
-