question

ondrej avatar image
ondrej asked ondrej answered

How to copy an order

Hi I would like to make (locally) a copy of an existing order.

Is there any other way besides orderConnector.createOrder(src); ? I would like to the new order to have a null state to not yet to be listed among orders on the device.

I have tried:

Order o = new Order();

 final Order newOrder = orderConnector.createOrder(o);

 ArrayList<String> lineItemIds = new ArrayList<>();
 for (LineItem i : src.getLineItems()){
     lineItemIds.add(i.getId());
 }

 orderConnector.createLineItemsFrom(src.getId(),newOrder.getId(), lineItemIds);

But that fails with

CloverBinder: isCallerClover(CloverBinder.java:897): Calling process doesn't have appropriate permission

Besides that the method is not commented as 'Not available to non-Clover apps.', how should I proceed?

Thank you, Ondrej

Orders
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

Can you provide more info/a full stack trace for the permission error?

It is not possible to use the order connector to create an order and have it not appear among orders on the device.

If the goal is to have a local copy of an order that you can then make changes to, you can do this by using:

Order copiedOrder = new Order(sourceOrder);

And then you can make do whatever you want to it, but you won't be able to use it with an OrderConnector until you call orderConnector.createOrder(copiedOrder), at which point he order is inserted in the local device database, the clover server, and is visible to the merchant, clover apps, and third party apps with the read orders permission.

Note that when createOrder is called, this will create a new, random uuid for the order and overwrite the order id from the original order (or whatever you updated it to).

10 |2000

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

ondrej avatar image
ondrej answered

I cannot reproduce it today :(

Finally I ended using it as suggested:

Order copiedOrder = new Order(sourceOrder);

NB: Now I am not able to delete the new order :) ... I will create another question for that .

Thank you very much, Ondrej

10 |2000

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

Welcome to the
Clover Developer Community