question

matteobklyn avatar image
matteobklyn asked matteobklyn edited

How to get categories of an item

Hi there!
I'm trying to get the categories of each item in an order and having troubles with that using the latest Android SDK.

I am fetching the order via the OrderConnector and noticed that each item has pretty much all I need but the categories: so I ended up asking each item details via the InventoryConnector, but still get an empty categories list.

orderConnector.getOrder(orderId)
inventoryConnector.getItem(itemId)

Is there anything wrong with this approach?
Orders
1 comment
10 |2000

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

matteobklyn avatar image matteobklyn commented ·

The workaround was to call

inventoryConnector.getItemWithCategories(itemId)

instead of

inventoryConnector.getItem(itemId)

otherwise the categories array is not getting populated at all.

Do not trust the accepted answer.

0 Likes 0 ·

1 Answer

Jonathan Ryan Grice avatar image
Jonathan Ryan Grice answered matteobklyn commented
SDK Documentation can be found at
https://clover.github.io/clover-android-sdk/
.getCategories() would have to be applied to retrieve the categories for an item.

getCategories

public java.util.List<Category> getCategories()
Categories associated with this item
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.

matteobklyn avatar image matteobklyn commented ·

Hi @Jonathan Ryan Grice, unfortunately I can't find your answer useful as of now.

I am calling getCategories() on the Item instance fetched via either the OrderConnector or InventoryConnector but the list is empty.

For instance, using Kotlin:

val item = inventoryConnector.getItem("my item id")
item.categories // empty

Is there any way to tell the SDK to also fetch the categories, like in a GraphQL fashion?

To give you a better understanding here's an example of an item I have in the inventory.

Item: Large Beer

Categories: Drinks, ...

Tags: Alcohol, ...

I can read all the item properties (e.g. the tags) but not the categories.

It's worth noting that the categories array is null and hasCategories always returns false, while on items with no tags I always get a non null list (empty or with some tags) and hasTags always returns true. Sounds like a serialization/deserialization issue on the SDK itself?

Thanks for your help.

0 Likes 0 ·
Jonathan Ryan Grice avatar image Jonathan Ryan Grice matteobklyn commented ·

getCategories is a function, not an object.

0 Likes 0 ·
matteobklyn avatar image matteobklyn Jonathan Ryan Grice commented ·

It's a function, meaning it will call getCagegories() on the Java code. Added my answer with the real solution. Thank you anyway!

0 Likes 0 ·

Welcome to the
Clover Developer Community