Class AbstractOrderEntry

All Implemented Interfaces:
Serializable, Comparable
Direct Known Subclasses:
GeneratedCartEntry, GeneratedOrderEntry, GeneratedQuoteEntry

public abstract class AbstractOrderEntry extends GeneratedAbstractOrderEntry

This is a general superclass for all order entries, which describes an ordered (or sold) product amount.

Besides essential information like the product, the amount and unit these object also may contain pricing information. So base and total price are stored here as well as applied taxes ( as TaxValue objects ) and discounts (as DiscountValue objects).

Like AbstractOrder an entry does not have this information from the beginning but must be calculated. Since each entry belongs to an order its calculation status is set by its order if necessary.

As price calculation is done by the installed price factory you should refer to its specific documentation how calculation for entries is done and if some behaviour differ from the descriptions stated here. Generally entry calculation is covered by these PriceFactory methods: PriceFactory.getBasePrice(AbstractOrderEntry), PriceFactory.getDiscountValues(AbstractOrderEntry) and PriceFactory.getTaxValues(AbstractOrderEntry).

See Also:
  • Field Details

  • Constructor Details

    • AbstractOrderEntry

      public AbstractOrderEntry()
  • Method Details

    • createItem

      protected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
      Description copied from class: Item
      Has to be implemented for each concrete subtype of item. This method is responsible for creating a new item instance ( by calling managers, ejb homes, etc. ) during ComposedType.newInstance(Map).

      In case this method uses any of the attribute values during creation it is required to override Item.getNonInitialAttributes(SessionContext, ItemAttributeMap) too.
      Sn example:

      
       public static final String MY_ATTRIBUTE = "someAttribute"; ... protected Item createItem(SessionContext
       ctx, ComposedType type, Map allAttributes ) throws JaloBusinessException { MyManager man = ... return
       man.createMyItem( (String)allAttributes.get(MY_ATTRIBUTE) );
       // here MY_ATTRIBUTE is used for creation, so it must not be set again } protected Map getNonInitialAttributes(
       SessionContext ctx, Map allAttributes ) { // let superclass remove its own initial attributes Map ret =
       super.getNonInitialAttributes( ctx, allAttributes );
       // remove MY_ATTRIBUTE from all attributes since if has already been set ret.remove(MY_ATTRIBUTE); return ret; }
      
       
      Overrides:
      createItem in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - the current session context which this item is created within
      type - the actual item type ( since subtypes may not provide a own jalo class this may be different from the type which this method was implemented for )
      Returns:
      the new item instance
      Throws:
      JaloBusinessException - indicates an error during creation - any changes will be rollbacked
    • remove

      public void remove(SessionContext ctx) throws ConsistencyCheckException
      This method delegates to AbstractOrder.removeEntry(AbstractOrderEntry) instead of removing the item directly.
      Overrides:
      remove in class Item
      Parameters:
      ctx - A SessionContext object
      Throws:
      ConsistencyCheckException - if this item could not be removed for some reason
    • removeWithoutOrderNotification

      protected void removeWithoutOrderNotification(SessionContext ctx) throws ConsistencyCheckException
      Removes the entry directly without notifying the enclosing AbstractOrder. Use with care since the enclosing order is not marked as changed so that incorrect prices may be shown!
      Parameters:
      ctx -
      Throws:
      ConsistencyCheckException
    • getOrder

      public AbstractOrder getOrder(SessionContext ctx)
      This entrys order.
      Overrides:
      getOrder in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - can be used for cached access object may be outdated!
      Returns:
      the AbstractOrder this abstract order entry is associated to
    • setOrder

      public void setOrder(SessionContext ctx, AbstractOrder value)
      Description copied from class: GeneratedAbstractOrderEntry
      Generated method - Setter of the AbstractOrderEntry.order attribute.
      Overrides:
      setOrder in class GeneratedAbstractOrderEntry
      value - the order
    • setProduct

      public void setProduct(SessionContext ctx, Product product)
      Changes the ordered product. Please note that this resets the entry in the 'uncalculated' status since price information cannot be valid any more.
      Overrides:
      setProduct in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - can be used for cached access object may be outdated!
      product -
    • setQuantity

      public void setQuantity(SessionContext ctx, Long qtd)
      Changes the number of ordered products. Please note that this resets the entry in the 'uncalculated' status since price information cannot be valid any more.
      Overrides:
      setQuantity in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - can be used for cached access value may be outdated!
      qtd -
    • setUnit

      public void setUnit(SessionContext ctx, Unit unit)
      Changes the unit of the ordered amount. Please note that this resets the entry in the 'uncalculated' status since prices might also depend on units.
      Overrides:
      setUnit in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - can be used for cached access object may be outdated!
      unit -
    • setBasePrice

      public void setBasePrice(SessionContext ctx, Double price)
      Sets the calculated base price for this entry.
      Overrides:
      setBasePrice in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - the session context
      price - the new base price
    • getTaxValues

      @Deprecated(since="ages", forRemoval=false) public Collection getTaxValues()
      Deprecated.
      since ages - Use AbstractOrderEntryModel.getTaxValues() instead.
      The collection of this entry's taxes. These are relative TaxValues which means they dont include real prices but only the tax rate. Please note that during order calculation these tax values are calculated by the current price factory.
      Returns:
      a collection containing all TaxValue objects which are applied on this entry
      Throws:
      JaloNotYetCalculatedException - if this order entry was not yet calculated.
    • getTaxValues

      @Deprecated(since="ages", forRemoval=false) public Collection getTaxValues(SessionContext ctx)
      Deprecated.
      since ages - Use AbstractOrderEntryModel.getTaxValues() instead.
      The collection of this entry's taxes. These are relative TaxValues which means they dont include real prices but only the tax rate. Please note that during order calculation these tax values are calculated by the current price factory.
      Parameters:
      ctx - can be used for cached access values may be outdated!
      Returns:
      a collection containing all TaxValue objects which are applied on this entry
      Throws:
      JaloNotYetCalculatedException - if this order entry was not yet calculated.
    • setTaxValues

      @Deprecated(since="ages", forRemoval=false) public void setTaxValues(Collection collection)
      Deprecated.
      since ages - Use AbstractOrderEntryModel.setTaxValues(Collection) instead.
      discards all present tax values and adds the given values.
      Parameters:
      collection - the new tax values
    • setTaxValues

      @Deprecated(since="ages", forRemoval=false) public void setTaxValues(SessionContext ctx, Collection collection)
      Deprecated.
      since ages - Use AbstractOrderEntryModel.setTaxValues(Collection) instead.
      discards all present tax values and adds the given values.
      Parameters:
      collection - the new tax values
    • addTaxValue

      @Deprecated(since="ages", forRemoval=false) public void addTaxValue(TaxValue taxValue)
      Deprecated.
      since ages - Use OrderEntryService.addTaxValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, TaxValue) instead.
      Adds a new tax into this entry
      Parameters:
      taxValue -
    • addTaxValue

      @Deprecated(since="ages", forRemoval=false) public void addTaxValue(SessionContext ctx, TaxValue taxValue)
      Deprecated.
      since ages - Use OrderEntryService.addTaxValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, TaxValue) instead.
      Adds a new tax into this entry
      Parameters:
      ctx -
      taxValue -
    • addAllTaxValues

      @Deprecated(since="ages", forRemoval=false) public void addAllTaxValues(Collection values)
      Deprecated.
      since ages - Use OrderEntryService.addAllTaxValues(de.hybris.platform.core.model.order.AbstractOrderEntryModel, List) instead.
      Adds a collection of taxes into this entry
      Parameters:
      values -
    • addAllTaxValues

      @Deprecated(since="ages", forRemoval=false) public void addAllTaxValues(SessionContext ctx, Collection values)
      Deprecated.
      since ages - Use OrderEntryService.addAllTaxValues(de.hybris.platform.core.model.order.AbstractOrderEntryModel, List) instead.
      Adds a collection of taxes into this entry
      Parameters:
      ctx -
      values -
    • removeTaxValue

      @Deprecated(since="ages", forRemoval=false) public void removeTaxValue(TaxValue taxValue)
      Deprecated.
      since ages - Use OrderEntryService.removeTaxValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, TaxValue) instead.
      Removes a new tax out of this entry
      Parameters:
      taxValue -
    • removeTaxValue

      @Deprecated(since="ages", forRemoval=false) public void removeTaxValue(SessionContext ctx, TaxValue taxValue)
      Deprecated.
      since ages - Use OrderEntryService.removeTaxValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, TaxValue) instead.
      Removes a new tax out of this entry
      Parameters:
      ctx -
      taxValue -
    • removeAllTaxValues

      @Deprecated(since="ages", forRemoval=false) public void removeAllTaxValues()
      Deprecated.
      since ages - Use AbstractOrderEntryModel.setTaxValues(Collection) and ModelService.save() instead. In order to remove all taxes, use null in the setter.
      Removes all taxes of this entry
    • removeAllTaxValues

      @Deprecated(since="ages", forRemoval=false) public void removeAllTaxValues(SessionContext ctx)
      Deprecated.
      since ages - Use AbstractOrderEntryModel.setTaxValues(Collection) and ModelService.save() instead. In order to remove all taxes, use null in the setter.
      Removes all taxes of this entry
      Parameters:
      ctx - the session context
    • getDiscountValues

      @Deprecated(since="ages", forRemoval=false) public List getDiscountValues()
      Deprecated.
      since ages - Use AbstractOrderEntryModel.getDiscountValues() instead.
      The list of this entry's discount values. In contrary to taxes these values contain "real" prices since all discounts directly apply to this entry ( otherwise they're global discounts and are not applied here). Since this may include absolute discounts the ordering of values is important for correct presentation of this entry, so we chose a List as collection format. Please note that during order calculation these discount values are calculated by the current price factory.
      Returns:
      a list of all DiscountValue objects which are applied on this entry
      Throws:
      JaloNotYetCalculatedException - if this order entry was not yet calculated.
    • getDiscountValues

      @Deprecated(since="ages", forRemoval=false) public List getDiscountValues(SessionContext ctx)
      Deprecated.
      since ages - Use AbstractOrderEntryModel.getDiscountValues() instead.
      The list of this entry's discount values. In contrary to taxes these values contain "real" prices since all discounts directly apply to this entry ( otherwise they're global discounts and are not applied here). Since this may include absolute discounts the ordering of values is important for correct presentation of this entry, so we chose a List as collection format. Please note that during order calculation these discount values are calculated by the current price factory.
      Parameters:
      ctx - can be used for cached access values may be outdated!
      Returns:
      a list of all DiscountValue objects which are applied on this entry
      Throws:
      JaloNotYetCalculatedException - if this order entry was not yet calculated.
    • setDiscountValues

      @Deprecated(since="ages", forRemoval=false) public void setDiscountValues(SessionContext ctx, List discountValues)
      Deprecated.
      since ages - Use AbstractOrderEntryModel.setDiscountValues(List) and ModelService.save() method instead.
      discards all present discount values and adds the given values.
      Parameters:
      discountValues - the new values
    • setDiscountValues

      public void setDiscountValues(List discountValues)
    • addDiscountValue

      @Deprecated(since="ages", forRemoval=false) public void addDiscountValue(DiscountValue discountValue)
      Deprecated.
      since ages - Use OrderEntryService.addDiscountValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, DiscountValue) instead.
      Adds a new discount into this entry
      Parameters:
      discountValue -
    • addDiscountValue

      @Deprecated(since="ages", forRemoval=false) public void addDiscountValue(SessionContext ctx, DiscountValue discountValue)
      Deprecated.
      since ages - Use OrderEntryService.addDiscountValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, DiscountValue) instead.
      Adds a new discount into this entry
      Parameters:
      ctx -
      discountValue -
    • addAllDisocuntValues

      @Deprecated(since="ages", forRemoval=false) public void addAllDisocuntValues(List values)
      Deprecated.
      since ages - UseaddAllDiscountValues(List) instead
      Adds a collection of discounts into this entry
      Parameters:
      values -
    • addAllDiscountValues

      @Deprecated(since="ages", forRemoval=false) public void addAllDiscountValues(List values)
      Deprecated.
      since ages - Use OrderEntryService.addAllDiscountValues(de.hybris.platform.core.model.order.AbstractOrderEntryModel, List) instead.
      Adds a collection of discounts into this entry
      Parameters:
      values -
    • addAllDiscountValues

      @Deprecated(since="ages", forRemoval=false) public void addAllDiscountValues(SessionContext ctx, List values)
      Deprecated.
      since ages - Use OrderEntryService.addAllDiscountValues(de.hybris.platform.core.model.order.AbstractOrderEntryModel, List) instead.
      Adds a collection of discounts into this entry
      Parameters:
      ctx -
      values -
    • removeDiscountValue

      @Deprecated(since="ages", forRemoval=false) public void removeDiscountValue(DiscountValue discountValue)
      Deprecated.
      since ages - Use OrderEntryService.removeDiscountValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, DiscountValue) instead.
      Removes a new discount out of this entry
      Parameters:
      discountValue -
    • removeDiscountValue

      @Deprecated(since="ages", forRemoval=false) public void removeDiscountValue(SessionContext ctx, DiscountValue discountValue)
      Deprecated.
      since ages - Use OrderEntryService.removeDiscountValue(de.hybris.platform.core.model.order.AbstractOrderEntryModel, DiscountValue) instead.
      Removes a new discount out of this entry
      Parameters:
      ctx -
      discountValue -
    • removeAllDiscountValues

      @Deprecated(since="ages", forRemoval=false) public void removeAllDiscountValues()
      Deprecated.
      since ages - Use AbstractOrderEntryModel.setDiscountValues(List) and ModelService.save() method instead. In order to remove all discounts, simply use null as setter argument.
      Removes all discounts of this entry
    • removeAllDiscountValues

      @Deprecated(since="ages", forRemoval=false) public void removeAllDiscountValues(SessionContext ctx)
      Deprecated.
      since ages - Use AbstractOrderEntryModel.setDiscountValues(List) and ModelService.save() method instead. In order to remove all discounts, simply use null as setter argument.
      Removes all discounts of this entry
      Parameters:
      ctx - the session context
    • isCalculated

      public Boolean isCalculated(SessionContext ctx)
      Shows if this entry was calculated before. Please note that all calculated fields are only valid if this method returns true .
      Overrides:
      isCalculated in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - can be used for cached access value may be outdated!
      Returns:
      true if this entry is calculated
    • isGiveAway

      public Boolean isGiveAway(SessionContext ctx)
      Shows if this entry will be treated as a give away (that is, for free).
      Overrides:
      isGiveAway in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - can be used for cached access value may be outdated!
      Returns:
      true if this entry is calculated
    • setGiveAway

      public void setGiveAway(SessionContext ctx, Boolean giveaway)
      Description copied from class: GeneratedAbstractOrderEntry
      Generated method - Setter of the AbstractOrderEntry.giveAway attribute.
      Overrides:
      setGiveAway in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - the session context
      giveaway - the giveaway flag
    • isRejected

      public Boolean isRejected(SessionContext ctx)
      Shows if the GIVEAWAY flag of this entry will be ignored.
      Overrides:
      isRejected in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - can be used for cached access value may be outdated!
      Returns:
      true the rejected flag
    • setRejected

      public void setRejected(SessionContext ctx, Boolean rejected)
      Description copied from class: GeneratedAbstractOrderEntry
      Generated method - Setter of the AbstractOrderEntry.rejected attribute.
      Overrides:
      setRejected in class GeneratedAbstractOrderEntry
      Parameters:
      ctx - the session context
      rejected - the rejected flag
    • calculate

      @Deprecated(since="ages", forRemoval=false) public void calculate() throws JaloPriceFactoryException
      Deprecated.
      since ages - Use CalculationService.calculate(de.hybris.platform.core.model.order.AbstractOrderEntryModel) intsead.
      Calculates this entry if the entry is not calculated yet. This includes finding the correct base price, taxes and discount using the currently installed price factory.

      If prices should be left as currently set but the entry totals have to be consolidated (e.g. when the quantity has changed) call calculateTotals(boolean) instead !

      Throws:
      JaloPriceFactoryException - if no price could be found or other price factory errors occurred.
    • recalculate

      @Deprecated(since="ages", forRemoval=false) public void recalculate() throws JaloPriceFactoryException
      Deprecated.
      since ages - Use CalculationService.recalculate(de.hybris.platform.core.model.order.AbstractOrderEntryModel) instead.
      Calculates this entry even if the entry was calculated before. This includes finding the correct base price, taxes and discount using the currently installed price factory.

      If prices should be left as currently set but the entry totals have to be consolidated (e.g. when the quantity has changed) call calculateTotals(boolean) instead !

      Throws:
      JaloPriceFactoryException - if no price could be found or other price factory errors occurred.
    • setEntryNumber

      public void setEntryNumber(SessionContext ctx, Integer number)
      Sets the entry number. This number affects the position of this entry within the collection obtainable via AbstractOrder.getAllEntries() which is ordered by entry numbers.
      Overrides:
      setEntryNumber in class GeneratedAbstractOrderEntry
      Parameters:
      number - the new entry number
    • setEntryNumberDirect

      protected void setEntryNumberDirect(int number)
      Changes entry number directly.
      Parameters:
      number - the new entry number
    • resetAllValues

      protected void resetAllValues() throws JaloPriceFactoryException
      This tries to get base price, taxes and discounts and sets these values including converting the base price if necessary. Please note that this doesnt change this entry's total. You have to call calculateTotals(boolean) to do so.
      Throws:
      JaloPriceFactoryException
    • findPrice

      protected PriceValue findPrice() throws JaloPriceFactoryException
      Finds a price for this entry. as default this just calls AbstractPriceFactory.getBasePrice(AbstractOrderEntry) but you may override this four your own (non-pricefactory) logic.

      The returned price value does not need to have the net/gross state of this order nor does it have to have the same currency as this entry's order.

      Returns:
      a price value - null is not allowed
      Throws:
      JaloPriceFactoryException - on pricefactory errors
    • findTaxes

      protected Collection findTaxes() throws JaloPriceFactoryException
      Finds tax values for this entry. as default this just calls AbstractPriceFactory.getTaxValues(AbstractOrderEntry) but you may override this four your own (non-pricefactory) logic.

      The returned tax values are converted into applied tax values after the price was found.

      Returns:
      a collection of TaxValue
      Throws:
      JaloPriceFactoryException - on pricefactory errors
    • findDiscounts

      protected List findDiscounts() throws JaloPriceFactoryException
      Ffinds tax values for this entry. as default this just calls AbstractPriceFactory.getDiscountValues(AbstractOrderEntry) but you may override this four your own (non-pricefactory) logic.

      The returned discount values are converted into applied tax values after the price was found.

      Returns:
      a collection of DiscountValue
      Throws:
      JaloPriceFactoryException - on pricefactory errors
    • calculateTotals

      @Deprecated(since="ages", forRemoval=false) public void calculateTotals(boolean recalculate)
      Deprecated.
      since ages - Use CalculationService.calculateTotals(de.hybris.platform.core.model.order.AbstractOrderEntryModel, boolean) instead
      Recalculates this entries total prices and re-applies tax and discount values. This does not include finding price, taxes or discount but uses all currently set values.
      Parameters:
      recalculate - forces the recalculation of the abstract order entry.
    • applyDiscounts

      protected double applyDiscounts(double totalWithoutDiscounts)
      Applies the discount values of this order entry to the given total value. The calculation algorithm is:

          value = given total value
              for each DiscountValue dv
          {
                      if dv is absolute
                              subtract from value the value of dv
             else
                              subtract from value ( the value of dv * value / 100 )
          }
          round value to order currency
       
      Parameters:
      totalWithoutDiscounts -
      Returns:
      the total minus all discounts
    • toString

      public String toString()
      Description copied from class: Item
      Returns the String representation of this item. This is by default the representation of the primary key of this item.
      Overrides:
      toString in class Item
      Returns:
      the String representation of this item.
    • compareTo

      public int compareTo(Object order)
      AbstractOrderEntries are compared by entry number.
      Specified by:
      compareTo in interface Comparable
      Overrides:
      compareTo in class Item
      Parameters:
      order - the abstract order entry, which should be compared with this abstract order entry
      Returns:
      an int value calculated by subtracting the entry number of the argument abstract order entry from the entry number of this abstract order entry.
    • setChanged

      protected void setChanged()