Skip to content

Commit b250a48

Browse files
committed
Adds helper to define which order status a new order should begint with
1 parent 5b03557 commit b250a48

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Yosemite
2+
3+
/// Helper that defines which `status` a new order should initially have.
4+
///
5+
struct NewOrderInitialStatusResolver {
6+
7+
/// Current site ID
8+
///
9+
private let siteID: Int64
10+
11+
/// Stores.
12+
///
13+
private let stores: StoresManager
14+
15+
/// Defines the WC version where `auto-draft` should be available.
16+
///
17+
private let draftMinSupportedVersion = "6.3.0"
18+
19+
/// WooCommerce plugin name.
20+
///
21+
private let wcPluginName = "WooCommerce"
22+
23+
24+
/// Decides the initial `status` for a new order based on the current store version.
25+
///
26+
func resolve(onCompletion: @escaping (OrderStatusEnum) -> ()) {
27+
let action = SystemStatusAction.fetchSystemPlugin(siteID: siteID, systemPluginName: wcPluginName) { wooPlugin in
28+
guard let wooPlugin = wooPlugin else {
29+
return onCompletion(.pending)
30+
}
31+
32+
// auto-draft should exists in versions greater than `6.3.0`
33+
switch draftMinSupportedVersion.compare(wooPlugin.version, options: .numeric) {
34+
case .orderedAscending, .orderedSame:
35+
onCompletion(.autoDraft)
36+
case .orderedDescending:
37+
onCompletion(.pending)
38+
}
39+
}
40+
ServiceLocator.stores.dispatch(action)
41+
}
42+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@
420420
24C5AC7625A53021008FD769 /* Embassy in Frameworks */ = {isa = PBXBuildFile; productRef = 247CE89B2583402A00F9D9D1 /* Embassy */; };
421421
24F98C502502AEE200F49B68 /* EventLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24F98C4F2502AEE200F49B68 /* EventLogging.swift */; };
422422
2602A63D27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2602A63C27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift */; };
423+
2602A63F27BD880A00B347F1 /* NewOrderInitialStatusResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2602A63E27BD880A00B347F1 /* NewOrderInitialStatusResolver.swift */; };
423424
260C315E2523CC4000157BC2 /* RefundProductsTotalViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260C315D2523CC4000157BC2 /* RefundProductsTotalViewModel.swift */; };
424425
260C31602524ECA900157BC2 /* IssueRefundViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260C315F2524ECA900157BC2 /* IssueRefundViewController.swift */; };
425426
260C31622524EEB200157BC2 /* IssueRefundViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 260C31612524EEB200157BC2 /* IssueRefundViewController.xib */; };
@@ -2058,6 +2059,7 @@
20582059
24F98C4F2502AEE200F49B68 /* EventLogging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventLogging.swift; sourceTree = "<group>"; };
20592060
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>"; };
20602061
2602A63C27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteOrderSynchronizer.swift; sourceTree = "<group>"; };
2062+
2602A63E27BD880A00B347F1 /* NewOrderInitialStatusResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewOrderInitialStatusResolver.swift; sourceTree = "<group>"; };
20612063
260C315D2523CC4000157BC2 /* RefundProductsTotalViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefundProductsTotalViewModel.swift; sourceTree = "<group>"; };
20622064
260C315F2524ECA900157BC2 /* IssueRefundViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueRefundViewController.swift; sourceTree = "<group>"; };
20632065
260C31612524EEB200157BC2 /* IssueRefundViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = IssueRefundViewController.xib; sourceTree = "<group>"; };
@@ -4526,6 +4528,7 @@
45264528
26C6439227B5DBE900DD00D1 /* OrderSynchronizer.swift */,
45274529
26C6439427B9A1B300DD00D1 /* LocalOrderSynchronizer.swift */,
45284530
2602A63C27BD3C8C00B347F1 /* RemoteOrderSynchronizer.swift */,
4531+
2602A63E27BD880A00B347F1 /* NewOrderInitialStatusResolver.swift */,
45294532
);
45304533
path = Synchronizer;
45314534
sourceTree = "<group>";
@@ -8397,6 +8400,7 @@
83978400
02817B39242B34560050AD8B /* ToolbarView.swift in Sources */,
83988401
D817586222BB64C300289CFE /* OrderDetailsNotices.swift in Sources */,
83998402
022F7A0324A05F6400012601 /* LinkedProductsListSelectorViewController.swift in Sources */,
8403+
2602A63F27BD880A00B347F1 /* NewOrderInitialStatusResolver.swift in Sources */,
84008404
E120F63826C26B550005A029 /* InPersonPaymentsLoadingView.swift in Sources */,
84018405
456417F4247D5434001203F6 /* UITableView+Helpers.swift in Sources */,
84028406
E15FC74326BC1D2700CF83E6 /* SafariSheet.swift in Sources */,

0 commit comments

Comments
 (0)