Class Order
- java.lang.Object
-
- de.hybris.order.calculation.domain.Order
-
public class Order extends java.lang.Object
Central Object that holds all calculation related data and strategies required for calculating the order/cart. The net/gross mode (seeisNet()
) and the current currency (getCurrency()
) has to be provided during creation. After this pointLineItem
or other objects can be created with a differentCurrency
but when adding it tho the currentOrder
aCurrenciesAreNotEqualException
is thrown. The getTotal...() methods returns the overall calculated Money for the different line item posts or taxes. With get...Values() a map is returned which shows the concrete single amount for each charge/discount/tax.
-
-
Constructor Summary
Constructors Constructor Description Order(Currency currency, boolean isNet, CalculationStrategies calculationStrategies)
Creates a new order calculation object based on a specific currency and bet/gross mode.Order(Currency currency, CalculationStrategies calculationStrategies)
Creates a new gross order calculation object based on a specific currency.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCharge(int index, OrderCharge aoc)
Assigns a single charge to this order at a specific position.void
addCharge(OrderCharge aoc)
Assigns a single charge to this order.void
addCharges(OrderCharge... charges)
Assigns multiple charges to this order.void
addCharges(java.util.List<OrderCharge> charges)
Assigns multiple charges to this order.void
addDiscount(int index, OrderDiscount discount)
Assigns a discount to this order at a speific position.void
addDiscount(OrderDiscount discount)
Assigns a discount to this order.void
addDiscounts(OrderDiscount... discounts)
Assigns multiple discounts to this order.void
addDiscounts(java.util.List<OrderDiscount> discounts)
Assigns multiple discounts to this order.void
addLineItem(int index, LineItem lineitem)
Attaches a line items to this order at the specified position.void
addLineItem(LineItem lineitem)
Attaches a line items to this order.void
addLineItems(LineItem... lineItems)
Attaches multiple line items to this order.void
addLineItems(java.util.List<LineItem> lineItems)
Attaches multiple line items to this order.void
addTax(Tax tax)
Assigns a tax to this order.void
addTaxes(Tax... taxes)
Assigns multiple taxes to this order.void
addTaxes(java.util.Collection<Tax> taxes)
Assigns multiple taxes to this order.protected Money
calculateOrderCharge(Money currentValue, OrderCharge addCharge)
protected Money
calculateOrderDiscount(Money currentValue, OrderDiscount discount)
Calculates order discountprotected Money
calculateTaxTotal(Tax tax, double autoTaxCorrectionFactor)
void
clearCharges()
Removes all assigned charges from this order.void
clearDiscounts()
Removes all assigned discounts from this order.void
clearLineItems()
Removes all attached line items.void
clearTaxes()
Removes all attached taxes from this order.protected double
getAutomaticTaxCorrectionFactor()
CalculationStrategies
getCalculationStrategies()
Delegate to all necessary strategies.java.util.List<OrderCharge>
getCharges()
Returns all charges assigned to this order.Currency
getCurrency()
Returns the currency which this order is being calculated for.java.util.List<OrderDiscount>
getDiscounts()
Returns all discounts attached to this order.protected Money
getFixedTaxedAdditionalCharges(java.util.Map<OrderCharge,Money> aocValues)
java.util.List<LineItem>
getLineItems()
Returns all line items attached to this order.Money
getSubTotal()
Calculates the sum of all line item totals (LineItem.getTotal(Order)
).java.util.Collection<Tax>
getTaxes()
Returns all taxes assigned to this order.java.util.Collection<Tax>
getTaxesFor(Taxable object)
Money
getTotal()
Calculates the order total.Money
getTotalCharge()
Calculates the total of all charges which apply to the order at a whole.Money
getTotalChargeOfType(AbstractCharge.ChargeType chargeType)
Calculates the total of all charges of one specific type which apply to the order at a whole.java.util.Map<OrderCharge,Money>
getTotalCharges()
Calculates totals of all charges assigned to this order separately.Money
getTotalDiscount()
Calculates the total of all discounts assigned to this order.java.util.Map<OrderDiscount,Money>
getTotalDiscounts()
Calculates totals of all discounts assigned to this order separately.Money
getTotalIncludingTaxes()
Calculates the order total always including taxes.Money
getTotalTax()
Returns the overall sum of taxes within this order.java.util.Map<Tax,Money>
getTotalTaxes()
Calculates total taxes for all assignedTax
object.Money
getTotalTaxFor(Tax tax)
Calculates the total tax for a specificTax
object.boolean
hasAssignedTaxes(Taxable object)
boolean
hasCharges()
Tells whether this order has got assigned charges or not.boolean
hasDisounts()
Tells whether this order has got assigned discounts or not.boolean
hasLineItems()
Tells whether or not this order has got line items.boolean
hasTaxes()
Tells whether this order has got assigned taxes or not.boolean
isGross()
boolean
isNet()
void
removeCharge(OrderCharge aoc)
Removes a charge from this order.void
removeDiscount(OrderDiscount orderDiscount)
Removes a discount from this order.void
removeLineItem(LineItem lineitem)
Removes a single line item.void
removeTax(Tax tax)
Removes the given tax from this order.
-
-
-
Constructor Detail
-
Order
public Order(Currency currency, CalculationStrategies calculationStrategies)
Creates a new gross order calculation object based on a specific currency.- Parameters:
currency
- the currency the whole calculation will be incalculationStrategies
- some strategies
-
Order
public Order(Currency currency, boolean isNet, CalculationStrategies calculationStrategies)
Creates a new order calculation object based on a specific currency and bet/gross mode.- Parameters:
currency
- the currency the whole calculation will be inisNet
- true for net, false for gross modecalculationStrategies
- some strategies
-
-
Method Detail
-
getTotal
public Money getTotal()
Calculates the order total. Depending on the net/gross status of this order that total is either net or gross. Please know thatgetTotalIncludingTaxes()
will always return the gross total for both modes.
-
getSubTotal
public Money getSubTotal()
Calculates the sum of all line item totals (LineItem.getTotal(Order)
).- See Also:
getTotal()
-
getTotalTaxFor
public Money getTotalTaxFor(Tax tax)
Calculates the total tax for a specificTax
object.
-
getTotalTaxes
public java.util.Map<Tax,Money> getTotalTaxes()
Calculates total taxes for all assignedTax
object.
-
getAutomaticTaxCorrectionFactor
protected double getAutomaticTaxCorrectionFactor()
-
getFixedTaxedAdditionalCharges
protected Money getFixedTaxedAdditionalCharges(java.util.Map<OrderCharge,Money> aocValues)
-
getTaxesFor
public java.util.Collection<Tax> getTaxesFor(Taxable object)
- Returns:
- the assigned taxes or an empty collection
-
hasAssignedTaxes
public boolean hasAssignedTaxes(Taxable object)
-
getTotalTax
public Money getTotalTax()
Returns the overall sum of taxes within this order. To get the exact money for each tax please usegetTotalTaxes()
.- See Also:
getTotalTaxes()
-
getTotalCharge
public Money getTotalCharge()
Calculates the total of all charges which apply to the order at a whole. Please note that line item charges are not included here since they are already part of the line item total!
-
getTotalChargeOfType
public Money getTotalChargeOfType(AbstractCharge.ChargeType chargeType)
Calculates the total of all charges of one specific type which apply to the order at a whole. Please note that line item charges are not included here since they are already part of the line item total!- Parameters:
chargeType
- the type of charge to select- See Also:
getTotalCharge()
,getTotalCharges()
-
getTotalDiscount
public Money getTotalDiscount()
Calculates the total of all discounts assigned to this order. Please note that this does not include line item discounts since they are already included in line item totals!- See Also:
getTotalDiscounts()
-
getTotalCharges
public java.util.Map<OrderCharge,Money> getTotalCharges()
Calculates totals of all charges assigned to this order separately.- Returns:
- a map (
OrderCharge
->Money
)
-
getTotalDiscounts
public java.util.Map<OrderDiscount,Money> getTotalDiscounts()
Calculates totals of all discounts assigned to this order separately.- Returns:
- a map (
OrderDiscount
->Money
)
-
calculateOrderCharge
protected Money calculateOrderCharge(Money currentValue, OrderCharge addCharge)
-
calculateOrderDiscount
protected Money calculateOrderDiscount(Money currentValue, OrderDiscount discount)
Calculates order discount- Parameters:
currentValue
-discount
-- Returns:
- money
- Throws:
CurrenciesAreNotEqualException
MissingCalculationDataException
-
getTotalIncludingTaxes
public Money getTotalIncludingTaxes()
Calculates the order total always including taxes. This makes most sense in case of this order being in net mode whengetTotal()
will show order total without taxes only.
-
getLineItems
public java.util.List<LineItem> getLineItems()
Returns all line items attached to this order.
-
addLineItems
public void addLineItems(LineItem... lineItems)
Attaches multiple line items to this order. Please note that each line item will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case at least one line item has got a base price of different currency than the order currency
-
addLineItems
public void addLineItems(java.util.List<LineItem> lineItems)
Attaches multiple line items to this order. Please note that each line item will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case at least one line item has got a base price of different currency than the order currency
-
addLineItem
public void addLineItem(LineItem lineitem)
Attaches a line items to this order. Please note that the line item will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case the line item has got a base price of different currency than the order currency
-
addLineItem
public void addLineItem(int index, LineItem lineitem)
Attaches a line items to this order at the specified position. Please note that the line item will receive a back reference to this order.- Parameters:
index
- insert the given line item into this position.lineitem
- the line item to be added- Throws:
CurrenciesAreNotEqualException
- in case the line item has got a base price of different currency than the order currency
-
clearLineItems
public void clearLineItems()
Removes all attached line items. Please note that these line items also lose their back reference to this order.
-
removeLineItem
public void removeLineItem(LineItem lineitem)
Removes a single line item. Please note that the line items also lose its back reference to this order.
-
getTaxes
public java.util.Collection<Tax> getTaxes()
Returns all taxes assigned to this order.
-
addTaxes
public void addTaxes(Tax... taxes)
Assigns multiple taxes to this order. Please note that each tax receives a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case there is at least one absolute tax having a different currency than the one of this order
-
addTaxes
public void addTaxes(java.util.Collection<Tax> taxes)
Assigns multiple taxes to this order. Please note that each tax receives a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case there is at least one absolute tax having a different currency than the one of this order
-
addTax
public void addTax(Tax tax)
Assigns a tax to this order. Please note that the tax receives a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case it's a absolute tax having a different currency than the one of this order
-
clearTaxes
public void clearTaxes()
Removes all attached taxes from this order. Please note that all back references to this order are cleared.
-
removeTax
public void removeTax(Tax tax)
Removes the given tax from this order.
-
getDiscounts
public java.util.List<OrderDiscount> getDiscounts()
Returns all discounts attached to this order.
-
addDiscounts
public void addDiscounts(OrderDiscount... discounts)
Assigns multiple discounts to this order. Please note that the discounts will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case there is at least one absolute discount having a different currency than the one of this order
-
addDiscounts
public void addDiscounts(java.util.List<OrderDiscount> discounts)
Assigns multiple discounts to this order. Please note that the discounts will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case there is at least one absolute discount having a different currency than the one of this order
-
addDiscount
public void addDiscount(OrderDiscount discount)
Assigns a discount to this order. Please note that the discount will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case it's a absolute discount having a different currency than the one of this order
-
addDiscount
public void addDiscount(int index, OrderDiscount discount)
Assigns a discount to this order at a speific position. Please note that the discount will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case it's a absolute discount having a different currency than the one of this order
-
clearDiscounts
public void clearDiscounts()
Removes all assigned discounts from this order. Please note that all back reference to this order are also cleared.
-
removeDiscount
public void removeDiscount(OrderDiscount orderDiscount)
Removes a discount from this order. Please note that the back reference to this order isalso cleared.
-
getCharges
public java.util.List<OrderCharge> getCharges()
Returns all charges assigned to this order.
-
addCharges
public void addCharges(OrderCharge... charges)
Assigns multiple charges to this order. Please note that each one will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case at least one absolute charge is using a different currency than the one used for this order
-
addCharges
public void addCharges(java.util.List<OrderCharge> charges)
Assigns multiple charges to this order. Please note that each one will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case at least one absolute charge is using a different currency than the one used for this order
-
addCharge
public void addCharge(OrderCharge aoc)
Assigns a single charge to this order. Please note that it will receive a back reference to this order.- Throws:
CurrenciesAreNotEqualException
- in case it's a absolute charge using a different currency than the one used for this order
-
addCharge
public void addCharge(int index, OrderCharge aoc)
Assigns a single charge to this order at a specific position. Please note that it will receive a back reference to this order.- Parameters:
index
- the position to add the charge at- Throws:
CurrenciesAreNotEqualException
- in case it's a absolute charge using a different currency than the one used for this order
-
clearCharges
public void clearCharges()
Removes all assigned charges from this order. Please note that all back references are cleared as well.
-
removeCharge
public void removeCharge(OrderCharge aoc)
Removes a charge from this order. Please note that the back reference is cleared as well.
-
hasLineItems
public boolean hasLineItems()
Tells whether or not this order has got line items.
-
hasCharges
public boolean hasCharges()
Tells whether this order has got assigned charges or not.
-
hasDisounts
public boolean hasDisounts()
Tells whether this order has got assigned discounts or not.
-
hasTaxes
public boolean hasTaxes()
Tells whether this order has got assigned taxes or not.
-
isNet
public boolean isNet()
- Returns:
- true if this order is in net mode, returns false if the order is in gross mode.
-
isGross
public boolean isGross()
- Returns:
- false if this order is in net mode, returns true if the order is in gross mode.
-
getCalculationStrategies
public CalculationStrategies getCalculationStrategies()
Delegate to all necessary strategies.
-
getCurrency
public Currency getCurrency()
Returns the currency which this order is being calculated for.
-
-