Class LineItemOfferDetail

java.lang.Object
com.broadleafcommerce.promotion.offer.web.context.info.LineItemOfferDetail
All Implemented Interfaces:
Serializable

public class LineItemOfferDetail extends Object implements 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 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 new OfferQualifier or updates a preexisting one for the given CandidateItemOffer, marking the quantity of to reserve for use as qualifiers for the given ItemCriteriaRule.
      Parameters:
      itemOffer - the CandidateItemOffer for which to either create a new OfferQualifier or update a preexisting one.
      qualifierCriteria - the Offer.getItemQualifierCriteria() matched by the lineItem
      qtyToMarkAsQualifier - the number of items to mark as reserved for use as item qualifiers
      offerFactory - the TypeFactory used to create a new OfferQualifier if needed
      Returns:
      the new or updated OfferQualifier DTO related to the given CandidateItemOffer
    • addOrUpdateMatchingOfferTarget

      public void addOrUpdateMatchingOfferTarget(@NonNull CandidateItemOffer itemOffer, @NonNull ItemCriteriaRule targetCriteria, int qtyToMarkAsTarget, @NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory)
      Either creates a new OfferDiscount or updates a preexisting one for the given CandidateItemOffer, marking the quantity of to reserve for use as targets for the given ItemCriteriaRule.
      Parameters:
      itemOffer - the CandidateItemOffer for which to either create a new OfferDiscount or update a preexisting one.
      targetCriteria - the Offer.getTargetItemCriteria() matched by the lineItem
      qtyToMarkAsTarget - the number of items to mark as reserved for use as target items
      offerFactory - the TypeFactory used to create a new OfferDiscount if needed
    • isNonCombinableOfferApplied

      protected boolean isNonCombinableOfferApplied()
      Returns:
      whether any ItemOfferAdjustment.getOffer() adjustment's offer} doesn't have a Offer.getCombinabilityType() of CombinabilityType.ANY.
    • isTotalitarianOfferApplied

      public boolean isTotalitarianOfferApplied()
      Returns:
      whether any ItemOfferAdjustment.getOffer() adjustment's offer} has a Offer.getCombinabilityType() of CombinabilityType.NONE.
    • getQtyAvailableToUseAsTarget

      public int getQtyAvailableToUseAsTarget(CandidateItemOffer offer)
      Calculates the number of order items available to be used as targets for the provided Offer.

      Checks if the provided Offer is combinable and if all offers already applied to the related order item are also combinable, then returns the result of #getQtyAvailableToBeUsed(Offer, boolean). If this or an already applied offer are non-combinable or totalitarian, 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

      public int getQtyAvailableToUseAsQualifier(CandidateItemOffer offer)
      Calculates the number of order items available to be used as qualifiers for the provided Offer.
      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. Calls chooseSaleOrStandardPrice() 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

      @NonNull public String 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

      protected Predicate<ItemOfferAdjustment> 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 of order 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 qualifiers
      offerDiscounts - the OfferDiscount DTOs containing information about items already used as targets
      Returns:
      the number of orderLineItems not already exclusively used as targets
    • isStackable

      protected boolean isStackable(Offer offer, Offer otherOffer)
    • checkStackable

      protected boolean checkStackable(Offer offer, Offer otherOffer)
    • getQuantityOfItemsExclusivelyUsedAsQualifiers

      protected int getQuantityOfItemsExclusivelyUsedAsQualifiers(CandidateItemOffer thisOffer, Set<OfferQualifier> offerQualifiers, boolean isForQualifierQty)
      Calculates the number of order 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 qualifiers
      offerQualifiers - the OfferQualifier 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 two LineItemOfferDetails and returns the newly created LineItemOfferDetail.
      Parameters:
      offerFactory - the TypeFactory used to create a new OfferDiscount if needed
      offerDiscount - the OfferDiscount 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 of split(TypeFactory, OfferDiscount).
      Splits this item into two LineItemOfferDetails and returns the newly created LineItemOfferDetail.
      Parameters:
      offerFactory - the TypeFactory used to create a new OfferDiscount if needed
      discountQty - the discount quantity to split
      offerId - the offer id of the OfferDiscount.getOffer()
      hasQualifiers - whether or not the OfferDiscount.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 - the TypeFactory used to create a new OfferDiscount if needed
      discountQty - quantity to split the discount
      newDetail - the new LineItemOfferDetail to copy the OfferDiscounts and ItemOfferAdjustments to
    • addNewQualifierAndGet

      protected OfferQualifier addNewQualifierAndGet(com.broadleafcommerce.common.extension.TypeFactory offerFactory, CandidateItemOffer itemOffer)
    • lookupOfferQualifierByOffer

      protected Optional<OfferQualifier> lookupOfferQualifierByOffer(CandidateItemOffer itemOffer)
    • getQtyAvailableToBeUsed

      protected int getQtyAvailableToBeUsed(CandidateItemOffer offer, boolean isForQualifierQty)
      Calculates the number of order 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 given Offer.

      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 targets
      isForQualifierQty - 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

      protected Optional<OfferDiscount> lookupOfferTargetByOffer(CandidateItemOffer itemOffer)
    • getFutureCreditValue

      public javax.money.MonetaryAmount getFutureCreditValue(javax.money.CurrencyUnit currency)
    • getBundleRatioOr1

      public double getBundleRatioOr1()
    • getDetailAsAmountQtyTuple

      public AmountQtyTuple getDetailAsAmountQtyTuple()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getLineItem

      public EnhancedLineItem getLineItem()
      The EnhancedLineItem affected by offers.
      Returns:
      The EnhancedLineItem affected by offers.
    • getAdjustments

      public Set<ItemOfferAdjustment> getAdjustments()
      The ItemOfferAdjustments caused by offers treating the lineItem as a target.
      Returns:
      The ItemOfferAdjustments caused by offers treating the lineItem as a target.
    • getProratedAdjustments

      public Set<EnhancedProratedItemOfferAdjustment> getProratedAdjustments()
      The ProratedItemOfferAdjustments caused by offers with Discount.getProrationType() or ProrationType.TARGET_AND_QUALIFIER treating both lineItem as a target and the items that qualify it.
      Returns:
      The ProratedItemOfferAdjustments caused by offers with Discount.getProrationType() or ProrationType.TARGET_AND_QUALIFIER treating both lineItem as a target and the items that qualify it.
    • getOfferDiscounts

      public Set<OfferDiscount> getOfferDiscounts()
      Additional info for all the offers treating the lineItem as a target. While adjustments are the price orderAdjustments, offer discounts track which Offer.getTargetItemCriteria() matched the lineItem and how many were matched.
      Returns:
      Additional info for all the offers treating the lineItem as a target.
    • getOfferQualifiers

      public Set<OfferQualifier> getOfferQualifiers()
      Additional information about the offers using the lineItem as item qualifiers. This includes the quantity used and the Offer.getItemQualifierCriteria() of an order item matched.
      Returns:
      Additional information about the offers using the lineItem 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 use EnhancedLineItem.getSalePrice() in price adjustment calculations. Default is false.
      Returns:
      Whether to use EnhancedLineItem.getSalePrice() in price adjustment calculations.
    • isAdjustmentsFinalized

      public boolean isAdjustmentsFinalized()
      Whether the adjustments 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 all adjustments times the quantity of this detail.
      Returns:
      The total value of all adjustments times the quantity 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

      public void setLineItem(EnhancedLineItem lineItem)
      The EnhancedLineItem affected by offers.
      Parameters:
      item - The EnhancedLineItem affected by offers.
    • setAdjustments

      public void setAdjustments(Set<ItemOfferAdjustment> adjustments)
      The ItemOfferAdjustments caused by offers treating the lineItem as a target.
      Parameters:
      orderAdjustments - The ItemOfferAdjustments caused by offers treating the lineItem as a target.
    • setProratedAdjustments

      public void setProratedAdjustments(Set<EnhancedProratedItemOfferAdjustment> proratedAdjustments)
      The ProratedItemOfferAdjustments caused by offers with Discount.getProrationType() or ProrationType.TARGET_AND_QUALIFIER treating both lineItem as a target and the items that qualify it.
      Parameters:
      proratedAdjustments - The ProratedItemOfferAdjustments caused by offers with Discount.getProrationType() or ProrationType.TARGET_AND_QUALIFIER treating both lineItem as a target and the items that qualify it.
    • setOfferDiscounts

      public void setOfferDiscounts(Set<OfferDiscount> offerDiscounts)
      Additional info for all the offers treating the lineItem as a target. While adjustments are the price orderAdjustments, offer discounts track which Offer.getTargetItemCriteria() matched the lineItem and how many were matched.
      Parameters:
      offerDiscounts - Additional info for all the offers treating the lineItem as a target.
    • setOfferQualifiers

      public void setOfferQualifiers(Set<OfferQualifier> offerQualifiers)
      Additional information about the offers using the lineItem as item qualifiers. This includes the quantity used and the Offer.getItemQualifierCriteria() of an order item matched.
      Parameters:
      offerQualifiers - Additional information about the offers using the lineItem 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 use EnhancedLineItem.getSalePrice() in price adjustment calculations. Default is false.
      Parameters:
      useSaleAdjustments - Whether to use EnhancedLineItem.getSalePrice() in price adjustment calculations.
    • setAdjustmentsFinalized

      public void setAdjustmentsFinalized(boolean adjustmentsFinalized)
      Whether the adjustments are the orderAdjustments to actually use rather than being potential or incomplete.
      Parameters:
      adjustmentsFinalized - Whether the adjustments are the orderAdjustments to actually use rather than being potential or incomplete.
    • setAdjustedTotal

      public void setAdjustedTotal(javax.money.MonetaryAmount adjustedTotal)
      The total value of all adjustments times the quantity of this detail.
      Parameters:
      adjustedTotal - The total value of all adjustments times the quantity 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

      public String toString()
      Overrides:
      toString in class Object