- Home /

Hi,

I am trying to rename a LineItem discount that I added to a LineItem using OrderConnector.addLineItemDiscount() Is there any way of doing it other than calling OrderConnector.deleteLineItemDiscounts() and then re-adding the line item discount? I was trying something like this but I kept getting a ClientException. Assume that there is only one item in the current order:

`Order order = mOrderConnector.getOrder(currentOrderId);`

` `

List<LineItem> lineItems = order.getLineItems();

if(lineItems != null && lineItems.size() > 0) {

```
LineItem lineItem = lineItems.get(0); // reference to the only item in the order
Discount discount = new Discount();
discount.setAmount(-100L);
discount.setName("Test Discount");
order = mOrderConnector.addLineItemDiscount(currentOrderId, lineItem.getId(), discount); // this works ok
List<LineItem> updatedLineItems = order.getLineItems();
for(LineItem updatedLineItem : updatedLineItems) {
if(updatedLineItem.hasDiscounts()) {
for(Discount updatedDiscount : updatedLineItem.getDiscounts();
updatedDiscount.setName("New Discount"); // this renames the discount from "Test Discount" to "New Discount"
}
}
}
```

`mOrderConnector.updateLineItems(currentOrderId, lineItems); // causes ClientException } `

Perhaps this is not the intended use for the updateLineItems() method? Any help would be appreciated.

Thanks,

Steve

Comment

Follow
### Follow this Question

how to change discount amount 0 Answers

Apply Equal Discount on Multiple LineItems. 0 Answers

Is LineItem.getDiscountAmount() implemented ? 1 Answer

how to calculate exact discount in clover. 0 Answers

Adding a Modifier to a LineItem Via SDK 2 Answers

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