Working with nested Product Types
Akii opened this issue · 3 comments
Akii commented
What is the best way to deal with nested Product Types? I've been following this tutorial here: https://docs.commercetools.com/tutorials/nested-types
The best way of accessing the nested type I came up with has been this attempt:
val taste = productVariant.withProductVariant(AttributesAccessor::of).asString("taste")
val nutrients = productVariant.withProductVariant(AttributesAccessor::of).get("nutrients")
val nutrientsValues = nutrients!!.value as List<List<AttributeImpl>>
println("The taste is $taste for these nutrients:")
nutrientsValues.forEach {
println(" Code: ${it[1].value} and Quality: ${it[0].value}")
}
Is there a better way of accessing the nested type?
jenschude commented
Hi,
please see https://github.com/commercetools/commercetools-sdk-java-v2/pull/295/files
The change will be included in the next release, but could also be used on your side by copying the necessary methods
Akii commented
Hey, that looks awesome. Thanks for adding this!
jenschude commented
Just released 8.6.0 which includes the additions to the AttributesAccessor