Skip to content

Commit 42aefd1

Browse files
authored
Merge pull request #6391 from woocommerce/issue/fix-creating-products-with-local-synchronizer
2 parents f0ae7a8 + a23efe1 commit 42aefd1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/Synchronizer/LocalOrderSynchronizer.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class LocalOrderSynchronizer: OrderSynchronizer {
5656
/// Creates the order remotely.
5757
///
5858
func commitAllChanges(onCompletion: @escaping (Result<Order, Error>) -> Void) {
59-
let action = OrderAction.createOrder(siteID: siteID, order: order, onCompletion: onCompletion)
59+
let action = OrderAction.createOrder(siteID: siteID, order: order.removingItemIDs(), onCompletion: onCompletion)
6060
stores.dispatch(action)
6161
}
6262
}
@@ -112,3 +112,14 @@ private extension LocalOrderSynchronizer {
112112
return input.updating(id: Int64(UUID().uuidString.hashValue))
113113
}
114114
}
115+
116+
// MARK: Order Helpers
117+
private extension Order {
118+
/// Removes the `itemID` values from items.
119+
/// This is needed to create the item without the random generated ID, the remote API would fail otherwise.
120+
func removingItemIDs() -> Order {
121+
copy (
122+
items: items.map { $0.copy(itemID: .zero, subtotal: "", total: "") }
123+
)
124+
}
125+
}

0 commit comments

Comments
 (0)