Setting the Returned Product Attributes in Recommendations in Swift SDK
Dynamic Yield provides a default structure for product attributes returned in recommendation campaign responses. You can fine-tune these product attributes to match your business needs as described in this article. Note that when you use the chooseVariation function , you can override this default by creating a dedicated recsProductData object.
The default product attribute structure
The following is the default product structure (based on the Dynamic Yield product feed structure):
  public class DefaultRecsProductData: RecsProductData {
        let productType: ProductType?
        let groupId: String?
        let name: String?
        let url: String?
        let price: Float?
        let inStock: Bool?
        let imageUrl: String?
        let categories: [String?]?
        var keywords: [String?]?
        var extra: [String: Any?] = [:]
    }
Changing the default using Swift SDK
To add more fields to the product structure:
- Create a new class that inherits from 
RecsProductData. 
    public class CustomRecsProductData: RecsProductData {
        var shortColor: String = "yellow"
        var tShirtNumber: Int = 8
        var initials: String = "A.N"
    }
- Set this class as the new default product data structure by calling 
setDefaultProductDataType(). 
  DYSdk.shared().setDefaultProductDataType(defaultRecsProductData: CustomRecsProductData.self)
- After calling 
setDefaultProductDataType(), wheneverchooseVariationsis called for recommendations campaigns, the return value includes the fields you added to the new class. The product data will include the values in either a dedicated attribute (to the listed above attribute - product type, price, keywords, etc.), any additional attribute and it's value will be found inside theextramap.
 
Updated 4 months ago