Changing the Default Product Structure in Kotlin SDK
The following is what the default product structure looks like according to the Dynamic Yield product feed structure:
Open class DefaultRecsProductData : RecsProductData() {
var product_type: ProductType? = null
var group_id: String? = null
var name: String? = null
var url: String? = null
var price: Float? = null
var in_stock: Boolean? = null
var image_url: String? = null
var categories: List<String?>? = null
var keywords: List<String?>? = null
}
Changing the default using Kotlin SDK
To add more fields to the product structure:
- Create a new class that inherits from
RecsProductData
and annotate the class with the@Serializable
annotation (org.jetbrains.kotlinx:kotlinx-serialization-json).
@Serializable
class CustomRecsProductData : RecsProductData() {
val color: String? = null
}
- Set this class as the new default product data structure by calling
setDefaultProductDataType()
.
private fun changeTheDefaultRecsProductData() {
DYSdk.getInstance().setDefaultProductDataType(CustomRecsProductData.serializer())
}
- After calling
setDefaultProductDataType()
, wheneverchooseVariations
is called for recommendations campaigns, the return value includes the fields you added to the new class.
Updated 5 days ago