- Home /

Hi, I have a reference to a LineItem and it returns a List<discount> when I call getDiscounts() on it. However when I call getDiscountAmount() on the same valid reference I get a NullPointerException. The description of this method in the JavaDocs is: "does the calculated flag actually do anything?" which gives the impression that the method is not implemented and is probably just throwing a NullPointerException. Could anyone verify if this is the case?

Thanks, Steve

Comment

**Answer** by Jacob Abrams
·
Jan 31, 2016 at 06:42 PM

Yes the `getDiscountAmount()`

method is not implemented, it should be removed. What exactly are you looking for? A line item can have many discounts, there are also modifications and order level discounts that apply to all line items. If you want to compute the overall discount amount including order level discounts we have some provided functionality that can help. Here is some sample code:

```
OrderCalc calc = new OrderCalc(order);
Collection<LineItem> lineItem = Collections.singletonList(order.getLineItems().get(0));
Price itemSubtotal = new Price(calc.getLineSubtotal(lineItem));
Price itemSubtotalWithoutDiscounts = new Price(calc.getLineSubtotalWithoutDiscounts(lineItem));
Price lineItemComputedDiscountAmount = itemSubtotalWithoutDiscounts.subtract(itemSubtotal);
```

If you want to compute the line item discount amount excluding the order level discounts you will need to calculate that yourself using the discount values provided in the LineItem.

Thanks jacobabrams,

As you guessed I was trying to compute the line item discount amount excluding the order level discounts. I managed to get that working correctly. Thanks for the sample code - it will be useful for my next task.

Steve

Follow
### Follow this Question

How to rename a LineItem Discount ? 0 Answers

how to calculate exact discount in clover. 0 Answers

how to change discount amount 0 Answers

Apply Discount in android 1 Answer

How to apply discount via Rest API? 1 Answer

Copyright © 2010-16 DZone, Inc. - All rights reserved.

- Anonymous
- Sign in
- Create
- Ask a question
- Create an article
- Spaces
- Help
- Explore
- Topics
- Questions
- Users
- Badges