Skip to content

Commit cd50cc2

Browse files
authored
Merge pull request #6145 from woocommerce/issue/6127-order-sync-protocol
Order Creation: Adds OrderSynchronizer Protocol
2 parents 0b840fd + 0a36564 commit cd50cc2

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import Foundation
2+
import Yosemite
3+
import Combine
4+
5+
/// Possible states of an `OrderSynchronizer` type.
6+
///
7+
enum OrderSyncState {
8+
case syncing
9+
case synced
10+
case error(Error)
11+
}
12+
13+
/// Product input for an `OrderSynchronizer` type.
14+
///
15+
struct OrderSyncProductInput {
16+
/// Types of products the synchronizer supports
17+
///
18+
enum ProductType {
19+
case product(Product)
20+
case variation(ProductVariation)
21+
}
22+
let product: ProductType
23+
let quantity: Int
24+
}
25+
26+
/// Addresses input for an `OrderSynchronizer` type.
27+
///
28+
struct OrderSyncAddressesInput {
29+
let billing: Address
30+
let shipping: Address
31+
}
32+
33+
/// A type that receives "supported" order properties and keeps it synced against another source.
34+
///
35+
protocol OrderSynchronizer {
36+
37+
// MARK: Outputs
38+
39+
/// Defines the current sync state of the synchronizer.
40+
///
41+
var state: Published<OrderSyncState> { get }
42+
43+
/// Defines the latest order to be synced or that is synced.
44+
///
45+
var order: Published<Order> { get }
46+
47+
// MARK: Inputs
48+
49+
/// Changes the underlaying order status.
50+
/// This property is not synched remotely until `commitAllChanges` method is invoked.
51+
///
52+
var setStatus: PassthroughSubject<OrderStatusEnum, Never> { get }
53+
54+
/// Sets a product with it's quantity.
55+
/// Set a `zero` quantity to remove a product.
56+
///
57+
var setProduct: PassthroughSubject<OrderSyncProductInput, Never> { get }
58+
59+
/// Sets or removes the order shipping & billing addresses.
60+
///
61+
var setAddresses: PassthroughSubject<OrderSyncAddressesInput?, Never> { get }
62+
63+
/// Sets or removes a shipping line.
64+
///
65+
var setShipping: PassthroughSubject<ShippingLine?, Never> { get }
66+
67+
/// Sets or removes an order fee.
68+
///
69+
var setFee: PassthroughSubject<OrderFeeLine?, Never> { get }
70+
71+
/// Retires the order sync. State needs to be in `.error` to initiate work.
72+
///
73+
func retrySync()
74+
75+
/// Commits all order changes to the remote source. State needs to be in `.synced` to initiate work.
76+
///
77+
func commitAllChanges(onCompletion: (Result<Order, Error>) -> Void)
78+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@
494494
26B98758273C5BE30090E8CA /* EditCustomerNoteViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B98757273C5BE30090E8CA /* EditCustomerNoteViewModelProtocol.swift */; };
495495
26B9875D273C6A830090E8CA /* SimplePaymentsNoteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B9875C273C6A830090E8CA /* SimplePaymentsNoteViewModel.swift */; };
496496
26B9875F273CB6AA0090E8CA /* SimplePaymentsNoteViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B9875E273CB6AA0090E8CA /* SimplePaymentsNoteViewModelTests.swift */; };
497+
26C6439327B5DBE900DD00D1 /* OrderSynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26C6439227B5DBE900DD00D1 /* OrderSynchronizer.swift */; };
497498
26C6E8E026E2B7BD00C7BB0F /* CountrySelectorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26C6E8DF26E2B7BD00C7BB0F /* CountrySelectorViewModel.swift */; };
498499
26C6E8E426E2D87C00C7BB0F /* CountrySelectorViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26C6E8E326E2D87C00C7BB0F /* CountrySelectorViewModelTests.swift */; };
499500
26C6E8E626E6B5F500C7BB0F /* StateSelectorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26C6E8E526E6B5F500C7BB0F /* StateSelectorViewModel.swift */; };
@@ -2115,6 +2116,7 @@
21152116
26B98757273C5BE30090E8CA /* EditCustomerNoteViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCustomerNoteViewModelProtocol.swift; sourceTree = "<group>"; };
21162117
26B9875C273C6A830090E8CA /* SimplePaymentsNoteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplePaymentsNoteViewModel.swift; sourceTree = "<group>"; };
21172118
26B9875E273CB6AA0090E8CA /* SimplePaymentsNoteViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplePaymentsNoteViewModelTests.swift; sourceTree = "<group>"; };
2119+
26C6439227B5DBE900DD00D1 /* OrderSynchronizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderSynchronizer.swift; sourceTree = "<group>"; };
21182120
26C6E8DF26E2B7BD00C7BB0F /* CountrySelectorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountrySelectorViewModel.swift; sourceTree = "<group>"; };
21192121
26C6E8E326E2D87C00C7BB0F /* CountrySelectorViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountrySelectorViewModelTests.swift; sourceTree = "<group>"; };
21202122
26C6E8E526E6B5F500C7BB0F /* StateSelectorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateSelectorViewModel.swift; sourceTree = "<group>"; };
@@ -4474,6 +4476,14 @@
44744476
path = Summary;
44754477
sourceTree = "<group>";
44764478
};
4479+
26C6439127B5DBE900DD00D1 /* Synchronizer */ = {
4480+
isa = PBXGroup;
4481+
children = (
4482+
26C6439227B5DBE900DD00D1 /* OrderSynchronizer.swift */,
4483+
);
4484+
path = Synchronizer;
4485+
sourceTree = "<group>";
4486+
};
44774487
26C6E8E126E2D85300C7BB0F /* Addresses */ = {
44784488
isa = PBXGroup;
44794489
children = (
@@ -6484,6 +6494,7 @@
64846494
children = (
64856495
CCFC50542743BC0D001E505F /* NewOrder.swift */,
64866496
CCFC50582743E021001E505F /* NewOrderViewModel.swift */,
6497+
26C6439127B5DBE900DD00D1 /* Synchronizer */,
64876498
AE264C05275A495E00B52996 /* FlowCoordinator */,
64886499
CC200BAF27847D9300EC5884 /* PaymentSection */,
64896500
CC53FB3627551A8700C4CA4F /* ProductsSection */,
@@ -8241,6 +8252,7 @@
82418252
CE32B11A20BF8E32006FBCF4 /* UIButton+Helpers.swift in Sources */,
82428253
45BBFBC5274FDCE900213001 /* HubMenu.swift in Sources */,
82438254
02A9BCD62737F73C00159C79 /* JetpackBenefitItem.swift in Sources */,
8255+
26C6439327B5DBE900DD00D1 /* OrderSynchronizer.swift in Sources */,
82448256
CE0F17D222A8308900964A63 /* FancyAlertController+PurchaseNote.swift in Sources */,
82458257
E1BAAEA026BBECEF00F2C037 /* ButtonStyles.swift in Sources */,
82468258
CC13C0CB278E021300C0B5B5 /* AddProductVariationToOrderViewModel.swift in Sources */,

0 commit comments

Comments
 (0)