Skip to content

Commit 0429875

Browse files
authored
Merge release/22.4 into trunk (#15666)
2 parents a96b095 + b81f168 commit 0429875

39 files changed

+1663
-520
lines changed

WooCommerce/Classes/Extensions/SitePlugin+Woo.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import Yosemite
44
///
55
extension SitePlugin {
66
enum SupportedPlugin {
7-
public static let LegacyWCShip = "WooCommerce Shipping & Tax"
8-
public static let WooShipping = ["Woo Shipping", "WooCommerce Shipping"]
97
public static let WCTracking = "WooCommerce Shipment Tracking"
108
public static let WCSubscriptions = ["WooCommerce Subscriptions", "Woo Subscriptions"]
119
public static let WCProductBundles = ["WooCommerce Product Bundles", "Woo Product Bundles"]
@@ -14,4 +12,9 @@ extension SitePlugin {
1412
public static let WCGiftCards = ["WooCommerce Gift Cards", "Woo Gift Cards"]
1513
public static let GoogleForWooCommerce = ["Google Listings and Ads", "Google for WooCommerce"]
1614
}
15+
16+
enum SupportedPluginPath {
17+
public static let LegacyWCShip = "woocommerce-services/woocommerce-services.php"
18+
public static let WooShipping = "woocommerce-shipping/woocommerce-shipping.php"
19+
}
1720
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ final class OrderDetailsDataSource: NSObject {
9090
///
9191
var shouldAllowWCShipInstallation: Bool {
9292
let isFeatureFlagEnabled = featureFlags.isFeatureFlagEnabled(.shippingLabelsOnboardingM1)
93-
let plugin = resultsControllers.sitePlugins.first { $0.name == SitePlugin.SupportedPlugin.LegacyWCShip }
93+
let plugin = resultsControllers.sitePlugins.first { $0.plugin == SitePlugin.SupportedPluginPath.LegacyWCShip }
9494
let isPluginInstalled = plugin != nil && resultsControllers.sitePlugins.count > 0
9595
let isPluginActive = plugin?.status.isActive ?? false
9696
let isCountryCodeUS = SiteAddress(siteSettings: siteSettings).countryCode == CountryCode.US

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -795,19 +795,19 @@ extension OrderDetailsViewModel {
795795
return false
796796
}
797797

798-
guard await !isPluginActive(SitePlugin.SupportedPlugin.LegacyWCShip) else {
798+
guard await !isPluginActive(pluginPath: SitePlugin.SupportedPluginPath.LegacyWCShip) else {
799799
return true
800800
}
801801

802-
return await isPluginActive(SitePlugin.SupportedPlugin.WooShipping)
802+
return await isPluginActive(pluginPath: SitePlugin.SupportedPluginPath.WooShipping)
803803
}
804804

805805
/// Checks if the Woo Shipping extension is active, with the minimum version required for its shipping label flow.
806806
///
807807
@MainActor
808808
func isWooShippingSupported() async -> Bool {
809809
guard featureFlagService.isFeatureFlagEnabled(.revampedShippingLabelCreation),
810-
let plugin = await fetchPlugin(SitePlugin.SupportedPlugin.WooShipping) else {
810+
let plugin = await fetchPluginByPath(SitePlugin.SupportedPluginPath.WooShipping) else {
811811
return false
812812
}
813813

@@ -884,7 +884,7 @@ extension OrderDetailsViewModel {
884884
///
885885
private func isPluginActive(_ pluginNames: [String], completion: @escaping (Bool) -> (Void)) {
886886
Task { @MainActor in
887-
let plugin = await fetchPlugin(pluginNames)
887+
let plugin = await fetchPluginByNames(pluginNames)
888888
completion(plugin?.active == true)
889889
}
890890
}
@@ -893,7 +893,7 @@ extension OrderDetailsViewModel {
893893
/// Additionally it logs to tracks if the plugin store is accessed without it being in sync so we can handle that edge-case if it happens recurrently.
894894
///
895895
@MainActor
896-
private func fetchPlugin(_ pluginNames: [String]) async -> SystemPlugin? {
896+
private func fetchPluginByNames(_ pluginNames: [String]) async -> SystemPlugin? {
897897
guard arePluginsSynced() else {
898898
DDLogError("⚠️ SystemPlugins accessed without being in sync.")
899899
ServiceLocator.analytics.track(event: WooAnalyticsEvent.Orders.pluginsNotSyncedYet())
@@ -907,6 +907,24 @@ extension OrderDetailsViewModel {
907907
}
908908
}
909909

910+
/// Fetches a plugin from storage, based on the provided plugin path.
911+
/// Additionally it logs to tracks if the plugin store is accessed without it being in sync so we can handle that edge-case if it happens recurrently.
912+
///
913+
@MainActor
914+
private func fetchPluginByPath(_ path: String) async -> SystemPlugin? {
915+
guard arePluginsSynced() else {
916+
DDLogError("⚠️ SystemPlugins accessed without being in sync.")
917+
ServiceLocator.analytics.track(event: WooAnalyticsEvent.Orders.pluginsNotSyncedYet())
918+
return nil
919+
}
920+
921+
return await withCheckedContinuation { continuation in
922+
stores.dispatch(SystemStatusAction.fetchSystemPluginWithPath(siteID: order.siteID, pluginPath: path, onCompletion: { plugin in
923+
continuation.resume(returning: plugin)
924+
}))
925+
}
926+
}
927+
910928
/// Function that checks for any existing system plugin in the order's store.
911929
/// If there is none, we assume plugins are not synced because at least the`WooCommerce` plugin should be present.
912930
///
@@ -944,6 +962,12 @@ private extension OrderDetailsViewModel {
944962
}
945963
}
946964
}
965+
966+
@MainActor
967+
func isPluginActive(pluginPath: String) async -> Bool {
968+
let plugin = await fetchPluginByPath(pluginPath)
969+
return plugin?.active == true
970+
}
947971
}
948972

949973
extension OrderDetailsViewModel {

0 commit comments

Comments
 (0)