question

scottnj avatar image
scottnj asked Jacob Abrams answered

Group variant items when using InventoryContract

I am currently displaying a list of inventory items in a RecyclerView queried using the InventoryContract and the Paging library as was recommended at the following link.

https://community.clover.com/questions/22806/list-of-items-belonging-to-a-category-using-invent.html

I now need to display the variants grouped together in the list like the Register App does when displaying "All Items".


Is there a convenient way to query a list of items with the variants grouped together as a single item? If not, I would be very grateful for recommendations on how to accomplish this.


An example use case would be a shoe store with many shoe styles and many sizes for each style. Displaying all the style + size combinations on the screen would make the view very long. Modifiers wouldn't work for this merchant either because the store might want to keep track of how many of each size variant they have in stock.


Clover Android SDKInventory
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

·
Jacob Abrams avatar image
Jacob Abrams answered

There is a mechanism to return a cursor that has one row for each item with no group plus one row for each item group. Note that slightly annoyingly the response is missing the android standard column "_id" which classes like android.widget.CursorAdapter expect. I shall attempt to correct this oversight in a future release of our engine app but for now here is an example command:

getContentResolver().query(InventoryContract.ItemGroup.contentUriAndSampleItemWithAccount(mAccount),
        new String[] {
            // This trick gets a column with the name "_id"
            "item._id AS _id",
            InventoryContract.Item.NAME,
            InventoryContract.Item.PRICE,
            InventoryContract.Item.PRICE_TYPE,
            InventoryContract.Item.UNIT_NAME,
            InventoryContract.ItemGroupsAndItemsColumns.ITEM_GROUP_NAME,
        }, null, null, InventoryContract.Item.NAME);
10 |2000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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