Skip to content

Commit 8a5a2bf

Browse files
committed
Include image in OrderItem object
1 parent db48e93 commit 8a5a2bf

File tree

22 files changed

+70
-1
lines changed

22 files changed

+70
-1
lines changed

Modules/Sources/Fakes/NetworkingCore.generated.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ extension NetworkingCore.OrderItem {
270270
totalTax: .fake(),
271271
attributes: .fake(),
272272
addOns: .fake(),
273+
image: .fake(),
273274
parent: .fake(),
274275
bundleConfiguration: .fake()
275276
)

Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Codegen
55
import Foundation
66
import WooFoundation
77
import struct Alamofire.JSONEncoding
8+
import struct NetworkingCore.JetpackSite
89

910

1011
extension Networking.AIProduct {

Modules/Sources/NetworkingCore/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ extension NetworkingCore.OrderItem {
444444
totalTax: CopiableProp<String> = .copy,
445445
attributes: CopiableProp<[OrderItemAttribute]> = .copy,
446446
addOns: CopiableProp<[OrderItemProductAddOn]> = .copy,
447+
image: NullableCopiableProp<OrderItemProductImage> = .copy,
447448
parent: NullableCopiableProp<Int64> = .copy,
448449
bundleConfiguration: CopiableProp<[OrderItemBundleItem]> = .copy
449450
) -> NetworkingCore.OrderItem {
@@ -462,6 +463,7 @@ extension NetworkingCore.OrderItem {
462463
let totalTax = totalTax ?? self.totalTax
463464
let attributes = attributes ?? self.attributes
464465
let addOns = addOns ?? self.addOns
466+
let image = image ?? self.image
465467
let parent = parent ?? self.parent
466468
let bundleConfiguration = bundleConfiguration ?? self.bundleConfiguration
467469

@@ -481,6 +483,7 @@ extension NetworkingCore.OrderItem {
481483
totalTax: totalTax,
482484
attributes: attributes,
483485
addOns: addOns,
486+
image: image,
484487
parent: parent,
485488
bundleConfiguration: bundleConfiguration
486489
)

Modules/Sources/NetworkingCore/Model/OrderItem.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public struct OrderItem: Codable, Equatable, Hashable, Sendable, GeneratedFakeab
3030

3131
public let addOns: [OrderItemProductAddOn]
3232

33+
public let image: OrderItemProductImage?
34+
3335
/// Item ID of parent `OrderItem`, if any.
3436
///
3537
/// An `OrderItem` can have a parent if, for example, it is a bundled item within a product bundle.
@@ -58,6 +60,7 @@ public struct OrderItem: Codable, Equatable, Hashable, Sendable, GeneratedFakeab
5860
totalTax: String,
5961
attributes: [OrderItemAttribute],
6062
addOns: [OrderItemProductAddOn],
63+
image: OrderItemProductImage?,
6164
parent: Int64?,
6265
bundleConfiguration: [OrderItemBundleItem]) {
6366
self.itemID = itemID
@@ -75,6 +78,7 @@ public struct OrderItem: Codable, Equatable, Hashable, Sendable, GeneratedFakeab
7578
self.totalTax = totalTax
7679
self.attributes = attributes
7780
self.addOns = addOns
81+
self.image = image
7882
self.parent = parent
7983
self.bundleConfiguration = bundleConfiguration
8084
}
@@ -123,6 +127,9 @@ public struct OrderItem: Codable, Equatable, Hashable, Sendable, GeneratedFakeab
123127
forKey: .attributes)
124128
.first(where: { $0.key == "_pao_ids" })?.value ?? []
125129

130+
// Order item product image
131+
let image = try container.decodeIfPresent(OrderItemProductImage.self, forKey: .image)
132+
126133
// Product Bundle extension properties:
127134
// If the order item is part of a product bundle, `bundledBy` is the parent order item (product bundle).
128135
// If it's not a bundled item, the API returns an empty string for `bundledBy` and the value will be `nil`.
@@ -149,6 +156,7 @@ public struct OrderItem: Codable, Equatable, Hashable, Sendable, GeneratedFakeab
149156
totalTax: totalTax,
150157
attributes: attributes,
151158
addOns: productAddOns,
159+
image: image,
152160
parent: bundledBy ?? compositeParent,
153161
bundleConfiguration: [])
154162
}
@@ -174,6 +182,10 @@ public struct OrderItem: Codable, Equatable, Hashable, Sendable, GeneratedFakeab
174182
try container.encode(total, forKey: .total)
175183
}
176184

185+
if let image = image {
186+
try container.encode(image, forKey: .image)
187+
}
188+
177189
if !bundleConfiguration.isEmpty {
178190
try container.encode(bundleConfiguration, forKey: .bundleConfiguration)
179191
}
@@ -204,6 +216,7 @@ extension OrderItem {
204216
case bundledBy = "bundled_by"
205217
case compositeParent = "composite_parent"
206218
case bundleConfiguration = "bundle_configuration"
219+
case image
207220
}
208221
}
209222

@@ -222,3 +235,16 @@ private struct OrderItemProductAddOnContainer: Decodable {
222235
let key: String
223236
let value: [OrderItemProductAddOn]
224237
}
238+
239+
240+
// MARK: - Order Item Product Image
241+
//
242+
public struct OrderItemProductImage: Codable, Equatable, Hashable, Sendable {
243+
public let id: String
244+
public let src: String
245+
246+
public init(id: String, src: String) {
247+
self.id = id
248+
self.src = src
249+
}
250+
}

Modules/Sources/Yosemite/Model/Mocks/MockObjectGraph.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ extension MockObjectGraph {
222222
totalTax: "0",
223223
attributes: [],
224224
addOns: [],
225+
image: nil,
225226
parent: nil,
226227
bundleConfiguration: []
227228
)

Modules/Sources/Yosemite/Model/Storage/OrderItem+ReadOnlyConvertible.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extension Storage.OrderItem: ReadOnlyConvertible {
5555
totalTax: totalTax ?? "",
5656
attributes: attributes,
5757
addOns: addOns,
58+
image: nil,
5859
parent: parent?.int64Value,
5960
bundleConfiguration: [])
6061
}

Modules/Sources/Yosemite/PointOfSale/OrderList/POSOrderItem.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public struct POSOrderItem: Equatable, Hashable {
1010
public let quantity: Decimal
1111
public let formattedPrice: String
1212
public let formattedTotal: String
13+
public let imageSrc: String?
1314
public let attributes: [OrderItemAttribute]
1415

1516
public init(itemID: Int64,
@@ -19,6 +20,7 @@ public struct POSOrderItem: Equatable, Hashable {
1920
quantity: Decimal,
2021
formattedPrice: String,
2122
formattedTotal: String,
23+
imageSrc: String?,
2224
attributes: [OrderItemAttribute]) {
2325
self.itemID = itemID
2426
self.name = name
@@ -27,6 +29,7 @@ public struct POSOrderItem: Equatable, Hashable {
2729
self.quantity = quantity
2830
self.formattedPrice = formattedPrice
2931
self.formattedTotal = formattedTotal
32+
self.imageSrc = imageSrc
3033
self.attributes = attributes
3134
}
3235
}

Modules/Sources/Yosemite/PointOfSale/OrderList/POSOrderMapper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct POSOrderMapper {
6161
quantity: orderItem.quantity,
6262
formattedPrice: currencyFormatter.formatAmount(orderItem.price, with: currency) ?? "",
6363
formattedTotal: currencyFormatter.formatAmount(orderItem.total, with: currency) ?? "",
64+
imageSrc: orderItem.image?.src,
6465
attributes: orderItem.attributes
6566
)
6667
}

Modules/Sources/Yosemite/Stores/Order/ProductInputTransformer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private extension ProductInputTransformer {
241241
totalTax: "",
242242
attributes: [],
243243
addOns: [],
244+
image: nil,
244245
parent: nil,
245246
bundleConfiguration: input.bundleConfiguration.map {
246247
switch $0.productOrVariation {

Modules/Tests/YosemiteTests/PointOfSale/POSOrderMapperTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ private extension POSOrderMapperTests {
193193
quantity: quantity,
194194
price: price,
195195
subtotal: subtotal,
196-
total: total
196+
total: total,
197+
image: nil
197198
)
198199
}
199200

0 commit comments

Comments
 (0)