question

jollyraiyani avatar image
jollyraiyani asked Dan commented

Update LineItems in Order ?

Hello,
I want to update line item price in sale order, I m try following code but it gives me "com.clover.sdk.v1.ClientException: status code: 400 cannot update one or more of these fields" this kind of error also try v3 api with parameter in that response received but no changes are received

List<LineItem> lineItems = curOrder.getLineItems();
LineItem lineItem = lineItems.get(0);
lineItem.setId(lineItemId);
lineItem.setPrice(4000);
orderConnector.updateLineItems(orderID,lineItems);
orderConnector.updateOrder(curOrder);
OrdersLineItems
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dan avatar image
Dan answered Dan edited
Changing the line item id is prohibited. That should be what is happening here. I would be able to confirm with a more complete example and the full exception message, but that is pretty clearly the problem.

Update: calling lineItem.setId(lineItemId); is presumably the problem, even if the id that is being set is the same id. Calling lineItem.resetChangeLog() after setting the id would get around this, but this would need to be done with care, as you also would lose any changes made to other fields prior to calling resetChangeLog(). The change log is used by the system to determine which fields have been modified, and any field that is not in the change log may be ignored.
4 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jollyraiyani avatar image jollyraiyani commented ·

hello, thanks for replay , I m remove id and update only price but still no luck receive 400 error

0 Likes 0 ·
Dan avatar image Dan ♦ jollyraiyani commented ·

Please provide a more complete example and the full exception message
I suspect that there is a problem with the changes you are making to curOrder.

0 Likes 0 ·
jollyraiyani avatar image jollyraiyani commented ·

hello, here is my complete code

Order curOrder = orderConnector.getOrder(orderID);

lineItemId = curOrder.getLineItems().get(0).getId();
price=donationAmountLong+curOrder.getLineItems().get(0).getPrice();

List<LineItem> lineItems = curOrder.getLineItems();
Log.d("lineItems",lineItems+"");
LineItem lineItem = lineItems.get(0);
lineItem.setPrice(donationAmountLong+curOrder.getLineItems().get(0).getPrice());
Log.d("lineItems",lineItems+"");
float f = (float)donationAmountLong/100;
curOrder.setNote("CharityCheckout & " + charityTo + " & " + f);
orderConnector.updateLineItems(orderID,lineItems);
orderConnector.updateOrder(curOrder);

line item update but after 400 error code received ,can't update more then one filed and in log curorder line item total changed

0 Likes 0 ·
Dan avatar image Dan ♦ jollyraiyani commented ·

Can you please post the full exception message

0 Likes 0 ·
ballidaku avatar image
ballidaku answered Dan commented
Hello Dan
i am also getting the same error while updating the lineItem.
My error msg is : com.clover.sdk.v1.ClientException: status code: 400 no valid line item updates found
It occured when i am using :
Double p = Double.parseDouble(273) * 100;
long price = Math.round(p);
List<LineItem> lineItems = order.getLineItems();
lineItems.get(0).setPrice(price);
List<LineItem> list = new ArrayList<>();
list.add(lineItems.get(0));
orderConnector1.updateLineItems(orderId,list);

what i found is after setting the price :
[LineItem{json='{"id":"4MHVJMQVZGSBC","item":{"id":"7RW2KH3XBADC4"},"createdTime":1516345253555,"binName":null,"userData":null,"itemCode":null,"price":27300,"alternateName":null,"name":"aa1","exchanged":false,"refunded":false,"printed":false,"isRevenue":true,"taxRates":{"elements":[{"id":"DMMEP9P6W1YQ0","name":"NO_TAX_APPLIED","rate":0,"isDefault":false}]}}', bundle=null, changeLog=Bundle[{price=null}]}]

In Changelog the price is showing null but in the price it is showing.
Please help me in that.

2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

chanel avatar image chanel commented ·

Hi @ballidaku. Please create a new question that includes this information and the full exception message.

0 Likes 0 ·
Dan avatar image Dan ♦ commented ·

I don't know if you're actually supposed to be able to change the price of a line item.

If so, then theres a bug in updateLineItems. As of today, its only updating the line item if at least one of the binName, printed, note, or userData fields are changed. Note that there are many prohibited fields, but price isn't in that list.

To fix your problem, you'll need to touch one of those fields. I went with li2.setNote(li2.getNote()).

OrderConnector oc = new OrderConnector(MainActivity.this, CloverAccount.getAccount(MainActivity.this), null);

try {
  Order order = oc.createOrder(new Order());
  LineItem li = new LineItem();
  li.resetChangeLog();
  li.setPrice(500l);
  li.setName("name");
  LineItem li2 = oc.addCustomLineItem(order.getId(), li, false);
  li2.setPrice(300l);
  li2.setNote(li2.getNote());
  oc.updateLineItems(order.getId(), Arrays.asList(new LineItem[] {li2}));
} catch(Exception e) {
  e.printStackTrace();
}
0 Likes 0 ·

Welcome to the
Clover Developer Community