|
4 | 4 |
|
5 | 5 | import UIKit
|
6 | 6 |
|
7 |
| -/** |
8 |
| - `CommerceItem` represents a product. These are used by the commerce API; see [IterableAPI trackPurchase:items:dataFields:] |
9 |
| - */ |
| 7 | +/// `CommerceItem` represents a product |
| 8 | +/// - SeeAlso: IterableAPI.track(purchase withTotal: items:) |
10 | 9 | @objcMembers public class CommerceItem: NSObject {
|
11 |
| - /** id of this product */ |
| 10 | + /// id of this product |
12 | 11 | public var id: String
|
13 | 12 |
|
14 |
| - /** name of this product */ |
| 13 | + /// name of this product |
15 | 14 | public var name: String
|
16 | 15 |
|
17 |
| - /** price of this product */ |
| 16 | + /// price of this product |
18 | 17 | public var price: NSNumber
|
19 | 18 |
|
20 |
| - /** quantity of this product */ |
| 19 | + /// quantity of this product |
21 | 20 | public var quantity: UInt
|
22 | 21 |
|
23 |
| - /** |
24 |
| - Creates a `CommerceItem` with the specified properties |
25 |
| - |
26 |
| - - parameters: |
27 |
| - - id: id of the product |
28 |
| - - name: name of the product |
29 |
| - - price: price of the product |
30 |
| - - quantity: quantity of the product |
31 |
| - |
32 |
| - - returns: an instance of `CommerceItem` with the specified properties |
33 |
| - */ |
34 |
| - public init(id: String, name: String, price: NSNumber, quantity: UInt) { |
| 22 | + /// SKU of this product |
| 23 | + public var sku: String? |
| 24 | + |
| 25 | + /// description of the product |
| 26 | + /// the class field is named `itemDescription` to avoid iOS namespace (`description`) |
| 27 | + public var itemDescription: String? |
| 28 | + |
| 29 | + /// URL of the product |
| 30 | + public var url: String? |
| 31 | + |
| 32 | + /// URL of the product's image |
| 33 | + public var imageUrl: String? |
| 34 | + |
| 35 | + /// categories this product belongs to |
| 36 | + /// each category is a breadcrumb in list form |
| 37 | + public var categories: [String]? |
| 38 | + |
| 39 | + /// Creates a `CommerceItem` with the specified properties |
| 40 | + /// |
| 41 | + /// - Parameters: |
| 42 | + /// - id: id of the product |
| 43 | + /// - name: name of the product |
| 44 | + /// - price: price of the product |
| 45 | + /// - quantity: quantity of the product |
| 46 | + /// - sku: SKU of the eproduct |
| 47 | + /// - description: description of the product |
| 48 | + /// - url: URL of the product |
| 49 | + /// - imageUrl: URL of the product's image |
| 50 | + /// - categories: categories this product belongs to |
| 51 | + /// |
| 52 | + /// - returns: an instance of `CommerceItem` with the specified properties |
| 53 | + public init(id: String, |
| 54 | + name: String, |
| 55 | + price: NSNumber, |
| 56 | + quantity: UInt, |
| 57 | + sku: String? = nil, |
| 58 | + description: String? = nil, |
| 59 | + url: String? = nil, |
| 60 | + imageUrl: String? = nil, |
| 61 | + categories: [String]? = nil) { |
35 | 62 | self.id = id
|
36 | 63 | self.name = name
|
37 | 64 | self.price = price
|
38 | 65 | self.quantity = quantity
|
| 66 | + self.sku = sku |
| 67 | + self.itemDescription = description |
| 68 | + self.url = url |
| 69 | + self.imageUrl = imageUrl |
| 70 | + self.categories = categories |
39 | 71 | }
|
40 | 72 |
|
41 |
| - /** |
42 |
| - A Dictionary respresentation of this item |
43 |
| - |
44 |
| - - returns: An NSDictionary representing this item |
45 |
| - */ |
| 73 | + /// A `Dictionary` representation of this item |
| 74 | + /// |
| 75 | + /// - returns: An `Dictionary` representing this item |
46 | 76 | public func toDictionary() -> [AnyHashable: Any] {
|
47 |
| - ["id": id, |
48 |
| - "name": name, |
49 |
| - "price": price, |
50 |
| - "quantity": quantity] |
| 77 | + var dictionary: [AnyHashable: Any] = [JsonKey.CommerceItem.id: id, |
| 78 | + JsonKey.CommerceItem.name: name, |
| 79 | + JsonKey.CommerceItem.price: price, |
| 80 | + JsonKey.CommerceItem.quantity: quantity] |
| 81 | + |
| 82 | + if let sku = sku { |
| 83 | + dictionary[JsonKey.CommerceItem.sku] = sku |
| 84 | + } |
| 85 | + |
| 86 | + if let description = itemDescription { |
| 87 | + dictionary[JsonKey.CommerceItem.description] = description |
| 88 | + } |
| 89 | + |
| 90 | + if let url = url { |
| 91 | + dictionary[JsonKey.CommerceItem.url] = url |
| 92 | + } |
| 93 | + |
| 94 | + if let imageUrl = imageUrl { |
| 95 | + dictionary[JsonKey.CommerceItem.imageUrl] = imageUrl |
| 96 | + } |
| 97 | + |
| 98 | + if let categories = categories { |
| 99 | + dictionary[JsonKey.CommerceItem.categories] = categories |
| 100 | + } |
| 101 | + |
| 102 | + return dictionary |
51 | 103 | }
|
52 | 104 | }
|
0 commit comments