Skip to content

Commit bc43663

Browse files
authored
Merge pull request #6199 from woocommerce/issue/6129-basic-remote-synchronizer
Order Creation: Adds empty RemoteOrderSynchronizer
2 parents e94ec2e + d07e106 commit bc43663

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

Experiments/Experiments/DefaultFeatureFlagService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
2727
return true
2828
case .orderCreation:
2929
return buildConfig == .localDeveloper || buildConfig == .alpha
30+
case .orderCreationRemoteSynchronizer:
31+
return false
3032
case .hubMenu:
3133
return true
3234
case .systemStatusReport:

Experiments/Experiments/FeatureFlag.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public enum FeatureFlag: Int {
5454
///
5555
case orderCreation
5656

57+
/// Allows new orders to be created and synced as drafts
58+
///
59+
case orderCreationRemoteSynchronizer
60+
5761
/// Display the new tab "Menu" in the tab bar.
5862
///
5963
case hubMenu

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrderViewModel.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ final class NewOrderViewModel: ObservableObject {
161161
stores: StoresManager = ServiceLocator.stores,
162162
storageManager: StorageManagerType = ServiceLocator.storageManager,
163163
currencySettings: CurrencySettings = ServiceLocator.currencySettings,
164-
analytics: Analytics = ServiceLocator.analytics) {
164+
analytics: Analytics = ServiceLocator.analytics,
165+
enableRemoteSync: Bool = ServiceLocator.featureFlagService.isFeatureFlagEnabled(.orderCreationRemoteSynchronizer)) {
165166
self.siteID = siteID
166167
self.stores = stores
167168
self.storageManager = storageManager
168169
self.currencyFormatter = CurrencyFormatter(currencySettings: currencySettings)
169170
self.analytics = analytics
170-
self.orderSynchronizer = LocalOrderSynchronizer(siteID: siteID, stores: stores)
171+
self.orderSynchronizer = enableRemoteSync ? RemoteOrderSynchronizer(siteID: siteID, stores: stores)
172+
: LocalOrderSynchronizer(siteID: siteID, stores: stores)
171173

172174
configureNavigationTrailingItem()
173175
configureStatusBadgeViewModel()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import Foundation
2+
import Yosemite
3+
import Combine
4+
5+
/// Type that syncs the order with the remote server.
6+
///
7+
final class RemoteOrderSynchronizer: OrderSynchronizer {
8+
9+
// MARK: Outputs
10+
11+
@Published private(set) var state: OrderSyncState = .synced
12+
13+
var statePublisher: Published<OrderSyncState>.Publisher {
14+
$state
15+
}
16+
17+
@Published private(set) var order: Order = OrderFactory.emptyNewOrder
18+
19+
var orderPublisher: Published<Order>.Publisher {
20+
$order
21+
}
22+
23+
// MARK: Inputs
24+
25+
var setStatus = PassthroughSubject<OrderStatusEnum, Never>()
26+
27+
var setProduct = PassthroughSubject<OrderSyncProductInput, Never>()
28+
29+
var setAddresses = PassthroughSubject<OrderSyncAddressesInput?, Never>()
30+
31+
var setShipping = PassthroughSubject<ShippingLine?, Never>()
32+
33+
var setFee = PassthroughSubject<OrderFeeLine?, Never>()
34+
35+
// MARK: Private properties
36+
37+
private let siteID: Int64
38+
39+
private let stores: StoresManager
40+
41+
// MARK: Initializers
42+
43+
init(siteID: Int64, stores: StoresManager = ServiceLocator.stores) {
44+
self.siteID = siteID
45+
self.stores = stores
46+
}
47+
48+
// MARK: Methods
49+
func retrySync() {
50+
// TODO: Implement
51+
}
52+
53+
/// Creates the order remotely.
54+
///
55+
func commitAllChanges(onCompletion: @escaping (Result<Order, Error>) -> Void) {
56+
// TODO: Implement
57+
}
58+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@
419419
247CE8A6258340E600F9D9D1 /* ScreenshotImages.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 247CE8A5258340E600F9D9D1 /* ScreenshotImages.xcassets */; };
420420
24C5AC7625A53021008FD769 /* Embassy in Frameworks */ = {isa = PBXBuildFile; productRef = 247CE89B2583402A00F9D9D1 /* Embassy */; };
421421
24F98C502502AEE200F49B68 /* EventLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F98C4F2502AEE200F49B68 /* EventLogging.swift */; };
422+
2602A63D27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2602A63C27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift */; };
422423
260C315E2523CC4000157BC2 /* RefundProductsTotalViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260C315D2523CC4000157BC2 /* RefundProductsTotalViewModel.swift */; };
423424
260C31602524ECA900157BC2 /* IssueRefundViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260C315F2524ECA900157BC2 /* IssueRefundViewController.swift */; };
424425
260C31622524EEB200157BC2 /* IssueRefundViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 260C31612524EEB200157BC2 /* IssueRefundViewController.xib */; };
@@ -2056,6 +2057,7 @@
20562057
24C579D124F476300076E1B4 /* Woo-Alpha.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Woo-Alpha.entitlements"; sourceTree = "<group>"; };
20572058
24F98C4F2502AEE200F49B68 /* EventLogging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventLogging.swift; sourceTree = "<group>"; };
20582059
25D00C97936D2C6589F8ECE9 /* Pods-WooCommerce.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WooCommerce.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-WooCommerce/Pods-WooCommerce.release-alpha.xcconfig"; sourceTree = "<group>"; };
2060+
2602A63C27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteOrderSynchronizer.swift; sourceTree = "<group>"; };
20592061
260C315D2523CC4000157BC2 /* RefundProductsTotalViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundProductsTotalViewModel.swift; sourceTree = "<group>"; };
20602062
260C315F2524ECA900157BC2 /* IssueRefundViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueRefundViewController.swift; sourceTree = "<group>"; };
20612063
260C31612524EEB200157BC2 /* IssueRefundViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = IssueRefundViewController.xib; sourceTree = "<group>"; };
@@ -4523,6 +4525,7 @@
45234525
children = (
45244526
26C6439227B5DBE900DD00D1 /* OrderSynchronizer.swift */,
45254527
26C6439427B9A1B300DD00D1 /* LocalOrderSynchronizer.swift */,
4528+
2602A63C27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift */,
45264529
);
45274530
path = Synchronizer;
45284531
sourceTree = "<group>";
@@ -8663,6 +8666,7 @@
86638666
DEDB886B26E8531E00981595 /* ShippingLabelPackageAttributes.swift in Sources */,
86648667
AEC95D412774C5AE001571F5 /* AddressFormViewModelProtocol.swift in Sources */,
86658668
B6E851F5276330200041D1BA /* RefundFeesDetailsTableViewCell.swift in Sources */,
8669+
2602A63D27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift in Sources */,
86668670
B57C744A20F5649300EEFC87 /* EmptyStoresTableViewCell.swift in Sources */,
86678671
45DB70602614C7E80064A6CF /* ShippingLabelPackageDetailsResultsControllers.swift in Sources */,
86688672
027D67D1245ADDF40036B8DB /* FilterTypeViewModel+Helpers.swift in Sources */,

0 commit comments

Comments
 (0)