Class DefaultProrationService
java.lang.Object
com.broadleafcommerce.promotion.offer.service.engine.proration.DefaultProrationService
- All Implemented Interfaces:
ProrationService
- Author:
- Nathan Moore (nathanmoore).
-
Field Summary
Modifier and TypeFieldDescriptionprotected final com.broadleafcommerce.common.extension.TypeFactory
-
Constructor Summary
ConstructorDescriptionDefaultProrationService
(com.broadleafcommerce.common.extension.TypeFactory offerFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addProratedItemOfferAdjustmentsToParentOfferDetails
(Collection<? extends EnhancedProratedItemOfferAdjustment> proratedAdjustments) Adds theProratedItemOfferAdjustments
to their parentLineItemOfferDetails
buildProratedOrderAdjustments
(OrderOfferAdjustment offerAdjustment, List<? extends EnhancedLineItem> lineItems, DiscountableItemInfo discountableItemInfo) Builds a list ofEnhancedProratedOfferAdjustments
that prorates the adjustment value of the passed inOrderOfferAdjustment
to the passed in list of relevantEnhancedLineItem
sprotected javax.money.MonetaryAmount
calculateProratedAmount
(ItemOfferAdjustment adjustment, int itemQty) For anyOffer
that has aDiscount.prorationType
ofProrationType.TARGET_AND_QUALIFIER
, this will populate all of theProratedItemOfferAdjustments
on theLineItemOfferDetails
mostly for the sake of reporting instruments.protected EnhancedProratedItemOfferAdjustment
calculateProrationItemAdjustment
(ItemOfferAdjustment adjustment) protected com.broadleafcommerce.promotion.offer.client.web.context.info.LineItemRef
createLineItemRef
(EnhancedLineItem lineItem) protected com.broadleafcommerce.promotion.offer.client.web.context.info.OfferRef
createOfferRef
(Offer offer) protected EnhancedProratedItemOfferAdjustment
createProratedAdjustment
(Offer offer, EnhancedLineItem lineItem, LineItemOfferDetail parentDetail, javax.money.MonetaryAmount proratedAmt, int quantity) protected Set<ItemOfferAdjustment>
getAllAdjustments
(EnhancedOrder order) protected String
getCustomLineItemType
(EnhancedLineItem lineItem) protected javax.money.MonetaryAmount
getDiscountableItemsTotal
(javax.money.MonetaryAmount startingAmount, List<? extends EnhancedLineItem> lineItems) Gets the discountable total for the givenEnhancedLineItems
.protected String
getLineItemType
(EnhancedLineItem lineItem) protected MoneyRoundingHelper
protected boolean
isMatchingQualifier
(Offer offer, OfferQualifier qualifier) protected boolean
isProrationRequiredForAdjustment
(ItemOfferAdjustment adjustment) protected void
populateItemQuantitesProrationDetails
(@NonNull Set<EnhancedProratedOfferAdjustment> proratedOfferAdjustments) PopulatesItemProrationDetails
to represent how anEnhancedProratedOfferAdjustment
can be prorated down to an item quantity level.protected void
Populates the prorated fulfillment group adjustments for the givenEnhancedFulfillmentGroup
.void
Populates all of theEnhancedProratedOfferAdjustments
for anyOffer
that has aDiscount.getTargetType()
ofDiscountTargetType.FULFILLMENT_GROUP
and add them onto the individual discountablefulfillment items
, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments()
.protected void
populateProratedFulfillmentGroupAdjustments
(FulfillmentGroupAdjustment fgAdjustment, EnhancedFulfillmentGroup group) Populates the prorated fulfillment group adjustments from the givenFulfillmentGroupAdjustment
across the givenfulfillment items
and the givenEnhancedFulfillmentGroup
.void
populateProratedOrderAdjustments
(EnhancedOrder order, OfferProcessingContext context) Populates all of theEnhancedProratedOfferAdjustments
for anyOffer
that has aDiscount.getTargetType()
ofDiscountTargetType.ORDER
and 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
.void
setMoneyRoundingHelper
(MoneyRoundingHelper moneyRoundingHelper) protected boolean
shouldProrateAdjustment
(FulfillmentGroupAdjustment adjustment) Determines whether the givenFulfillmentGroupAdjustment
should be prorated across the fulfillment items.protected boolean
shouldProrateAdjustment
(OrderOfferAdjustment adjustment) Determines whether the givenOrderOfferAdjustment
should be prorated across the order line items.protected final javax.money.MonetaryAmount
zeroIfNull
(javax.money.MonetaryAmount amount, javax.money.CurrencyUnit currency) Defaults theamount
to 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:ProrationService
Adds theProratedItemOfferAdjustments
to their parentLineItemOfferDetails
- Specified by:
addProratedItemOfferAdjustmentsToParentOfferDetails
in interfaceProrationService
- Parameters:
proratedAdjustments
-ProratedItemOfferAdjustments
to be added
-
calculateProratedItemAdjustments
@NonNull public Set<EnhancedProratedItemOfferAdjustment> calculateProratedItemAdjustments(@NonNull EnhancedOrder order) Description copied from interface:ProrationService
For anyOffer
that has aDiscount.prorationType
ofProrationType.TARGET_AND_QUALIFIER
, this will populate all of theProratedItemOfferAdjustments
on theLineItemOfferDetails
mostly for the sake of reporting instruments.- Specified by:
calculateProratedItemAdjustments
in interfaceProrationService
- Parameters:
order
- theEnhancedOrder
whose items may needProratedItemOfferAdjustments
- Returns:
- all of the
ProratedItemOfferAdjustments
for thisOrder's
order and fulfillmentLineItems
.
-
populateProratedOrderAdjustments
public void populateProratedOrderAdjustments(@NonNull EnhancedOrder order, OfferProcessingContext context) Description copied from interface:ProrationService
Populates all of theEnhancedProratedOfferAdjustments
for anyOffer
that has aDiscount.getTargetType()
ofDiscountTargetType.ORDER
and add them onto the individual discountablefulfillment items
, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments()
.- Specified by:
populateProratedOrderAdjustments
in interfaceProrationService
- Parameters:
order
- theEnhancedOrder
to populate the fulfillment group offer adjustment prorations
-
populateProratedFulfillmentGroupAdjustments
Description copied from interface:ProrationService
Populates all of theEnhancedProratedOfferAdjustments
for anyOffer
that has aDiscount.getTargetType()
ofDiscountTargetType.FULFILLMENT_GROUP
and add them onto the individual discountablefulfillment items
, as well as populatingEnhancedFulfillmentGroup.getProratedFulfillmentAdjustments()
.- Specified by:
populateProratedFulfillmentGroupAdjustments
in interfaceProrationService
- Parameters:
order
- theEnhancedOrder
to populate the fulfillment group offer adjustment prorations
-
getAllAdjustments
-
isProrationRequiredForAdjustment
-
shouldProrateAdjustment
Determines whether the givenOrderOfferAdjustment
should be prorated across the order line items.Returns
true
by default, any custom logic should be added here.- Parameters:
adjustment
- theOrderOfferAdjustment
to check against- Returns:
- true if the given
OrderOfferAdjustment
should be prorated across the order line items
-
shouldProrateAdjustment
Determines whether the givenFulfillmentGroupAdjustment
should be prorated across the fulfillment items.Returns
true
by default, any custom logic should be added here.- Parameters:
adjustment
- theFulfillmentGroupAdjustment
to check against- Returns:
- true if the given
FulfillmentGroupAdjustment
should 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:ProrationService
Builds a list ofEnhancedProratedOfferAdjustments
that prorates the adjustment value of the passed inOrderOfferAdjustment
to the passed in list of relevantEnhancedLineItem
s- Specified by:
buildProratedOrderAdjustments
in interfaceProrationService
- Parameters:
offerAdjustment
- theOrderOfferAdjustment
to prorate.lineItems
- the list of relevantEnhancedLineItems
to- Returns:
- the list of
EnhancedProratedOfferAdjustments
-
populateProratedFulfillmentGroupAdjustments
Populates the prorated fulfillment group adjustments for the givenEnhancedFulfillmentGroup
.- Parameters:
group
- theEnhancedFulfillmentGroup
to populate the prorations for
-
populateProratedFulfillmentGroupAdjustments
protected void populateProratedFulfillmentGroupAdjustments(FulfillmentGroupAdjustment fgAdjustment, EnhancedFulfillmentGroup group) Populates the prorated fulfillment group adjustments from the givenFulfillmentGroupAdjustment
across the givenfulfillment items
and the givenEnhancedFulfillmentGroup
.- Parameters:
fgAdjustment
- theFulfillmentGroupAdjustment
to prorate across theEnhancedFulfillmentGroup
andfulfillment items
group
- theEnhancedFulfillmentGroup
to 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
- theEnhancedLineItems
to 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
- theOffer
where the adjustment came fromadjustmentAmount
- the adjustment amount to proratediscountableItemInfo
- structure with item discount informationlineItems
- theEnhancedLineItems
to 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) PopulatesItemProrationDetails
to represent how anEnhancedProratedOfferAdjustment
can 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 twoItemProrationDetails
representing 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
- theEnhancedProratedOfferAdjustments
to 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 theamount
to zero if null.- Parameters:
amount
- TheMonetaryAmount
to default to zerocurrency
- Theamount's
CurrencyUnit
- Returns:
- The
amount
or zero if null.
-
getMoneyRoundingHelper
-
setMoneyRoundingHelper
-