question

Ajmal M A avatar image
Ajmal M A asked Ajmal M A commented

How to add an Item to label ( Tag ) ?

I want to add specific item in the inventory to a label. Currently we are using following code to achieve this.

For create a Tag

tag = new Tag();
tag.setName(tagName);
tag = inventoryService.createTag(tag, resultStatus);

Which successfully created a tag in inventory. Now i want add this tag to an item :

List<Tag> tagList = new ArrayList<>();
tagList.add(tag);
newItem.setTags(tagList);
newItem = inventoryService.createItem(newItem, resultStatus);
Which created the item, But label not added to that item.

How can I add a label (tag) to an item? Please help me with some sample code snippets.

Thank you




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

Dan avatar image
Dan answered Ajmal M A commented
You should be able to use of InventoryConnector#assignTagsToItem(final String itemId, final List<String> tags)

So the process would be something like:
Tag tag = new Tag();
tag.setName("My First New Tag");
Tag tag2 = new Tag();
tag2.setName("My Second New Tag");
Item item = new Item();
item.setName("My New Item");
item.setPrice(1000L);
tag = inventoryConnector.createTag(tag);
tag2 = inventoryConnector.createTag(tag2);
item = inventoryConnector.createItem(item);
List<String> tagIds = new ArrayList<>();
tagIds.add(tag.getId());
tagIds.add(tag2.getId());
inventoryConnector.assignTagsToItem(item.getId(), tagIds);
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.

Ajmal M A avatar image Ajmal M A commented ·

Thanks Dan, It worked!!

0 Likes 0 ·

Welcome to the
Clover Developer Community