@@ -8,6 +8,7 @@ public struct OrderItem: Decodable {
88 public let name : String
99 public let productID : Int
1010 public let quantity : Int
11+ public let price : NSDecimalNumber
1112 public let sku : String ?
1213 public let subtotal : String
1314 public let subtotalTax : String
@@ -18,11 +19,12 @@ public struct OrderItem: Decodable {
1819
1920 /// OrderItem struct initializer.
2021 ///
21- public init ( itemID: Int , name: String , productID: Int , quantity: Int , sku: String , subtotal: String , subtotalTax: String , taxClass: String , total: String , totalTax: String , variationID: Int ) {
22+ public init ( itemID: Int , name: String , productID: Int , quantity: Int , price : NSDecimalNumber , sku: String ? , subtotal: String , subtotalTax: String , taxClass: String , total: String , totalTax: String , variationID: Int ) {
2223 self . itemID = itemID
2324 self . name = name
2425 self . productID = productID
2526 self . quantity = quantity
27+ self . price = price
2628 self . sku = sku
2729 self . subtotal = subtotal
2830 self . subtotalTax = subtotalTax
@@ -31,6 +33,39 @@ public struct OrderItem: Decodable {
3133 self . totalTax = totalTax
3234 self . variationID = variationID
3335 }
36+
37+ /// The public initializer for OrderItem.
38+ ///
39+ public init ( from decoder: Decoder ) throws {
40+ let container = try decoder. container ( keyedBy: CodingKeys . self)
41+ let itemID = try container. decode ( Int . self, forKey: . itemID)
42+ let name = try container. decode ( String . self, forKey: . name)
43+ let productID = try container. decode ( Int . self, forKey: . productID)
44+ let quantity = try container. decode ( Int . self, forKey: . quantity)
45+ let decimalPrice = try container. decodeIfPresent ( Decimal . self, forKey: . price) ?? Decimal ( 0 )
46+ let price = NSDecimalNumber ( decimal: decimalPrice)
47+ let sku = try container. decodeIfPresent ( String . self, forKey: . sku)
48+ let subtotal = try container. decode ( String . self, forKey: . subtotal)
49+ let subtotalTax = try container. decode ( String . self, forKey: . subtotalTax)
50+ let taxClass = try container. decode ( String . self, forKey: . taxClass)
51+ let total = try container. decode ( String . self, forKey: . total)
52+ let totalTax = try container. decode ( String . self, forKey: . totalTax)
53+ let variationID = try container. decode ( Int . self, forKey: . variationID)
54+
55+ // initialize the struct
56+ self . init ( itemID: itemID,
57+ name: name,
58+ productID: productID,
59+ quantity: quantity,
60+ price: price,
61+ sku: sku,
62+ subtotal: subtotal,
63+ subtotalTax: subtotalTax,
64+ taxClass: taxClass,
65+ total: total,
66+ totalTax: totalTax,
67+ variationID: variationID)
68+ }
3469}
3570
3671
@@ -43,6 +78,7 @@ private extension OrderItem {
4378 case name = " name "
4479 case productID = " product_id "
4580 case quantity = " quantity "
81+ case price = " price "
4682 case sku = " sku "
4783 case subtotal = " subtotal "
4884 case subtotalTax = " subtotal_tax "
@@ -62,6 +98,7 @@ extension OrderItem: Comparable {
6298 lhs. name == rhs. name &&
6399 lhs. productID == rhs. productID &&
64100 lhs. quantity == rhs. quantity &&
101+ lhs. price == rhs. price &&
65102 lhs. sku == rhs. sku &&
66103 lhs. subtotal == rhs. subtotal &&
67104 lhs. subtotalTax == rhs. subtotalTax &&
0 commit comments