Class LineItem
- java.lang.Object
-
- de.hybris.order.calculation.domain.LineItem
-
- All Implemented Interfaces:
Taxable
- Direct Known Subclasses:
NumberedLineItem
public class LineItem extends java.lang.Object implements Taxable
Represents one entry (or element) for anOrder
. Central objects that holds all line items related data required for amount calculation. ALineItem
isTaxable
which meansgetTotal(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 orderedList
ofLineItemDiscount
s andLineItemCharge
s. The line item must use the sameCurrency
as the linkedOrder
or aCurrenciesAreNotEqualException
is thrown.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCharge(int index, LineItemCharge lineItemCharge)
Adds a single charge to this line item at a specific position.void
addCharge(LineItemCharge lineItemCharge)
Adds a single charge to this line item.void
addCharges(LineItemCharge... lineItemCharges)
Adds multiple charges to this line item.void
addCharges(java.util.List<LineItemCharge> lineItemCharges)
Adds multiple charges to this line item.void
addDiscount(int index, LineItemDiscount discount)
Adds a single discount to this line item at a specific position.void
addDiscount(LineItemDiscount discount)
Adds a single discount to this line item.void
addDiscounts(LineItemDiscount... discounts)
Adds multiple discounts to this line item.void
addDiscounts(java.util.List<LineItemDiscount> discounts)
Adds multiple discounts to this line item.protected void
assertCurrency(AbstractAmount amount)
protected Money
calculateCharge(Money currentValue, LineItemCharge charge)
protected Money
calculateDiscount(Money currentValue, LineItemDiscount discount)
void
clearCharges()
Removes all attached charges of the current line item.void
clearDiscounts()
Removes all attached discounts of the current line item.Money
getBasePrice()
Returns the base price of this line item.java.util.List<LineItemCharge>
getCharges()
Returns all charges assigned to this line item.java.util.List<LineItemDiscount>
getDiscounts()
Returns all discounts assigned to this line item.int
getGiveAwayUnits()
Tells the number of units to be 'for free' meaning that they're excluded from calculation completely.int
getNumberOfUnits()
Returns the regular number of units within that line item.int
getNumberOfUnitsForCalculation()
Returns the number of units that are applicable for calculation.Order
getOrder()
Money
getSubTotal()
Calculates the line item sub total.java.util.Collection<Tax>
getTaxes()
Returns all taxes which are targeting this line item.Money
getTotal(Order context)
Calculates to line item total.Money
getTotalCharge()
Calculates the total of all line item charges.java.util.Map<LineItemCharge,Money>
getTotalCharges()
Calculates totals of all line item charges separately.Money
getTotalDiscount()
Calculates the total of all line item discounts.java.util.Map<LineItemDiscount,Money>
getTotalDiscounts()
Calculates the totals of all line item discounts separately.void
removeCharge(LineItemCharge charge)
Removes a charge from this line item.void
removeDiscount(LineItemDiscount discount)
Removes a single discount from this line item.void
setGiveAwayUnits(int giveAwayCount)
Changes the number of units to be 'for free' meaning that they're excluded from calculation completely.void
setNumberOfUnits(int numberOfUnits)
Changes the number of regular units within that line item.void
setOrder(Order order)
Sets theOrder
to for this line item belongs to.java.lang.String
toString()
{numberOfUnits}x {basePrice} {currency}(free:{giveAwayCount}) discounts:[...] charges:[...]
-
-
-
Method Detail
-
getTotal
public Money getTotal(Order context)
Calculates to line item total. This includes sub total, discounts and charges.- Specified by:
getTotal
in interfaceTaxable
- Parameters:
context
- the order within the tax is being calculated- See Also:
getSubTotal()
,getTotalDiscount()
,getTotalCharge()
-
getSubTotal
public Money 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:
getTotal(Order)
-
getTotalDiscount
public Money getTotalDiscount()
Calculates the total of all line item discounts.- See Also:
getTotalDiscounts()
-
getTotalCharge
public Money getTotalCharge()
Calculates the total of all line item charges.- See Also:
getTotalCharges()
-
getTotalDiscounts
public java.util.Map<LineItemDiscount,Money> getTotalDiscounts()
Calculates the totals of all line item discounts separately.- Returns:
- a map (
LineItemDiscount
->Money
) - See Also:
getTotalDiscount()
-
getTotalCharges
public java.util.Map<LineItemCharge,Money> getTotalCharges()
Calculates totals of all line item charges separately.- Returns:
- a map (
LineItemCharge
->Money
) - See Also:
getTotalCharge()
-
calculateDiscount
protected Money calculateDiscount(Money currentValue, LineItemDiscount discount)
-
calculateCharge
protected Money calculateCharge(Money currentValue, LineItemCharge charge)
-
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
public void setOrder(Order order)
Sets theOrder
to 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
public Order 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
public Money getBasePrice()
Returns the base price of this line item.
-
toString
public java.lang.String toString()
{numberOfUnits}x {basePrice} {currency}(free:{giveAwayCount}) discounts:[...] charges:[...]
- Overrides:
toString
in classjava.lang.Object
-
getDiscounts
public java.util.List<LineItemDiscount> getDiscounts()
Returns all discounts assigned to this line item.
-
addDiscounts
public void addDiscounts(LineItemDiscount... discounts)
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
public void addDiscounts(java.util.List<LineItemDiscount> discounts)
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
public void addDiscount(int index, LineItemDiscount discount)
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
protected void assertCurrency(AbstractAmount amount)
-
addDiscount
public void addDiscount(LineItemDiscount discount)
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
public void removeDiscount(LineItemDiscount discount)
Removes a single discount from this line item.
-
getCharges
public java.util.List<LineItemCharge> getCharges()
Returns all charges assigned to this line item.
-
addCharges
public void addCharges(LineItemCharge... lineItemCharges)
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
public void addCharges(java.util.List<LineItemCharge> lineItemCharges)
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
public void addCharge(LineItemCharge lineItemCharge)
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
public void addCharge(int index, LineItemCharge lineItemCharge)
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
public void removeCharge(LineItemCharge charge)
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
public java.util.Collection<Tax> getTaxes()
Returns all taxes which are targeting this line item.- See Also:
Order.getTaxesFor(Taxable)
-
-