Skip to content

Commit aa774ac

Browse files
authored
Order details: Fix crash when reloading orders (#15764)
2 parents a54cd3e + 1737b8e commit aa774ac

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
22.7
55
-----
6+
- [*] Order Details: Fix crash when reloading data [https://github.com/woocommerce/woocommerce-ios/pull/15764]
67
- [*] Shipping Labels: Improved shipment management UI by hiding remove/merge options instead of disabling them, hiding merge option for orders with 2 or fewer unfulfilled shipments, and hiding the ellipsis menu when no remove/merge actions are available [https://github.com/woocommerce/woocommerce-ios/pull/15760]
78
- [**] POS: a POS tab in the tab bar is now available in the app for stores eligible for Point of Sale, instead of the previous entry point in the Menu tab. [https://github.com/woocommerce/woocommerce-ios/pull/15766]
89

WooCommerce/Classes/ViewModels/Order Details/OrderDetailsDataSource.swift

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,23 @@ final class OrderDetailsDataSource: NSObject {
136136

137137
/// Order shipment tracking list
138138
///
139-
var orderTracking: [ShipmentTracking] {
140-
return resultsControllers.orderTracking
141-
}
139+
var orderTracking: [ShipmentTracking] = []
142140

143141
/// Order statuses list
144142
///
145-
var currentSiteStatuses: [OrderStatus] {
146-
return resultsControllers.currentSiteStatuses
147-
}
143+
var currentSiteStatuses: [OrderStatus] = []
148144

149145
/// Products from an Order
150146
///
151-
var products: [Product] {
152-
return resultsControllers.products
153-
}
147+
var products: [Product] = []
148+
149+
/// Product variations from an order
150+
///
151+
var productVariations: [ProductVariation] = []
154152

155153
/// Custom amounts (fees) from an Order
156154
///
157-
var customAmounts: [OrderFeeLine] {
158-
return resultsControllers.feeLines
159-
}
155+
var customAmounts: [OrderFeeLine] = []
160156

161157
/// OrderItemsRefund Count
162158
///
@@ -166,19 +162,13 @@ final class OrderDetailsDataSource: NSObject {
166162

167163
/// Refunds on an Order
168164
///
169-
var refunds: [Refund] {
170-
return resultsControllers.refunds
171-
}
165+
var refunds: [Refund] = []
172166

173-
var addOnGroups: [AddOnGroup] {
174-
resultsControllers.addOnGroups
175-
}
167+
var addOnGroups: [AddOnGroup] = []
176168

177169
/// Shipping Methods list
178170
///
179-
var siteShippingMethods: [ShippingMethod] {
180-
resultsControllers.siteShippingMethods
181-
}
171+
var siteShippingMethods: [ShippingMethod] = []
182172

183173
/// Shipping Labels for an Order
184174
///
@@ -1171,7 +1161,7 @@ extension OrderDetailsDataSource {
11711161
}
11721162

11731163
private func lookUpProductVariation(productID: Int64, variationID: Int64) -> ProductVariation? {
1174-
return resultsControllers.productVariations.filter({ $0.productID == productID && $0.productVariationID == variationID }).first
1164+
return productVariations.filter({ $0.productID == productID && $0.productVariationID == variationID }).first
11751165
}
11761166

11771167
func lookUpRefund(by refundID: Int64) -> Refund? {
@@ -1195,12 +1185,20 @@ extension OrderDetailsDataSource {
11951185
@MainActor
11961186
func reloadSections() async {
11971187
// Freezes any data that require lookup after the sections are reloaded, in case the data from a ResultsController changes before the next reload.
1188+
refunds = resultsControllers.refunds
1189+
customAmounts = resultsControllers.feeLines
1190+
orderTracking = resultsControllers.orderTracking
1191+
currentSiteStatuses = resultsControllers.currentSiteStatuses
1192+
products = resultsControllers.products
1193+
addOnGroups = resultsControllers.addOnGroups
1194+
siteShippingMethods = resultsControllers.siteShippingMethods
1195+
productVariations = resultsControllers.productVariations
11981196
shippingLabels = resultsControllers.shippingLabels
11991197
shippingLabelOrderItemsAggregator = AggregatedShippingLabelOrderItems(
12001198
shippingLabels: shippingLabels,
12011199
orderItems: items,
12021200
products: products,
1203-
productVariations: resultsControllers.productVariations
1201+
productVariations: productVariations
12041202
)
12051203

12061204
var sections = buildStaticSections().compactMap { $0 }

0 commit comments

Comments
 (0)