Skip to content

Commit 3a75208

Browse files
authored
Merge pull request #491 from Iterable/MOB-3180-updateCart-items-datafields
[MOB-3180] update cart items datafields
2 parents 190df2b + 235d924 commit 3a75208

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

swift-sdk/CommerceItem.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ import UIKit
3636
/// each category is a breadcrumb in list form
3737
public var categories: [String]?
3838

39+
/// data fields for this product
40+
public var dataFields: [AnyHashable: Any]?
41+
3942
/// Creates a `CommerceItem` with the specified properties
4043
///
4144
/// - Parameters:
@@ -58,7 +61,8 @@ import UIKit
5861
description: String? = nil,
5962
url: String? = nil,
6063
imageUrl: String? = nil,
61-
categories: [String]? = nil) {
64+
categories: [String]? = nil,
65+
dataFields: [AnyHashable: Any]? = nil) {
6266
self.id = id
6367
self.name = name
6468
self.price = price
@@ -68,6 +72,7 @@ import UIKit
6872
self.url = url
6973
self.imageUrl = imageUrl
7074
self.categories = categories
75+
self.dataFields = dataFields
7176
}
7277

7378
/// A `Dictionary` representation of this item
@@ -99,6 +104,10 @@ import UIKit
99104
dictionary[JsonKey.CommerceItem.categories] = categories
100105
}
101106

107+
if let dataFields = dataFields {
108+
dictionary[JsonKey.CommerceItem.dataFields] = dataFields
109+
}
110+
102111
return dictionary
103112
}
104113
}

swift-sdk/Constants.swift

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ enum JsonKey {
170170
static let imageUrl = "imageUrl"
171171
static let url = "url"
172172
static let categories = "categories"
173+
static let dataFields = "dataFields"
173174
}
174175

175176
enum Device {

tests/unit-tests/CommerceItemTests.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class CommerceItemTests: XCTestCase {
2828
url: "stand-alone-complex",
2929
imageUrl: "laughing-man",
3030
categories: ["section 9",
31-
"personnel transport"]).toDictionary()
31+
"personnel transport"],
32+
dataFields: ["color": "yellow",
33+
"count": 8]).toDictionary()
3234

3335
let expected: [AnyHashable: Any] = ["id": "THINKTANK",
3436
"name": "Tachikoma",
@@ -39,7 +41,9 @@ class CommerceItemTests: XCTestCase {
3941
"url": "stand-alone-complex",
4042
"imageUrl": "laughing-man",
4143
"categories": ["section 9",
42-
"personnel transport"]]
44+
"personnel transport"],
45+
"dataFields": ["color": "yellow",
46+
"count": 8]]
4347

4448
XCTAssertEqual(NSDictionary(dictionary: itemDictionary), NSDictionary(dictionary: expected))
4549
}

0 commit comments

Comments
 (0)