Class OrderItemImpl

java.lang.Object
org.broadleafcommerce.core.order.domain.OrderItemImpl
All Implemented Interfaces:
Serializable, Cloneable, org.broadleafcommerce.common.admin.domain.AdminMainEntity, org.broadleafcommerce.common.copy.MultiTenantCloneable<OrderItem>, org.broadleafcommerce.common.currency.util.CurrencyCodeIdentifiable, OrderItem
Direct Known Subclasses:
BundleOrderItemImpl, DiscreteOrderItemImpl

@Entity public class OrderItemImpl extends Object implements OrderItem, Cloneable, org.broadleafcommerce.common.admin.domain.AdminMainEntity, org.broadleafcommerce.common.currency.util.CurrencyCodeIdentifiable
See Also:
  • Field Details

  • Constructor Details

    • OrderItemImpl

      public OrderItemImpl()
  • Method Details

    • getRetailPrice

      public org.broadleafcommerce.common.money.Money getRetailPrice()
      Description copied from interface: OrderItem
      The retail price of the item that was added to the Order at the time that this was added. This is preferable to use as opposed to checking the price of the item that was added from the catalog domain (like in DiscreteOrderItem, using DiscreteOrderItem.getSku()'s retail price) since the price in the catalog domain could have changed since the item was added to the Order.
      Specified by:
      getRetailPrice in interface OrderItem
      Returns:
    • setRetailPrice

      public void setRetailPrice(org.broadleafcommerce.common.money.Money retailPrice)
      Description copied from interface: OrderItem
      Calling this method will manually set the retailPrice. To avoid the pricing engine resetting this price, you should also make a call to {@link #setRetailPriceOverride(true)}

      Consider also calling OrderItem.setDiscountingAllowed(boolean) with a value of false to restrict discounts after manually setting the retail price.

      Specified by:
      setRetailPrice in interface OrderItem
    • getSalePrice

      public org.broadleafcommerce.common.money.Money getSalePrice()
      Description copied from interface: OrderItem
      Returns the salePrice for this item. Note this method will return the lower of the retailPrice or salePrice. It will return the retailPrice instead of null.

      For SKU based pricing, a call to OrderItem.updateSaleAndRetailPrices() will ensure that the retailPrice being used is current.

      Specified by:
      getSalePrice in interface OrderItem
      Returns:
    • setSalePrice

      public void setSalePrice(org.broadleafcommerce.common.money.Money salePrice)
      Description copied from interface: OrderItem
      Calling this method will manually set the salePrice. It will also make a call to {@link #setSalePriceSetManually(true)}

      To avoid the pricing engine resetting this price, you should also make a call to {@link #setSalePriceOverride(true)}

      Typically for DiscreteOrderItems, the prices will be set with a call to OrderItem.updateSaleAndRetailPrices() which will use the Broadleaf dynamic pricing engine or the values directly tied to the SKU.

      Specified by:
      setSalePrice in interface OrderItem
    • getPrice

      public org.broadleafcommerce.common.money.Money getPrice()
      Specified by:
      getPrice in interface OrderItem
      Returns:
    • setPrice

      public void setPrice(org.broadleafcommerce.common.money.Money finalPrice)
      Description copied from interface: OrderItem
      Calling this method is the same as calling the following:

      OrderItem.setRetailPrice(Money) OrderItem.setSalePrice(Money) {@link #setRetailPriceOverride(true)} {@link #setSalePriceOverride(true)} {@link #setDiscountingAllowed(false)}

      This has the effect of setting the price in a way that no discounts or adjustments can be made.

      Specified by:
      setPrice in interface OrderItem
    • getTaxablePrice

      public org.broadleafcommerce.common.money.Money getTaxablePrice()
      Specified by:
      getTaxablePrice in interface OrderItem
      Returns:
    • getAuditable

      public org.broadleafcommerce.common.audit.Auditable getAuditable()
      Specified by:
      getAuditable in interface OrderItem
      Returns:
      the Auditable date for this record
    • setAuditable

      public void setAuditable(org.broadleafcommerce.common.audit.Auditable auditable)
      Description copied from interface: OrderItem
      Sets the Auditable date object - typially set by Hibernate through the AuditableListener
      Specified by:
      setAuditable in interface OrderItem
    • getQuantity

      public int getQuantity()
      Description copied from interface: OrderItem
      The quantity of this OrderItem.
      Specified by:
      getQuantity in interface OrderItem
      Returns:
    • setQuantity

      public void setQuantity(int quantity)
      Description copied from interface: OrderItem
      Sets the quantity of this item
      Specified by:
      setQuantity in interface OrderItem
    • getCategory

      public Category getCategory()
      Specified by:
      getCategory in interface OrderItem
    • setCategory

      public void setCategory(Category category)
      Specified by:
      setCategory in interface OrderItem
    • getCandidateItemOffers

      public List<CandidateItemOffer> getCandidateItemOffers()
      Specified by:
      getCandidateItemOffers in interface OrderItem
    • setCandidateItemOffers

      public void setCandidateItemOffers(List<CandidateItemOffer> candidateItemOffers)
      Specified by:
      setCandidateItemOffers in interface OrderItem
    • getPersonalMessage

      public PersonalMessage getPersonalMessage()
      Specified by:
      getPersonalMessage in interface OrderItem
    • setPersonalMessage

      public void setPersonalMessage(PersonalMessage personalMessage)
      Specified by:
      setPersonalMessage in interface OrderItem
    • getOrder

      public Order getOrder()
      Description copied from interface: OrderItem
      Reference back to the containing order.
      Specified by:
      getOrder in interface OrderItem
      Returns:
    • setOrder

      public void setOrder(Order order)
      Description copied from interface: OrderItem
      Sets the order for this orderItem.
      Specified by:
      setOrder in interface OrderItem
    • getId

      public Long getId()
      Description copied from interface: OrderItem
      The unique identifier of this OrderItem
      Specified by:
      getId in interface OrderItem
      Returns:
    • setId

      public void setId(Long id)
      Description copied from interface: OrderItem
      Sets the unique id of the OrderItem. Typically left null for new items and Broadleaf will set using the next sequence number.
      Specified by:
      setId in interface OrderItem
    • getName

      public String getName()
      Description copied from interface: OrderItem
      Generally copied from the Sku.getName()
      Specified by:
      getName in interface OrderItem
      Returns:
    • setName

      public void setName(String name)
      Description copied from interface: OrderItem
      Sets the name of this order item.
      Specified by:
      setName in interface OrderItem
    • isInCategory

      public boolean isInCategory(String categoryName)
      Specified by:
      isInCategory in interface OrderItem
    • getOrderItemQualifiers

      public List<OrderItemQualifier> getOrderItemQualifiers()
      Description copied from interface: OrderItem
      If any quantity of this item was used to qualify for an offer, then this returned list will indicate the offer and the relevant quantity.

      As an example, a BuyOneGetOneFree offer would have 1 qualifier and 1 adjustment.

      Specified by:
      getOrderItemQualifiers in interface OrderItem
      Returns:
      a List of OrderItemAdjustment
    • setOrderItemQualifiers

      public void setOrderItemQualifiers(List<OrderItemQualifier> orderItemQualifiers)
      Description copied from interface: OrderItem
      Sets the list of OrderItemQualifiers
      Specified by:
      setOrderItemQualifiers in interface OrderItem
    • getOrderItemAdjustments

      public List<OrderItemAdjustment> getOrderItemAdjustments()
      Description copied from interface: OrderItem
      Returns item level adjustment for versions of Broadleaf Commerce prior to 2.3.0 which replaced this concept with OrderItemPriceDetail adjustments.
      Specified by:
      getOrderItemAdjustments in interface OrderItem
      Returns:
      a List of OrderItemAdjustment
    • setOrderItemAdjustments

      public void setOrderItemAdjustments(List<OrderItemAdjustment> orderItemAdjustments)
      Specified by:
      setOrderItemAdjustments in interface OrderItem
    • getProratedOrderItemAdjustments

      public List<ProratedOrderItemAdjustment> getProratedOrderItemAdjustments()
      Description copied from interface: OrderItem
      Returns a list of all prorated adjustments for this order item.
      Specified by:
      getProratedOrderItemAdjustments in interface OrderItem
      Returns:
    • setProratedOrderItemAdjustments

      public void setProratedOrderItemAdjustments(List<ProratedOrderItemAdjustment> proratedOrderItemAdjustments)
      Description copied from interface: OrderItem
      Sets the list of prorated order item adjustments for this order item.
      Specified by:
      setProratedOrderItemAdjustments in interface OrderItem
    • getAdjustmentValue

      public org.broadleafcommerce.common.money.Money getAdjustmentValue()
      Specified by:
      getAdjustmentValue in interface OrderItem
      Returns:
    • getGiftWrapOrderItem

      public GiftWrapOrderItem getGiftWrapOrderItem()
      Specified by:
      getGiftWrapOrderItem in interface OrderItem
    • setGiftWrapOrderItem

      public void setGiftWrapOrderItem(GiftWrapOrderItem giftWrapOrderItem)
      Specified by:
      setGiftWrapOrderItem in interface OrderItem
    • getOrderItemType

      public OrderItemType getOrderItemType()
      Specified by:
      getOrderItemType in interface OrderItem
    • setOrderItemType

      public void setOrderItemType(OrderItemType orderItemType)
      Specified by:
      setOrderItemType in interface OrderItem
    • getIsOnSale

      public boolean getIsOnSale()
      Description copied from interface: OrderItem
      Specified by:
      getIsOnSale in interface OrderItem
      Returns:
    • getIsDiscounted

      public boolean getIsDiscounted()
      Description copied from interface: OrderItem
      Returns true if this item received a discount.
      Specified by:
      getIsDiscounted in interface OrderItem
      Returns:
    • updateSaleAndRetailPrices

      public boolean updateSaleAndRetailPrices()
      Description copied from interface: OrderItem
      Used to reset the base price of the item that the pricing engine uses.

      Generally, this will update the retailPrice and salePrice based on the corresponding value in the SKU.

      If the retail or sale price was manually set, this method will not change those prices.

      For non-manually set prices, prices can change based on system activities such as locale changes and customer authentication, this method is used to ensure that all cart items reflect the current base price before executing other pricing / adjustment operations.

      Other known scenarios that can effect the base prices include the automatic bundling or loading a stale cart from the database.

      See notes in subclasses for specific behavior of this method.

      Specified by:
      updateSaleAndRetailPrices in interface OrderItem
      Returns:
      true if the base prices changed as a result of this call
    • finalizePrice

      public void finalizePrice()
      Description copied from interface: OrderItem
      Called by the pricing engine after prices have been computed. Allows the system to set the averagePrice that is stored for the item.
      Specified by:
      finalizePrice in interface OrderItem
    • assignFinalPrice

      public void assignFinalPrice()
      Description copied from interface: OrderItem
      Used to set the final price of the item and corresponding details.
      Specified by:
      assignFinalPrice in interface OrderItem
    • getPriceBeforeAdjustments

      public org.broadleafcommerce.common.money.Money getPriceBeforeAdjustments(boolean allowSalesPrice)
      Description copied from interface: OrderItem
      Returns the unit price of this item. If the parameter allowSalesPrice is true, will return the sale price if one exists.

      Note that retail and sale prices are initialized for an OrderItem during the first execution of any method that depends on the sale or retail price including this one.

      Specified by:
      getPriceBeforeAdjustments in interface OrderItem
      Returns:
      See Also:
    • getPriceBeforeAdjustments

      public org.broadleafcommerce.common.money.Money getPriceBeforeAdjustments(boolean allowSalesPrice, boolean includeChildren)
      Specified by:
      getPriceBeforeAdjustments in interface OrderItem
    • addCandidateItemOffer

      public void addCandidateItemOffer(CandidateItemOffer candidateItemOffer)
      Description copied from interface: OrderItem
      Used by the promotion engine to add offers that might apply to this orderItem.
      Specified by:
      addCandidateItemOffer in interface OrderItem
    • removeAllCandidateItemOffers

      public void removeAllCandidateItemOffers()
      Description copied from interface: OrderItem
      Removes all candidate offers. Used by the promotion engine which subsequently adds the candidate offers that might apply back to this item.
      Specified by:
      removeAllCandidateItemOffers in interface OrderItem
    • removeAllAdjustments

      public int removeAllAdjustments()
      Description copied from interface: OrderItem
      Removes all adjustment for this order item and reset the adjustment price.
      Specified by:
      removeAllAdjustments in interface OrderItem
    • getOrderItemAttributes

      public Map<String,OrderItemAttribute> getOrderItemAttributes()
      A list of arbitrary attributes added to this item.
      Specified by:
      getOrderItemAttributes in interface OrderItem
    • setOrderItemAttributes

      public void setOrderItemAttributes(Map<String,OrderItemAttribute> orderItemAttributes)
      Sets the map of order item attributes.
      Specified by:
      setOrderItemAttributes in interface OrderItem
      Parameters:
      orderItemAttributes -
    • isTaxable

      public Boolean isTaxable()
      Description copied from interface: OrderItem
      Returns whether or not this item is taxable. If this flag is not set, it returns true by default
      Specified by:
      isTaxable in interface OrderItem
      Returns:
      the taxable flag. If null, returns true
    • setTaxable

      public void setTaxable(Boolean taxable)
      Description copied from interface: OrderItem
      Sets whether or not this item is taxable. Generally, this has been copied from the setting of the relevant SKU at the time it was added.
      Specified by:
      setTaxable in interface OrderItem
    • isDiscountingAllowed

      public boolean isDiscountingAllowed()
      Description copied from interface: OrderItem
      If true, this item can be discounted..
      Specified by:
      isDiscountingAllowed in interface OrderItem
    • setDiscountingAllowed

      public void setDiscountingAllowed(boolean discountsAllowed)
      Description copied from interface: OrderItem
      Turns off discount processing for this line item.
      Specified by:
      setDiscountingAllowed in interface OrderItem
    • getAveragePrice

      public org.broadleafcommerce.common.money.Money getAveragePrice()
      Description copied from interface: OrderItem
      Returns the average unit display price for the item.

      Some implementations may choose to show this on a view cart screen. Due to fractional discounts, it the display could represent a unit price that is off.

      For example, if this OrderItem had 3 items at $1 each and also received a $1 discount. The net effect under the default rounding scenario would be an average price of $0.666666

      Most systems would represent this as $0.67 as the discounted unit price; however, this amount times 3 ($2.01) would not equal the getTotalPrice() which would be $2.00. For this reason, it is not recommended that implementations utilize this field. Instead, they may choose not to show the unit price or show multiple prices by looping through the OrderItemPriceDetails.

      Specified by:
      getAveragePrice in interface OrderItem
      Returns:
    • getAverageAdjustmentValue

      public org.broadleafcommerce.common.money.Money getAverageAdjustmentValue()
      Description copied from interface: OrderItem
      Returns the average unit item adjustments.

      For example, if this item has a quantity of 2 at a base-price of $10 and a 10% discount applies to both then this method would return $1.

      Some implementations may choose to show this on a view cart screen. Due to fractional discounts, the display could represent a unit adjustment value that is off due to rounding. See OrderItem.getAveragePrice() for an example of this.

      Implementations wishing to show unit prices may choose instead to show the individual OrderItemPriceDetails instead of this value to avoid the rounding problem. This would result in multiple cart item display rows for each OrderItem.

      Alternatively, the cart display should use OrderItem.getTotalAdjustmentValue().

      Specified by:
      getAverageAdjustmentValue in interface OrderItem
      Returns:
    • getTotalAdjustmentValue

      public org.broadleafcommerce.common.money.Money getTotalAdjustmentValue()
      Description copied from interface: OrderItem
      Returns the total for all item level adjustments.

      For example, if the item has a 2 items priced at $10 a piece and a 10% discount applies to both quantities. This method would return $2.

      Specified by:
      getTotalAdjustmentValue in interface OrderItem
      Returns:
    • getTotalAdjustmentValue

      public org.broadleafcommerce.common.money.Money getTotalAdjustmentValue(boolean includeChildren)
      Description copied from interface: OrderItem
      Returns the total for all item level adjustments.
      Specified by:
      getTotalAdjustmentValue in interface OrderItem
      Returns:
    • getFutureCreditTotalAdjustmentValue

      public org.broadleafcommerce.common.money.Money getFutureCreditTotalAdjustmentValue()
      Description copied from interface: OrderItem
      Returns the total for future credit item level adjustments.

      For example, if the item has a 2 items priced at $10 a piece and a 10% discount applies to both quantities. This method would return $2.

      See Offer.getAdjustmentType() for more info on future credit

      Specified by:
      getFutureCreditTotalAdjustmentValue in interface OrderItem
      Returns:
    • getFutureCreditTotalAdjustmentValue

      public org.broadleafcommerce.common.money.Money getFutureCreditTotalAdjustmentValue(boolean includeChildren)
      Description copied from interface: OrderItem
      Returns the total for future credit item level adjustments.

      See Offer.getAdjustmentType() for more info on future credit

      Specified by:
      getFutureCreditTotalAdjustmentValue in interface OrderItem
      Returns:
    • getTotalPrice

      public org.broadleafcommerce.common.money.Money getTotalPrice()
      Description copied from interface: OrderItem
      Returns the total price to be paid for this order item including item-level adjustments.

      It does not include the effect of order level adjustments. Calculated by looping through the orderItemPriceDetails

      Specified by:
      getTotalPrice in interface OrderItem
      Returns:
    • getTotalPrice

      public org.broadleafcommerce.common.money.Money getTotalPrice(boolean includeChildren)
      Description copied from interface: OrderItem
      Returns the total price to be paid for this order item including item-level adjustments.
      Specified by:
      getTotalPrice in interface OrderItem
      Returns:
    • getTotalPriceBeforeAdjustments

      public org.broadleafcommerce.common.money.Money getTotalPriceBeforeAdjustments(boolean allowSalesPrice)
      Description copied from interface: OrderItem
      Returns the total price to be paid before adjustments.
      Specified by:
      getTotalPriceBeforeAdjustments in interface OrderItem
      Returns:
    • isRetailPriceOverride

      public boolean isRetailPriceOverride()
      Description copied from interface: OrderItem
      Returns true if the retail price was manually set. If the retail price is manually set, calls to updatePrices() will not do anything.
      Specified by:
      isRetailPriceOverride in interface OrderItem
      Returns:
    • setRetailPriceOverride

      public void setRetailPriceOverride(boolean override)
      Description copied from interface: OrderItem
      Indicates that the retail price was manually set. A typical usage might be for a CSR who has override privileges to control setting the price. This will automatically be set by calling OrderItem.setRetailPrice(Money)
      Specified by:
      setRetailPriceOverride in interface OrderItem
    • isSalePriceOverride

      public boolean isSalePriceOverride()
      Description copied from interface: OrderItem
      Returns true if the sale price was manually set. If the retail price is manually set, calls to updatePrices() will not do anything.
      Specified by:
      isSalePriceOverride in interface OrderItem
      Returns:
    • setSalePriceOverride

      public void setSalePriceOverride(boolean override)
      Description copied from interface: OrderItem
      Indicates that the sale price was manually set. A typical usage might be for a CSR who has override privileges to control setting the price.

      Consider also calling OrderItem.setDiscountingAllowed(boolean) with a value of false to restrict discounts after manually setting the retail price.

      If the salePrice is not lower than the retailPrice, the system will return the retailPrice when a call to OrderItem.getSalePrice() is made.

      Specified by:
      setSalePriceOverride in interface OrderItem
    • getOrderItemPriceDetails

      public List<OrderItemPriceDetail> getOrderItemPriceDetails()
      Description copied from interface: OrderItem
      Collection of priceDetails for this orderItem.

      Without discounts, an orderItem would have exactly 1 ItemPriceDetail. When orderItem discounting or tax-calculations result in an orderItem having multiple prices like in a buy-one-get-one free example, the orderItem will get an additional ItemPriceDetail.

      Generally, an OrderItem will have 1 ItemPriceDetail record for each uniquely priced version of the item.

      Specified by:
      getOrderItemPriceDetails in interface OrderItem
    • setOrderItemPriceDetails

      public void setOrderItemPriceDetails(List<OrderItemPriceDetail> orderItemPriceDetails)
      Description copied from interface: OrderItem
      Returns the list of orderItem price details.
      Specified by:
      setOrderItemPriceDetails in interface OrderItem
    • getChildOrderItems

      public List<OrderItem> getChildOrderItems()
      Specified by:
      getChildOrderItems in interface OrderItem
      Returns:
      the list of orderitems that are dependent on this order item
    • setChildOrderItems

      public void setChildOrderItems(List<OrderItem> childOrderItems)
      Description copied from interface: OrderItem
      Sets the list of orderitems that are dependent on this order item
      Specified by:
      setChildOrderItems in interface OrderItem
    • getParentOrderItem

      public OrderItem getParentOrderItem()
      Specified by:
      getParentOrderItem in interface OrderItem
      Returns:
      the parent order item for this item (potentially null)
    • setParentOrderItem

      public void setParentOrderItem(OrderItem parentOrderItem)
      Description copied from interface: OrderItem
      Sets the parent order item for this order item
      Specified by:
      setParentOrderItem in interface OrderItem
    • getHasValidationError

      public Boolean getHasValidationError()
      Specified by:
      getHasValidationError in interface OrderItem
      Returns:
      whether or not this order item has an error
    • setHasValidationError

      public void setHasValidationError(Boolean hasValidationError)
      Description copied from interface: OrderItem
      Sets whether or not this order item has an error associated with it
      Specified by:
      setHasValidationError in interface OrderItem
    • getCartMessages

      public List<String> getCartMessages()
      Specified by:
      getCartMessages in interface OrderItem
      Returns:
      the list of messages that should be displayed in the cart
    • setCartMessages

      public void setCartMessages(List<String> cartMessage)
      Description copied from interface: OrderItem
      Sets the list of messages that should be displayed in the cart
      Specified by:
      setCartMessages in interface OrderItem
    • isAParentOf

      public boolean isAParentOf(OrderItem candidateChild)
      Specified by:
      isAParentOf in interface OrderItem
      Returns:
      true if the candidateChild is a child of the hierarchy starting from this OrderItem
    • isChildOrderItem

      public boolean isChildOrderItem()
      Specified by:
      isChildOrderItem in interface OrderItem
      Returns:
      true if the OrderItem has a parent
    • getMainEntityName

      public String getMainEntityName()
      Specified by:
      getMainEntityName in interface org.broadleafcommerce.common.admin.domain.AdminMainEntity
    • getCurrencyCode

      public String getCurrencyCode()
      Specified by:
      getCurrencyCode in interface org.broadleafcommerce.common.currency.util.CurrencyCodeIdentifiable
    • shouldSumChildren

      @Deprecated protected boolean shouldSumChildren()
      Deprecated.
    • checkCloneable

      public void checkCloneable(OrderItem orderItem) throws CloneNotSupportedException, SecurityException, NoSuchMethodException
      Throws:
      CloneNotSupportedException
      SecurityException
      NoSuchMethodException
    • convertToMoney

      protected org.broadleafcommerce.common.money.Money convertToMoney(BigDecimal amount)
    • convertOrderItemType

      protected OrderItemType convertOrderItemType(String type)
    • clone

      public OrderItem clone()
      Specified by:
      clone in interface OrderItem
      Overrides:
      clone in class Object
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • createOrRetrieveCopyInstance

      public <G extends OrderItem> org.broadleafcommerce.common.copy.CreateResponse<G> createOrRetrieveCopyInstance(org.broadleafcommerce.common.copy.MultiTenantCopyContext context) throws CloneNotSupportedException
      Specified by:
      createOrRetrieveCopyInstance in interface org.broadleafcommerce.common.copy.MultiTenantCloneable<OrderItem>
      Throws:
      CloneNotSupportedException
    • isSkuActive

      public boolean isSkuActive()
      Description copied from interface: OrderItem
      Returns a boolean indicating whether this sku is active. This is used to determine whether a user the sku can add the sku to their cart.
      Specified by:
      isSkuActive in interface OrderItem