question

James Tickett avatar image
James Tickett asked James Tickett commented

How can we delete sets of orders, specifically open orders?

I've asked a similar question before, and we ended up deleting orders when they were being abandoned, however, this method doesn't catch all cases, so we've been asked to come up with an end-of-day process to remove remaining open orders. The basic process should be:

1) Search for Open Orders and save these order_ids

2) Use SDK or API to delete these.

I can use the API to return open orders, however I would prefer to use the SDK if possible, although I can't understand how to do the equivalent of a search (similar to "&filter=state=open"). Any ideas?

The API call seems to take a single OrderID for deleting orders, as does orderConnector.deleteorder() ...Is there a way to deal with multiple orders, or will I have to loop? ...And if so, do you have any suggestions to avoid pressuring the API too much?

Thanks!

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.

1 Answer

Jeffrey Blattman avatar image
Jeffrey Blattman answered James Tickett commented

No, using the SDK you can only delete one order at a time. In the SDK, you can query the order summaries table using OrderContract and filter on STATE to find the open orders, and delete them.

7 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.

James Tickett avatar image James Tickett commented ·

Hi Jeff,

I took a look at Clover Sample Code and found a few projects using OrderContracts. Looking at the class description for .getContentResolver().query() it seems like the third parameter is the equivalent of an SQL WHERE, so I tried this with no luck:

cursor = MainActivity.this.getContentResolver().query(
                    OrderContract.Summaries.contentUriWithAccount(account),
                    new String[]{OrderContract.Summaries.ID},
                    OrderContract.Summaries.STATE + " = OPEN",
                    null,
                    null

What am I doing wrong here?

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

Looks like your SQL is wrong. I think you need single quotes around "OPEN". `OrderContract.Summaries.STATE + "='OPEN'". You should be able to see in the log what is the problem.

0 Likes 0 ·
James Tickett avatar image James Tickett commented ·

I think I've got the hang of this now, but it's only returning one result, sometimes two, sometimes none. Assuming this is querying a local db on the device rather than online.... is there some way I can make sure this is updated?

I can see through the Orders screen a bunch of open orders, but only get returned the one.

0 Likes 0 ·
James Tickett avatar image James Tickett commented ·

Following the code that you corrected, I have:

if (cursor != null && cursor.moveToFirst()) {
                orderId = cursor.getString(cursor.getColumnIndex(OrderContract.Summaries.ID));
                order_ids.add(orderId);
                while(cursor.moveToNext()){
                    orderId = cursor.getString(cursor.getColumnIndex(OrderContract.Summaries.ID));
                    order_ids.add(orderId);
                }
            }
0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

Well, it's querying against the same DB that is backing the Orders app. Did you try say just querying everything and then looping through and inspecting the states of the results? Obviously not the ultimate solution but looking at the results of that might give you some clues as to what's wrong w/ your query. Other than that, you if you want provide a sample app + source I can run I could see why it's not working.

0 Likes 0 ·
Show more comments

Welcome to the
Clover Developer Community