Skip to content

Commit f013793

Browse files
authored
Shipping Labels: Display correct HAZMAT category on purchased label (#16081)
2 parents 2215ce8 + 630b5a2 commit f013793

File tree

20 files changed

+1192
-16
lines changed

20 files changed

+1192
-16
lines changed

Modules/Sources/Fakes/NetworkingCore.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ extension NetworkingCore.ShippingLabel {
456456
productNames: .fake(),
457457
commercialInvoiceURL: .fake(),
458458
usedDate: .fake(),
459-
expiryDate: .fake()
459+
expiryDate: .fake(),
460+
hazmatCategory: .fake()
460461
)
461462
}
462463
}

Modules/Sources/Networking/Mapper/WooShippingConfigMapper.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extension WooShippingConfigMapper {
4848
"config.shipments",
4949
"config.shippingLabelData.currentOrderLabels",
5050
"config.shippingLabelData.storedData.selected_destination",
51-
"config.shippingLabelData.storedData.selected_origin"
51+
"config.shippingLabelData.storedData.selected_origin",
52+
"config.shippingLabelData.storedData.selected_hazmat"
5253
].joined(separator: ", ")
5354
}

Modules/Sources/Networking/Model/ShippingLabel/Shipments/WooShippingConfigResponse.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ public struct WooShippingLabelData: Decodable, Equatable {
111111

112112
let destinations = storedData?.selectedDestinations
113113
let origins = storedData?.selectedOrigins
114+
let hazmatSelections = storedData?.selectedHazmat
114115

115116
if destinations?.isEmpty == false || origins?.isEmpty == false {
116117
orderLabels = WooShippingLabelData.mapAddresses(
117118
origins: origins,
118119
destinations: destinations,
120+
hazmatSelections: hazmatSelections,
119121
into: decodedOrderLabels
120122
)
121123
} else {
@@ -136,14 +138,17 @@ public struct WooShippingLabelData: Decodable, Equatable {
136138

137139
public extension WooShippingLabelData {
138140
typealias WooShippingLabelAddressMap = [String: WooShippingAddress]
141+
typealias WooShippingHazmatMap = [String: HazmatSelection]
139142

140143
struct StoredData: Decodable, Equatable {
141144
let selectedDestinations: WooShippingLabelAddressMap?
142145
let selectedOrigins: WooShippingLabelAddressMap?
146+
let selectedHazmat: WooShippingHazmatMap?
143147

144148
public enum CodingKeys: String, CodingKey {
145149
case selectedDestination = "selected_destination"
146150
case selectedOrigin = "selected_origin"
151+
case selectedHazmat = "selected_hazmat"
147152
}
148153

149154
public init(from decoder: any Decoder) throws {
@@ -156,6 +161,7 @@ public extension WooShippingLabelData {
156161
WooShippingLabelAddressMap.self,
157162
forKey: CodingKeys.selectedOrigin
158163
)
164+
selectedHazmat = try? container.decodeIfPresent(WooShippingHazmatMap.self, forKey: .selectedHazmat)
159165
}
160166
}
161167
}
@@ -166,3 +172,7 @@ enum WooShippingConfigDecodingError: Error {
166172
case missingSiteID
167173
case missingOrderID
168174
}
175+
176+
public struct HazmatSelection: Decodable, Equatable {
177+
public let category: String
178+
}

Modules/Sources/Networking/Model/ShippingLabel/Shipments/WooShippingLabelData+mapDestinations.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extension WooShippingLabelData {
44
static func mapAddresses(
55
origins: WooShippingLabelAddressMap?,
66
destinations: WooShippingLabelAddressMap?,
7+
hazmatSelections: WooShippingHazmatMap?,
78
into labels: [ShippingLabel]
89
) -> [ShippingLabel] {
910
return labels.map { label in
@@ -14,10 +15,12 @@ extension WooShippingLabelData {
1415
let formattedID = WooShippingShipmentIDFormatter.formattedShipmentID(shipmentID)
1516
let originAddress = origins?[formattedID] ?? origins?[shipmentID]
1617
let destinationAddress = destinations?[formattedID] ?? destinations?[shipmentID]
18+
let hazmat = hazmatSelections?[formattedID] ?? hazmatSelections?[shipmentID]
1719

1820
return label.copy(
1921
originAddress: originAddress?.toShippingLabelAddress() ?? .copy,
20-
destinationAddress: destinationAddress?.toShippingLabelAddress() ?? .copy
22+
destinationAddress: destinationAddress?.toShippingLabelAddress() ?? .copy,
23+
hazmatCategory: hazmat?.category
2124
)
2225
}
2326
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,8 @@ extension NetworkingCore.ShippingLabel {
716716
productNames: CopiableProp<[String]> = .copy,
717717
commercialInvoiceURL: NullableCopiableProp<String> = .copy,
718718
usedDate: NullableCopiableProp<Date> = .copy,
719-
expiryDate: NullableCopiableProp<Date> = .copy
719+
expiryDate: NullableCopiableProp<Date> = .copy,
720+
hazmatCategory: NullableCopiableProp<String> = .copy
720721
) -> NetworkingCore.ShippingLabel {
721722
let siteID = siteID ?? self.siteID
722723
let orderID = orderID ?? self.orderID
@@ -739,6 +740,7 @@ extension NetworkingCore.ShippingLabel {
739740
let commercialInvoiceURL = commercialInvoiceURL ?? self.commercialInvoiceURL
740741
let usedDate = usedDate ?? self.usedDate
741742
let expiryDate = expiryDate ?? self.expiryDate
743+
let hazmatCategory = hazmatCategory ?? self.hazmatCategory
742744

743745
return NetworkingCore.ShippingLabel(
744746
siteID: siteID,
@@ -761,7 +763,8 @@ extension NetworkingCore.ShippingLabel {
761763
productNames: productNames,
762764
commercialInvoiceURL: commercialInvoiceURL,
763765
usedDate: usedDate,
764-
expiryDate: expiryDate
766+
expiryDate: expiryDate,
767+
hazmatCategory: hazmatCategory
765768
)
766769
}
767770
}

Modules/Sources/NetworkingCore/Model/ShippingLabel/ShippingLabel.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public struct ShippingLabel: Equatable, Sendable, GeneratedCopiable, GeneratedFa
7171
/// Expiry date of the label
7272
public let expiryDate: Date?
7373

74+
/// Selected HAZMAT category of the label
75+
public let hazmatCategory: String?
76+
7477
public init(siteID: Int64,
7578
orderID: Int64,
7679
shippingLabelID: Int64,
@@ -91,7 +94,8 @@ public struct ShippingLabel: Equatable, Sendable, GeneratedCopiable, GeneratedFa
9194
productNames: [String],
9295
commercialInvoiceURL: String?,
9396
usedDate: Date?,
94-
expiryDate: Date?) {
97+
expiryDate: Date?,
98+
hazmatCategory: String?) {
9599
self.siteID = siteID
96100
self.orderID = orderID
97101
self.shippingLabelID = shippingLabelID
@@ -113,6 +117,7 @@ public struct ShippingLabel: Equatable, Sendable, GeneratedCopiable, GeneratedFa
113117
self.commercialInvoiceURL = commercialInvoiceURL
114118
self.usedDate = usedDate
115119
self.expiryDate = expiryDate
120+
self.hazmatCategory = hazmatCategory
116121
}
117122
}
118123

@@ -177,7 +182,8 @@ extension ShippingLabel: Decodable {
177182
productNames: productNames,
178183
commercialInvoiceURL: commercialInvoiceURL,
179184
usedDate: usedDate,
180-
expiryDate: expiryDate)
185+
expiryDate: expiryDate,
186+
hazmatCategory: nil) // hazmat category is not available in label details, will be updated later
181187
}
182188

183189
private enum CodingKeys: String, CodingKey {

Modules/Sources/Storage/Model/MIGRATIONS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations.
44

5+
## Model 125 (Release 23.2.0.0)
6+
- @itsmeichigo 2025-09-04
7+
- Added `hazmatCategory` attribute to `ShippingLabel` entity.
8+
59
## Model 124 (Release 22.9.0.0)
610
- @itsmeichigo 2025-07-11
711
- Added `WooShippingShipment` entity.

Modules/Sources/Storage/Model/ShippingLabel+CoreDataProperties.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ extension ShippingLabel {
3131
@NSManaged public var commercialInvoiceURL: String?
3232
@NSManaged public var usedDate: Date?
3333
@NSManaged public var expiryDate: Date?
34+
@NSManaged public var hazmatCategory: String?
3435

3536
}

Modules/Sources/Storage/Resources/WooCommerce.xcdatamodeld/.xccurrentversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<plist version="1.0">
44
<dict>
55
<key>_XCCurrentVersionName</key>
6-
<string>Model 124.xcdatamodel</string>
6+
<string>Model 125.xcdatamodel</string>
77
</dict>
88
</plist>

0 commit comments

Comments
 (0)