Class LineItemOfferDetail
java.lang.Object
com.broadleafcommerce.promotion.offer.web.context.info.LineItemOfferDetail
- All Implemented Interfaces:
Serializable
DTO containing information about the effects of all the
offer's
applicable to an
EnhancedLineItem
either treating it as a Offer.getTargetItemCriteria()
target} or
a Offer.getItemQualifierCriteria()
qualifier}.- Author:
- Nathan Moore (nathanmoore).
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected OfferQualifier
addNewQualifierAndGet
(com.broadleafcommerce.common.extension.TypeFactory offerFactory, CandidateItemOffer itemOffer) protected OfferDiscount
addNewTargetAndGet
(com.broadleafcommerce.common.extension.TypeFactory offerFactory, CandidateItemOffer itemOffer) addOrUpdateMatchingOfferQualifier
(CandidateItemOffer itemOffer, ItemCriteriaRule qualifierCriteria, int qtyToMarkAsQualifier, com.broadleafcommerce.common.extension.TypeFactory offerFactory) Either creates a newOfferQualifier
or updates a preexisting one for the givenCandidateItemOffer
, marking the quantity of to reserve for use as qualifiers for the givenItemCriteriaRule
.void
addOrUpdateMatchingOfferTarget
(CandidateItemOffer itemOffer, ItemCriteriaRule targetCriteria, int qtyToMarkAsTarget, com.broadleafcommerce.common.extension.TypeFactory offerFactory) Either creates a newOfferDiscount
or updates a preexisting one for the givenCandidateItemOffer
, marking the quantity of to reserve for use as targets for the givenItemCriteriaRule
.javax.money.MonetaryAmount
calculateAdjustmentValue
(javax.money.CurrencyUnit currency, boolean useSaleAdjustments) javax.money.MonetaryAmount
calculateItemUnitPriceWithAdjustments
(boolean allowSalePrice) protected javax.money.MonetaryAmount
protected javax.money.MonetaryAmount
javax.money.MonetaryAmount
calculateTotalAdjustmentValue
(javax.money.CurrencyUnit currency, boolean useSaleAdjustments) protected boolean
checkStackable
(Offer offer, Offer otherOffer) void
This method will check to see if the salePriceAdjustments or standardPriceAdjustments are better and remove those that should not apply.protected void
void
Clears target and qualifier quantities that were marked for a promotion that did not have enough qualifiers or targets to get applied.protected void
copyDiscountsAndAdjustmentsToNewDetail
(com.broadleafcommerce.common.extension.TypeFactory offerFactory, int discountQty, LineItemOfferDetail newDetail) protected void
finalizeAdjustments
(boolean useSaleAdjustments) void
Updates the target and qualifier quantities to indicate the number that are being used.javax.money.MonetaryAmount
The total value of alladjustments
times thequantity
of this detail.protected javax.money.MonetaryAmount
getAdjustedTotalUsingSalePrice
(javax.money.MonetaryAmount standardAdjustmentPrice) protected javax.money.MonetaryAmount
getAdjustedTotalUsingStandardPrice
(javax.money.MonetaryAmount standardAdjustmentPrice) double
The ratio of the offer discount to apply to this item.double
javax.money.MonetaryAmount
getFinalAdjustmentValue
(javax.money.CurrencyUnit currency) javax.money.MonetaryAmount
getFinalAdjustmentValueIncludingFutureDiscounts
(javax.money.CurrencyUnit currency) javax.money.MonetaryAmount
Returns the final total for this item taking into account the finalized orderAdjustments.javax.money.MonetaryAmount
getFinalTotalAdjustmentValue
(javax.money.CurrencyUnit currency) javax.money.MonetaryAmount
getFutureCreditValue
(javax.money.CurrencyUnit currency) TheEnhancedLineItem
affected byoffers
.Additional info for all theoffers
treating thelineItem
as a target.Additional information about theoffers
using thelineItem
as item qualifiers.TheProratedItemOfferAdjustments
caused byoffers
withDiscount.getProrationType()
orProrationType.TARGET_AND_QUALIFIER
treating bothlineItem
as a target and the items that qualify it.protected int
getQtyAvailableToBeUsed
(CandidateItemOffer offer, boolean isForQualifierQty) Calculates the number oforder items
not already exclusively used as targets or qualifiers either by this offer or any other and, therefore, are available to be used as qualifiers or targets by the givenOffer
.int
Calculates the number oforder items
available to be used as qualifiers for the providedOffer
.int
Calculates the number oforder items
available to be used as targets for the providedOffer
.int
The quantity of items related to this detail.protected int
getQuantityOfItemsExclusivelyUsedAsQualifiers
(CandidateItemOffer thisOffer, Set<OfferQualifier> offerQualifiers, boolean isForQualifierQty) Calculates the number oforder items
already exclusively used as qualifiers.protected int
getQuantityOfItemsExclusivelyUsedAsTargets
(CandidateItemOffer thisOffer, Set<OfferDiscount> offerDiscounts, boolean isForQualifierQty) Calculates the number oforder items
already exclusively used as targets.int
hashCode()
protected boolean
boolean
Whether theadjustments
are the orderAdjustments to actually use rather than being potential or incomplete.protected Predicate<ItemOfferAdjustment>
protected boolean
protected boolean
isStackable
(Offer offer, Offer otherOffer) boolean
boolean
Whether to useEnhancedLineItem.getSalePrice()
in price adjustment calculations.protected Optional<OfferQualifier>
lookupOfferQualifierByOffer
(CandidateItemOffer itemOffer) protected Optional<OfferDiscount>
lookupOfferTargetByOffer
(CandidateItemOffer itemOffer) void
Removes all orderAdjustments from this detail.protected void
protected void
removeZeroDollarAdjustments
(boolean useSalePrice) void
setAdjustedTotal
(javax.money.MonetaryAmount adjustedTotal) The total value of alladjustments
times thequantity
of this detail.void
setAdjustments
(Set<ItemOfferAdjustment> adjustments) void
setAdjustmentsFinalized
(boolean adjustmentsFinalized) Whether theadjustments
are the orderAdjustments to actually use rather than being potential or incomplete.void
setBundleRatio
(double bundleRatio) The ratio of the offer discount to apply to this item.void
setLineItem
(EnhancedLineItem lineItem) TheEnhancedLineItem
affected byoffers
.void
setOfferDiscounts
(Set<OfferDiscount> offerDiscounts) Additional info for all theoffers
treating thelineItem
as a target.void
setOfferQualifiers
(Set<OfferQualifier> offerQualifiers) Additional information about theoffers
using thelineItem
as item qualifiers.void
setProratedAdjustments
(Set<EnhancedProratedItemOfferAdjustment> proratedAdjustments) TheProratedItemOfferAdjustments
caused byoffers
withDiscount.getProrationType()
orProrationType.TARGET_AND_QUALIFIER
treating bothlineItem
as a target and the items that qualify it.void
setQuantity
(int quantity) The quantity of items related to this detail.void
setUseSaleAdjustments
(boolean useSaleAdjustments) Whether to useEnhancedLineItem.getSalePrice()
in price adjustment calculations.protected LineItemOfferDetail
split
(com.broadleafcommerce.common.extension.TypeFactory offerFactory, int discountQty, String offerId, boolean hasQualifiers) Deprecated.protected LineItemOfferDetail
split
(com.broadleafcommerce.common.extension.TypeFactory offerFactory, OfferDiscount offerDiscount) Splits this item into twoLineItemOfferDetails
and returns the newly createdLineItemOfferDetail
.splitIfNecessary
(com.broadleafcommerce.common.extension.TypeFactory offerFactory) Checks to see that the discount quantities match the target quantities.toString()
-
Constructor Details
-
LineItemOfferDetail
public LineItemOfferDetail()
-
-
Method Details
-
finalizeQuantities
public void finalizeQuantities()Updates the target and qualifier quantities to indicate the number that are being used. -
clearAllNonFinalizedQuantities
public void clearAllNonFinalizedQuantities()Clears target and qualifier quantities that were marked for a promotion that did not have enough qualifiers or targets to get applied. -
addOrUpdateMatchingOfferQualifier
@NonNull public OfferQualifier addOrUpdateMatchingOfferQualifier(@NonNull CandidateItemOffer itemOffer, @NonNull ItemCriteriaRule qualifierCriteria, int qtyToMarkAsQualifier, @NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory) Either creates a newOfferQualifier
or updates a preexisting one for the givenCandidateItemOffer
, marking the quantity of to reserve for use as qualifiers for the givenItemCriteriaRule
.- Parameters:
itemOffer
- theCandidateItemOffer
for which to either create a newOfferQualifier
or update a preexisting one.qualifierCriteria
- theOffer.getItemQualifierCriteria()
matched by thelineItem
qtyToMarkAsQualifier
- the number of items to mark as reserved for use as item qualifiersofferFactory
- theTypeFactory
used to create a newOfferQualifier
if needed- Returns:
- the new or updated
OfferQualifier
DTO related to the givenCandidateItemOffer
-
addOrUpdateMatchingOfferTarget
public void addOrUpdateMatchingOfferTarget(@NonNull CandidateItemOffer itemOffer, @NonNull ItemCriteriaRule targetCriteria, int qtyToMarkAsTarget, @NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory) Either creates a newOfferDiscount
or updates a preexisting one for the givenCandidateItemOffer
, marking the quantity of to reserve for use as targets for the givenItemCriteriaRule
.- Parameters:
itemOffer
- theCandidateItemOffer
for which to either create a newOfferDiscount
or update a preexisting one.targetCriteria
- theOffer.getTargetItemCriteria()
matched by thelineItem
qtyToMarkAsTarget
- the number of items to mark as reserved for use as target itemsofferFactory
- theTypeFactory
used to create a newOfferDiscount
if needed
-
isNonCombinableOfferApplied
protected boolean isNonCombinableOfferApplied()- Returns:
- whether any
ItemOfferAdjustment.getOffer()
adjustment's offer} doesn't have aOffer.getCombinabilityType()
ofCombinabilityType.ANY
.
-
isTotalitarianOfferApplied
public boolean isTotalitarianOfferApplied()- Returns:
- whether any
ItemOfferAdjustment.getOffer()
adjustment's offer} has aOffer.getCombinabilityType()
ofCombinabilityType.NONE
.
-
getQtyAvailableToUseAsTarget
Calculates the number oforder items
available to be used as targets for the providedOffer
.Checks if the provided
Offer
iscombinable
and if all offers already applied tothe related order item
are also combinable, then returns the result of#getQtyAvailableToBeUsed(Offer, boolean)
. If this or an already applied offer arenon-combinable
ortotalitarian
, then returns 0.- Parameters:
offer
- the offer for which we are counting the number of possible targets- Returns:
- the number of
orderLineItems
not already exclusively used as targets or qualifiers
-
getQtyAvailableToUseAsQualifier
Calculates the number oforder items
available to be used as qualifiers for the providedOffer
.- Parameters:
offer
- the offer for which we are counting the number of possible qualifiers- Returns:
- the number of
orderLineItems
not already exclusively used as targets or qualifiers
-
getFinalizedTotalWithAdjustments
public javax.money.MonetaryAmount getFinalizedTotalWithAdjustments()Returns the final total for this item taking into account the finalized orderAdjustments. CallschooseSaleOrStandardPrice()
to finalize the orderAdjustments before returning them.- Returns:
- the final total for this item taking into account the finalized orderAdjustments.
-
splitIfNecessary
@NonNull public Optional<LineItemOfferDetail> splitIfNecessary(@NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory) Checks to see that the discount quantities match the target quantities. If not, splits this item into two.- Returns:
- the item created by splitting
-
calculateItemUnitPriceWithAdjustments
public javax.money.MonetaryAmount calculateItemUnitPriceWithAdjustments(boolean allowSalePrice) - Parameters:
allowSalePrice
- whether to use the sale price in the calculation- Returns:
- the price to be used for this priceDetail taking into account whether or not the sales price can be used.
-
chooseSaleOrStandardPrice
public void chooseSaleOrStandardPrice()This method will check to see if the salePriceAdjustments or standardPriceAdjustments are better and remove those that should not apply. -
buildDetailKey
- Returns:
- a key that represents a unique offer detail
-
getFinalTotalAdjustmentValue
public javax.money.MonetaryAmount getFinalTotalAdjustmentValue(javax.money.CurrencyUnit currency) - Returns:
- the finalized adjustment value multiplied by the quantity
-
calculateTotalAdjustmentValue
public javax.money.MonetaryAmount calculateTotalAdjustmentValue(javax.money.CurrencyUnit currency, boolean useSaleAdjustments) -
calculateAdjustmentValue
public javax.money.MonetaryAmount calculateAdjustmentValue(javax.money.CurrencyUnit currency, boolean useSaleAdjustments) -
getFinalAdjustmentValue
public javax.money.MonetaryAmount getFinalAdjustmentValue(javax.money.CurrencyUnit currency) -
isDiscountCurrentOrder
-
getFinalAdjustmentValueIncludingFutureDiscounts
public javax.money.MonetaryAmount getFinalAdjustmentValueIncludingFutureDiscounts(javax.money.CurrencyUnit currency) -
removeAllAdjustments
public void removeAllAdjustments()Removes all orderAdjustments from this detail. Typically called when it has been determined that another "totalitarian" offer has been applied. -
getQuantityOfItemsExclusivelyUsedAsTargets
protected int getQuantityOfItemsExclusivelyUsedAsTargets(CandidateItemOffer thisOffer, Set<OfferDiscount> offerDiscounts, boolean isForQualifierQty) Calculates the number oforder items
already exclusively used as targets.For qualifiers, his will include:
- The number of items already used as targets by this offer
- The number of items already used as targets by another offer if
Offer.isQualifiersCanBeTargets()
is false for this offer or the other
For targets, his will include:
- The number of items already used as targets by this offer
- The number of items already used as targets by another offer if
Offer#isTargetsCanBeTargets()
is false for that offerr
- Parameters:
thisOffer
- the offer for which we are counting the number of possible qualifiersofferDiscounts
- theOfferDiscount
DTOs containing information about items already used as targets- Returns:
- the number of
orderLineItems
not already exclusively used as targets
-
isStackable
-
checkStackable
-
getQuantityOfItemsExclusivelyUsedAsQualifiers
protected int getQuantityOfItemsExclusivelyUsedAsQualifiers(CandidateItemOffer thisOffer, Set<OfferQualifier> offerQualifiers, boolean isForQualifierQty) Calculates the number oforder items
already exclusively used as qualifiers.For qualifiers, this will include:
- The number of items already used as qualifiers by this offer
- The number of items already used as qualifiers by another offer if
Offer.isQualifiersCanBeQualifiers()
is false for this offer or the other offer
For targets, this will include:
- The number of items already used as qualifiers by this offer
- The number of items already used as qualifiers by another offer if
Offer.isQualifiersCanBeTargets()
is false that offer
- Parameters:
thisOffer
- the offer for which we are counting the number of possible qualifiersofferQualifiers
- theOfferQualifier
DTOs containing information about items already used as qualifiers- Returns:
- the number of
orderLineItems
already exclusively used as qualifiers
-
hasOrderItemAdjustments
protected boolean hasOrderItemAdjustments() -
chooseUnadjustedSaleOrStandardPrice
protected void chooseUnadjustedSaleOrStandardPrice() -
calculateSaleAdjustmentUnitPrice
protected javax.money.MonetaryAmount calculateSaleAdjustmentUnitPrice() -
calculateStandardAdjustmentUnitPrice
protected javax.money.MonetaryAmount calculateStandardAdjustmentUnitPrice() -
getAdjustedTotalUsingSalePrice
protected javax.money.MonetaryAmount getAdjustedTotalUsingSalePrice(javax.money.MonetaryAmount standardAdjustmentPrice) -
getAdjustedTotalUsingStandardPrice
protected javax.money.MonetaryAmount getAdjustedTotalUsingStandardPrice(javax.money.MonetaryAmount standardAdjustmentPrice) -
removeStandardOnlyAdjustments
protected void removeStandardOnlyAdjustments() -
removeZeroDollarAdjustments
protected void removeZeroDollarAdjustments(boolean useSalePrice) -
finalizeAdjustments
protected void finalizeAdjustments(boolean useSaleAdjustments) -
split
protected LineItemOfferDetail split(com.broadleafcommerce.common.extension.TypeFactory offerFactory, OfferDiscount offerDiscount) Splits this item into twoLineItemOfferDetails
and returns the newly createdLineItemOfferDetail
.- Parameters:
offerFactory
- theTypeFactory
used to create a newOfferDiscount
if neededofferDiscount
- theOfferDiscount
to split- Returns:
- the
LineItemOfferDetail
created by splitting
-
split
@Deprecated protected LineItemOfferDetail split(com.broadleafcommerce.common.extension.TypeFactory offerFactory, int discountQty, String offerId, boolean hasQualifiers) Deprecated.since 1.6, in favor ofsplit(TypeFactory, OfferDiscount)
.Splits this item into twoLineItemOfferDetails
and returns the newly createdLineItemOfferDetail
.- Parameters:
offerFactory
- theTypeFactory
used to create a newOfferDiscount
if neededdiscountQty
- the discount quantity to splitofferId
- the offer id of theOfferDiscount.getOffer()
hasQualifiers
- whether or not theOfferDiscount.getOffer()
has qualifiers- Returns:
- the
LineItemOfferDetail
created by splitting
-
copyDiscountsAndAdjustmentsToNewDetail
protected void copyDiscountsAndAdjustmentsToNewDetail(com.broadleafcommerce.common.extension.TypeFactory offerFactory, int discountQty, LineItemOfferDetail newDetail) - Parameters:
offerFactory
- theTypeFactory
used to create a newOfferDiscount
if neededdiscountQty
- quantity to split the discountnewDetail
- the newLineItemOfferDetail
to copy theOfferDiscounts
andItemOfferAdjustments
to
-
addNewQualifierAndGet
protected OfferQualifier addNewQualifierAndGet(com.broadleafcommerce.common.extension.TypeFactory offerFactory, CandidateItemOffer itemOffer) -
lookupOfferQualifierByOffer
-
getQtyAvailableToBeUsed
Calculates the number oforder items
not already exclusively used as targets or qualifiers either by this offer or any other and, therefore, are available to be used as qualifiers or targets by the givenOffer
.Items that are not available to be qualifiers will be:
- Items already used as targets by the given offer
- Items already used as qualifiers by the given offer
- Items already used as targets by another offer if
Offer.isQualifiersCanBeTargets()
is false for the given offer - Items already used as qualifiers by another offer if
Offer.isQualifiersCanBeQualifiers()
is false for the given offer or for the other offer
Items that are not available to be targets will be:
- Items already used as targets by the given offer
- Items already used as qualifiers by the given offer
- Items already used as targets by another offer if
Offer#isTargetsCanBeTargets()
is false for the given offer - Items already used as qualifiers by another offer if
Offer.isQualifiersCanBeTargets()
is false for the given offer or for the other offer
- Parameters:
offer
- the offer for which we are counting the number of possible qualifiers and targetsisForQualifierQty
- Whether this calculation is for qualifiers available or targets.- Returns:
- the number of
orderLineItems
not already exclusively used as targets or qualifiers
-
addNewTargetAndGet
protected OfferDiscount addNewTargetAndGet(com.broadleafcommerce.common.extension.TypeFactory offerFactory, CandidateItemOffer itemOffer) -
lookupOfferTargetByOffer
-
getFutureCreditValue
public javax.money.MonetaryAmount getFutureCreditValue(javax.money.CurrencyUnit currency) -
getBundleRatioOr1
public double getBundleRatioOr1() -
getDetailAsAmountQtyTuple
-
hashCode
public int hashCode() -
getLineItem
TheEnhancedLineItem
affected byoffers
.- Returns:
- The
EnhancedLineItem
affected byoffers
.
-
getAdjustments
- Returns:
- The
ItemOfferAdjustments
caused byoffers
treating thelineItem
as a target.
-
getProratedAdjustments
TheProratedItemOfferAdjustments
caused byoffers
withDiscount.getProrationType()
orProrationType.TARGET_AND_QUALIFIER
treating bothlineItem
as a target and the items that qualify it.- Returns:
- The
ProratedItemOfferAdjustments
caused byoffers
withDiscount.getProrationType()
orProrationType.TARGET_AND_QUALIFIER
treating bothlineItem
as a target and the items that qualify it.
-
getOfferDiscounts
Additional info for all theoffers
treating thelineItem
as a target. Whileadjustments
are the price orderAdjustments, offer discounts track whichOffer.getTargetItemCriteria()
matched thelineItem
and how many were matched.- Returns:
- Additional info for all the
offers
treating thelineItem
as a target.
-
getOfferQualifiers
Additional information about theoffers
using thelineItem
as item qualifiers. This includes the quantity used and theOffer.getItemQualifierCriteria()
of an order item matched.- Returns:
- Additional information about the
offers
using thelineItem
as item qualifiers.
-
getQuantity
public int getQuantity()The quantity of items related to this detail.- Returns:
- The quantity of items related to this detail.
-
isUseSaleAdjustments
public boolean isUseSaleAdjustments()Whether to useEnhancedLineItem.getSalePrice()
in price adjustment calculations. Default is false.- Returns:
- Whether to use
EnhancedLineItem.getSalePrice()
in price adjustment calculations.
-
isAdjustmentsFinalized
public boolean isAdjustmentsFinalized()Whether theadjustments
are the orderAdjustments to actually use rather than being potential or incomplete.- Returns:
- Whether the
adjustments
are the orderAdjustments to actually use rather than being potential or incomplete.
-
getAdjustedTotal
public javax.money.MonetaryAmount getAdjustedTotal()The total value of alladjustments
times thequantity
of this detail.- Returns:
- The total value of all
adjustments
times thequantity
of this detail.
-
getBundleRatio
public double getBundleRatio()The ratio of the offer discount to apply to this item. Used for bundle offers like buy 3 for a fixed price of $10.- Returns:
- The ratio of the offer discount to apply to this item
-
setLineItem
TheEnhancedLineItem
affected byoffers
.- Parameters:
item
- TheEnhancedLineItem
affected byoffers
.
-
setAdjustments
- Parameters:
orderAdjustments
- TheItemOfferAdjustments
caused byoffers
treating thelineItem
as a target.
-
setProratedAdjustments
TheProratedItemOfferAdjustments
caused byoffers
withDiscount.getProrationType()
orProrationType.TARGET_AND_QUALIFIER
treating bothlineItem
as a target and the items that qualify it.- Parameters:
proratedAdjustments
- TheProratedItemOfferAdjustments
caused byoffers
withDiscount.getProrationType()
orProrationType.TARGET_AND_QUALIFIER
treating bothlineItem
as a target and the items that qualify it.
-
setOfferDiscounts
Additional info for all theoffers
treating thelineItem
as a target. Whileadjustments
are the price orderAdjustments, offer discounts track whichOffer.getTargetItemCriteria()
matched thelineItem
and how many were matched.- Parameters:
offerDiscounts
- Additional info for all theoffers
treating thelineItem
as a target.
-
setOfferQualifiers
Additional information about theoffers
using thelineItem
as item qualifiers. This includes the quantity used and theOffer.getItemQualifierCriteria()
of an order item matched.- Parameters:
offerQualifiers
- Additional information about theoffers
using thelineItem
as item qualifiers.
-
setQuantity
public void setQuantity(int quantity) The quantity of items related to this detail.- Parameters:
quantity
- The quantity of items related to this detail.
-
setUseSaleAdjustments
public void setUseSaleAdjustments(boolean useSaleAdjustments) Whether to useEnhancedLineItem.getSalePrice()
in price adjustment calculations. Default is false.- Parameters:
useSaleAdjustments
- Whether to useEnhancedLineItem.getSalePrice()
in price adjustment calculations.
-
setAdjustmentsFinalized
public void setAdjustmentsFinalized(boolean adjustmentsFinalized) Whether theadjustments
are the orderAdjustments to actually use rather than being potential or incomplete.- Parameters:
adjustmentsFinalized
- Whether theadjustments
are the orderAdjustments to actually use rather than being potential or incomplete.
-
setAdjustedTotal
public void setAdjustedTotal(javax.money.MonetaryAmount adjustedTotal) The total value of alladjustments
times thequantity
of this detail.- Parameters:
adjustedTotal
- The total value of alladjustments
times thequantity
of this detail.
-
setBundleRatio
public void setBundleRatio(double bundleRatio) The ratio of the offer discount to apply to this item. Used for bundle offers like buy 3 for a fixed price of $10.- Parameters:
bundleRatio
- Fraction of the offer discount amount to use for this item detail
-
toString
-
split(TypeFactory, OfferDiscount)
.