Class LineItem
java.lang.Object
de.hybris.order.calculation.domain.LineItem
- All Implemented Interfaces:
Taxable
- Direct Known Subclasses:
NumberedLineItem
Represents one entry (or element) for an
Order. Central objects that holds all line items related data
required for amount calculation. A LineItem is Taxable which means getTotal(Order) is used
for tax calculation. This line item holds the basePrice and the numberOfUnits. Additionally the giveAwayCount can be
set (10 items are bought, 5 of them are free) and this line item holds a ordered List of
LineItemDiscounts and LineItemCharges. The line item must use the same Currency as the linked
Order or a CurrenciesAreNotEqualException is thrown.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCharge(int index, LineItemCharge lineItemCharge) Adds a single charge to this line item at a specific position.voidaddCharge(LineItemCharge lineItemCharge) Adds a single charge to this line item.voidaddCharges(LineItemCharge... lineItemCharges) Adds multiple charges to this line item.voidaddCharges(List<LineItemCharge> lineItemCharges) Adds multiple charges to this line item.voidaddDiscount(int index, LineItemDiscount discount) Adds a single discount to this line item at a specific position.voidaddDiscount(LineItemDiscount discount) Adds a single discount to this line item.voidaddDiscounts(LineItemDiscount... discounts) Adds multiple discounts to this line item.voidaddDiscounts(List<LineItemDiscount> discounts) Adds multiple discounts to this line item.protected voidassertCurrency(AbstractAmount amount) protected MoneycalculateCharge(Money currentValue, LineItemCharge charge) protected MoneycalculateDiscount(Money currentValue, LineItemDiscount discount) voidRemoves all attached charges of the current line item.voidRemoves all attached discounts of the current line item.Returns the base price of this line item.Returns all charges assigned to this line item.Returns all discounts assigned to this line item.intTells the number of units to be 'for free' meaning that they're excluded from calculation completely.intReturns the regular number of units within that line item.intReturns the number of units that are applicable for calculation.getOrder()Calculates the line item sub total.getTaxes()Returns all taxes which are targeting this line item.Calculates to line item total.Calculates the total of all line item charges.Calculates totals of all line item charges separately.Calculates the total of all line item discounts.Calculates the totals of all line item discounts separately.voidremoveCharge(LineItemCharge charge) Removes a charge from this line item.voidremoveDiscount(LineItemDiscount discount) Removes a single discount from this line item.final voidsetGiveAwayUnits(int giveAwayCount) Changes the number of units to be 'for free' meaning that they're excluded from calculation completely.final voidsetNumberOfUnits(int numberOfUnits) Changes the number of regular units within that line item.voidSets theOrderto for this line item belongs to.toString(){numberOfUnits}x {basePrice} {currency}(free:{giveAwayCount}) discounts:[...] charges:[...]
-
Constructor Details
-
LineItem
Creates a new line item with the given base price and one unit. -
LineItem
Creates a new line item with the given base price and number of units.
-
-
Method Details
-
getTotal
Calculates to line item total. This includes sub total, discounts and charges. -
getSubTotal
Calculates the line item sub total. This is just the bas price multiplied by the number of applicable units (seesetGiveAwayUnits(int)for how some units may be excluded).- See Also:
-
getTotalDiscount
Calculates the total of all line item discounts.- See Also:
-
getTotalCharge
Calculates the total of all line item charges.- See Also:
-
getTotalDiscounts
Calculates the totals of all line item discounts separately.- Returns:
- a map (
LineItemDiscount->Money) - See Also:
-
getTotalCharges
Calculates totals of all line item charges separately.- Returns:
- a map (
LineItemCharge->Money) - See Also:
-
calculateDiscount
-
calculateCharge
-
getNumberOfUnits
public int getNumberOfUnits()Returns the regular number of units within that line item. Please note that some units may be excluded from calculation viasetGiveAwayUnits(int). -
setNumberOfUnits
public final void setNumberOfUnits(int numberOfUnits) Changes the number of regular units within that line item. Please note that some units may be excluded from calculation viasetGiveAwayUnits(int). -
setOrder
Sets theOrderto for this line item belongs to. Is needed for the calculation because all line item must have the same currency (Order.getCurrency()is used to check it). -
getOrder
- Returns:
- the order this line item belongs to. Can be null but no calculation is then possible!
- Throws:
MissingCalculationDataException- if order is null and this method or any calculation method (getTotal...) is called.
-
getBasePrice
Returns the base price of this line item. -
toString
{numberOfUnits}x {basePrice} {currency}(free:{giveAwayCount}) discounts:[...] charges:[...] -
getDiscounts
Returns all discounts assigned to this line item. -
addDiscounts
Adds multiple discounts to this line item.- Throws:
CurrenciesAreNotEqualException- in case at least one discount is absolute and uses a different currency than the enclosing order
-
addDiscounts
Adds multiple discounts to this line item.- Throws:
CurrenciesAreNotEqualException- in case at least one discount is absolute and uses a different currency than the enclosing order
-
addDiscount
Adds a single discount to this line item at a specific position.- Parameters:
index- the position to add the discount at- Throws:
CurrenciesAreNotEqualException- in case at it's a absolute discount and uses a different currency than the enclosing order
-
assertCurrency
-
addDiscount
Adds a single discount to this line item.- Throws:
CurrenciesAreNotEqualException- in case at it's a absolute discount and uses a different currency than the enclosing order
-
clearDiscounts
public void clearDiscounts()Removes all attached discounts of the current line item. -
removeDiscount
Removes a single discount from this line item. -
getCharges
Returns all charges assigned to this line item. -
addCharges
Adds multiple charges to this line item.- Throws:
CurrenciesAreNotEqualException- in case there is at least one absolute charge which uses a different currency than the enclosing order
-
addCharges
Adds multiple charges to this line item.- Throws:
CurrenciesAreNotEqualException- in case there is at least one absolute charge which uses a different currency than the enclosing order
-
addCharge
Adds a single charge to this line item.- Throws:
CurrenciesAreNotEqualException- in case at it's a absolute charge and uses a different currency than the enclosing order
-
addCharge
Adds a single charge to this line item at a specific position.- Parameters:
index- the position to add the charge at- Throws:
CurrenciesAreNotEqualException- in case at it's a absolute charge and uses a different currency than the enclosing order
-
clearCharges
public void clearCharges()Removes all attached charges of the current line item. -
removeCharge
Removes a charge from this line item. -
getNumberOfUnitsForCalculation
public int getNumberOfUnitsForCalculation()Returns the number of units that are applicable for calculation. Basically this isgetNumberOfUnits()-getGiveAwayUnits(). -
getGiveAwayUnits
public int getGiveAwayUnits()Tells the number of units to be 'for free' meaning that they're excluded from calculation completely. In consequence for calculation this line item appears to hold <numberOfUnits> - <giveAwayCount> units. In case the number of give-away units is greater than the actual available number of units the line item appear to have zero units. -
setGiveAwayUnits
public final void setGiveAwayUnits(int giveAwayCount) Changes the number of units to be 'for free' meaning that they're excluded from calculation completely. In consequence for calculation this line item appears to hold <numberOfUnits> - <giveAwayCount> units. In case the number of give-away units is greater than the actual available number of units the line item appear to have zero units. -
getTaxes
Returns all taxes which are targeting this line item.- See Also:
-