Class EnhancedLineItem

java.lang.Object
com.broadleafcommerce.promotion.offer.web.context.EnhancedLineItem
All Implemented Interfaces:
com.broadleafcommerce.promotion.offer.client.web.context.LineItem, Serializable
Direct Known Subclasses:
EnhancedFulfillmentLineItem, EnhancedOrderLineItem

public class EnhancedLineItem extends Object implements com.broadleafcommerce.promotion.offer.client.web.context.LineItem, Serializable
See Also:
  • Constructor Details

    • EnhancedLineItem

      public EnhancedLineItem()
  • Method Details

    • getUnadjustedSalePrice

      public javax.money.MonetaryAmount getUnadjustedSalePrice()
      Returns:
      the getSalePrice() if present with no adjustments, otherwise the getStandardPrice().
    • getTotalStandardPrice

      public javax.money.MonetaryAmount getTotalStandardPrice()
      Returns:
      getStandardPrice() multiplied by getQuantity().
    • getPrice

      public javax.money.MonetaryAmount getPrice(boolean useSalePrice)
      Convenience method to get either the getSalePrice() or getStandardPrice() depending on the flag. If salePrice == null, then returns getStandardPrice() no matter the value of the flag.
      Parameters:
      useSalePrice - whether to return getSalePrice() if it exists or getStandardPrice() ()}
      Returns:
      either the getSalePrice() or getStandardPrice() depending on the flag
    • isDependent

      public boolean isDependent()
      Whether this item is an Add-on/dependant type, that is, an item that cannot be sold or fulfilled on its own but as a child of another item. By default, this looks for an attribute called "itemType" with a value of "addOn". It also checks for the present of a "merchandisingContext" attribute, although this is not guaranteed to be set.
      Returns:
      Whether this item is an Add-on/dependant type
    • calculateTotalWithAdjustmentsAsDouble

      public Double calculateTotalWithAdjustmentsAsDouble()
    • calculateTotalWithAdjustments

      public javax.money.MonetaryAmount calculateTotalWithAdjustments()
      Returns:
      the item total including all LineItemOfferDetail.getAdjustments().
    • calculateTotalWithAdjustments

      public AmountQtyTuple calculateTotalWithAdjustments(List<LineItemOfferDetail> details, boolean excludeDiscountedItemsFromTotal)
      This method can be used to pass in a list of previously computed LineItemOfferDetails to produce an adjusted total. Pass in true for the second parameter to exclude items with discounted quantities from the total.
      Parameters:
      details -
      excludeDiscountedItemsFromTotal -
      Returns:
    • isOnSale

      public boolean isOnSale()
      Returns:
      whether this item has a sale price and that it is less than the standard price
    • getOnSale

      public Boolean getOnSale()
      Return isOnSale() as a Boolean for use in rule builders.
      Returns:
    • resetPriceDetails

      public void resetPriceDetails(@NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory)
      Clears all offerDetails and re-initializes them.
      Parameters:
      offerFactory - the TypeFactory to use to create any new LineItemOfferDetails during re-initialization.
    • initializePriceDetails

      public void initializePriceDetails(@NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory)
      Ensures that an LineItemOfferDetail is present so that the offer engine engages correctly.
      Parameters:
      offerFactory - the TypeFactory to use to create a new LineItemOfferDetail
    • createNewDetail

      public LineItemOfferDetail createNewDetail(@NonNull com.broadleafcommerce.common.extension.TypeFactory offerFactory, int quantity)
      Creates a new LineItemOfferDetail for this item.
      Parameters:
      offerFactory - the TypeFactory to use to create any new LineItemOfferDetails
      quantity - the item quantity to associate with the new detail
      Returns:
      the new LineItemOfferDetail
    • mergeLikeDetails

      public void mergeLikeDetails()
      Merges any priceDetails that share the same orderAdjustments.
    • getFinalTotalAdjustmentValue

      public javax.money.MonetaryAmount getFinalTotalAdjustmentValue()
      Returns:
      the total of all adjustments not including dependent items
    • getFutureCreditAdjustmentValue

      public javax.money.MonetaryAmount getFutureCreditAdjustmentValue()
    • calculateTotalAdjustmentValue

      public javax.money.MonetaryAmount calculateTotalAdjustmentValue(boolean useSaleAdjustments)
    • resetOfferDetails

      public void resetOfferDetails()
      Removes all LineItemOfferDetails except the first, which just gets reset.
    • finalizePrice

      public void finalizePrice()
      Sets getFinalPrice() to the average price of each item, which includes adjustments.
    • getAveragePrice

      public javax.money.MonetaryAmount getAveragePrice()
      Returns:
      the total combined price of this order item, including any orderAdjustments but not dependent items, divided by getQuantity().
    • getTotalPriceWithoutAdjustments

      public javax.money.MonetaryAmount getTotalPriceWithoutAdjustments()
      Returns:
      the price without adjustments multiplied by the quantity of items, using the sale price if present.
    • getTotalPriceWithoutAdjustments

      public javax.money.MonetaryAmount getTotalPriceWithoutAdjustments(boolean useSalePriceIfPresent)
    • getUnitPriceWithoutAdjustments

      public javax.money.MonetaryAmount getUnitPriceWithoutAdjustments()
      Returns:
      the unit price without adjustments without multiplying it by the quantity using the sale price if present.
    • getTotalPrice

      public javax.money.MonetaryAmount getTotalPrice()
      Gets the total combined price of this order item, including any adjustments.
      Returns:
      the total combined price of this order item, including any adjustments.
    • mergeDetails

      protected void mergeDetails(LineItemOfferDetail firstDetail, LineItemOfferDetail secondDetail)
    • getFutureCredits

      public javax.money.MonetaryAmount getFutureCredits()
    • getAdjustedTotalWithoutFutureCredits

      public javax.money.MonetaryAmount getAdjustedTotalWithoutFutureCredits()
    • getAdjustedTotalWithoutFutureCredits

      public javax.money.MonetaryAmount getAdjustedTotalWithoutFutureCredits(boolean useSalePriceIfPresent)
    • getId

      public String getId()
    • hasAdjustments

      public boolean hasAdjustments()
    • getEffectiveSegment

      public String getEffectiveSegment()
      Returns "ANY" for null or empty string segments; otherwise, returns the value of #getSegment.
      Returns:
      the effective segment
    • getCurrency

      public javax.money.CurrencyUnit getCurrency()
    • getLineNumber

      public String getLineNumber()
      Specified by:
      getLineNumber in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • getStandardPrice

      public javax.money.MonetaryAmount getStandardPrice()
      Specified by:
      getStandardPrice in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • getSalePrice

      public javax.money.MonetaryAmount getSalePrice()
      Specified by:
      getSalePrice in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • getFulfillmentPrice

      public javax.money.MonetaryAmount getFulfillmentPrice()
    • getQuantity

      public int getQuantity()
      Specified by:
      getQuantity in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • isDiscountable

      public boolean isDiscountable()
      Specified by:
      isDiscountable in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • isSubscription

      public boolean isSubscription()
      Specified by:
      isSubscription in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • getAttributes

      public Map<String,Object> getAttributes()
      Specified by:
      getAttributes in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • getSegment

      public String getSegment()
      Segments can be used to restrict offers. Common examples include segmenting an order by vendor or by store (a.k.a. banner). For applications that do not use segments at all, this value can be left null or set to ANY. The method getEffectiveSegment() will convert null or empty string to "ANY" This field works with the Offer#getRestrictedToSegments
      See Also:
    • getFulfillmentGroupRef

      public String getFulfillmentGroupRef()
    • getFinalPrice

      public javax.money.MonetaryAmount getFinalPrice()
      The final price, including adjustments, for a single merchandising item represented by this order line item.
      Returns:
      The final price, including adjustments, for a single merchandising item represented by this order line item.
    • getOfferDetails

      public List<LineItemOfferDetail> getOfferDetails()
      DTOs containing information about offers applicable to this item.
      Returns:
      DTOs containing information about offers applicable to this item.
    • getProratedAdjustments

      public List<com.broadleafcommerce.promotion.offer.client.web.context.info.ProratedOfferAdjustment> getProratedAdjustments()
      Prorated offer adjustment information for this line item.

      This is typically used to communicate the adjustments prorated to this item from order-level or fulfillment group-level offer adjustments.

      Returns:
      DTOs containing prorated offer adjustment information for this line item
    • setCurrency

      public void setCurrency(javax.money.CurrencyUnit currency)
    • setLineNumber

      public void setLineNumber(String lineNumber)
      Specified by:
      setLineNumber in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • setStandardPrice

      public void setStandardPrice(javax.money.MonetaryAmount standardPrice)
      Specified by:
      setStandardPrice in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • setSalePrice

      public void setSalePrice(javax.money.MonetaryAmount salePrice)
      Specified by:
      setSalePrice in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • setFulfillmentPrice

      public void setFulfillmentPrice(javax.money.MonetaryAmount fulfillmentPrice)
    • setQuantity

      public void setQuantity(int quantity)
      Specified by:
      setQuantity in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • setDiscountable

      public void setDiscountable(boolean discountable)
      Specified by:
      setDiscountable in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • setSubscription

      public void setSubscription(boolean isSubscription)
      Specified by:
      setSubscription in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • setAttributes

      public void setAttributes(Map<String,Object> attributes)
      Specified by:
      setAttributes in interface com.broadleafcommerce.promotion.offer.client.web.context.LineItem
    • setSegment

      public void setSegment(String segment)
      Segments can be used to restrict offers. Common examples include segmenting an order by vendor or by store (a.k.a. banner). For applications that do not use segments at all, this value can be left null or set to ANY. The method getEffectiveSegment() will convert null or empty string to "ANY" This field works with the Offer#getRestrictedToSegments
      See Also:
    • setFulfillmentGroupRef

      public void setFulfillmentGroupRef(String fulfillmentGroupRef)
    • setFinalPrice

      public void setFinalPrice(javax.money.MonetaryAmount finalPrice)
      The final price, including adjustments, for a single merchandising item represented by this order line item.
      Parameters:
      finalPrice - The final price, including adjustments, for a single merchandising item represented by this order line item.
    • setOfferDetails

      public void setOfferDetails(List<LineItemOfferDetail> offerDetails)
      DTOs containing information about offers applicable to this item.
      Parameters:
      offerDetails - DTOs containing information about offers applicable to this item.
    • setProratedAdjustments

      public void setProratedAdjustments(List<com.broadleafcommerce.promotion.offer.client.web.context.info.ProratedOfferAdjustment> proratedAdjustments)
      Prorated offer adjustment information for this line item.

      This is typically used to communicate the adjustments prorated to this item from order-level or fulfillment group-level offer adjustments.

      Parameters:
      proratedAdjustments - DTOs containing prorated offer adjustment information for this line item
    • setId

      public void setId(String id)
      Matches the line number unless the line number isn't available in which case it will represent a uuid.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object