I am attempting to get the names of all categories that a product belongs to in Commercetools platform.
I can get the unique ID of each category tied to a product through the following call:
final ProductProjectionQuery query = ProductProjectionQuery.ofCurrent();
ProductProjectionQuery q = query.withLimit(450);
try {
PagedQueryResult<io.sphere.sdk.products.ProductProjection> pagedQueryResult = client.execute(q).toCompletableFuture().get();
List<io.sphere.sdk.products.ProductProjection> products = pagedQueryResult.getResults();
//createDocument(products.get(0).getMasterVariant(), request);
for (io.sphere.sdk.products.ProductProjection product : products) {
String categoryId = product.getCategories().iterator().next().getId();
//createDocument(product.getMasterVariant(), request);
}
}
Though once I have the categoryId, I am unsure of how to access the category name. I thought that the obj property might allow me to drill down into the category, but the obj variable always seems to be null.