question

Dan avatar image
Dan asked Jacob Abrams commented

Create an Item with a specified ID using the InventoryConnector

I would like to create an item with a hard-coded ID so I know what the ID of the item is at all times. This is so at a later date I can verify it's existence by calling the getItem() function on the InventoryConnector and pass in this ID.

I create an item below like so:

Item i = new Item().setId(MY_ITEM_ID).setName(MY_ITEM_NAME).setPrice(0L).setPriceType(PriceType.VARIABLE).setDefaultTaxRates(false);
mInventoryConnector.createItem(i, new ServiceConnector.Callback<Item>() {
    @Override
    public void onServiceSuccess(Item result, ResultStatus status) {
       //
    }

    @Override
    public void onServiceFailure(ResultStatus status) {
        //
    }

    @Override
    public void onServiceConnectionFailure() {
        //
    }
});

In this case, the setId() function does not work, and the item's ID is always a 13 character String generated by the SDK.

How might I set an item ID on creation?

Inventory
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

jim-patel avatar image
jim-patel answered Jacob Abrams commented

You can't, Item ID is set by Clover and there's no way to alter this behavior.

When you create the item, the return value is an Item object. You can save this to your app's database for retrieval later.

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

Dan avatar image Dan commented ·

Okay Jim thanks for clarifying that. The reason this doesn't work for me is that if a client clears their app data I will end up creating nonfunctional dupes, so it looks like I'm going to have to remotely cache these IDs. My original logic was to check if the item existed by a name tag by checking all the items via getItems(), but that gives me a TransactionTooLarge exception on Merchants with very large databases of items so isn't an option either.

0 Likes 0 ·
Mike M avatar image Mike M commented ·

Items also have Product Code and SKU properties that you can use to store your custom ID's.

0 Likes 0 ·
Jacob Abrams avatar image Jacob Abrams ♦♦ commented ·

A better way to read and search inventory in an Android app is through the inventory content provider. Use https://github.com/clover/clover-andr... to access it.

0 Likes 0 ·

Welcome to the
Clover Developer Community