Skip to content

Commit 3e82715

Browse files
joshhealdclaude
andcommitted
[Local catalog] Add explicit local catalog flag to factory
- Add isLocalCatalogEnabled parameter to factory init - Replace implicit GRDB presence check with explicit flag check - Remove side-effecty localSearchStrategy helper method - Add stub implementation for trackSearchLocalResultsFetchComplete - Pass isLocalCatalogEligible flag when creating factories in POSTabCoordinator - Convert lazy factory properties to factory methods with eligibility parameter - Makes intent clear and improves testability The factory now explicitly checks the isLocalCatalogEnabled flag rather than relying on the presence of GRDBManager to determine which search strategy to use. This makes the behavior more predictable and testable. The POSTabCoordinator now dynamically creates factories with the current eligibility state each time POS is presented, ensuring the correct search strategy is used based on real-time eligibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent a3af88b commit 3e82715

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

Modules/Sources/PointOfSale/Analytics/POSItemFetchAnalytics.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@ struct POSItemFetchAnalytics: POSItemFetchAnalyticsTracking {
4343
)
4444
)
4545
}
46+
47+
/// Tracks when a local search results fetch completes
48+
/// - Parameters:
49+
/// - milliseconds: The time taken to fetch results in milliseconds
50+
/// - totalItems: The total number of items found in the search
51+
func trackSearchLocalResultsFetchComplete(millisecondsSinceRequestSent: Int, totalItems: Int) {
52+
// TODO: Implement analytics event for local search results
53+
// This will be implemented in the final PR
54+
}
4655
}

Modules/Sources/Yosemite/PointOfSale/Items/PointOfSaleItemFetchStrategyFactory.swift

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ public final class PointOfSaleItemFetchStrategyFactory: PointOfSaleItemFetchStra
1818
private let productsRemote: ProductsRemote
1919
private let variationsRemote: ProductVariationsRemote
2020
private let grdbManager: GRDBManagerProtocol?
21+
private let isLocalCatalogEnabled: Bool
2122

2223
public init(siteID: Int64,
2324
credentials: Credentials?,
2425
selectedSite: AnyPublisher<JetpackSite?, Never>? = nil,
2526
appPasswordSupportState: AnyPublisher<Bool, Never>? = nil,
26-
grdbManager: GRDBManagerProtocol? = nil) {
27+
grdbManager: GRDBManagerProtocol? = nil,
28+
isLocalCatalogEnabled: Bool = false) {
2729
self.siteID = siteID
2830
let network = AlamofireNetwork(credentials: credentials,
2931
selectedSite: selectedSite,
3032
appPasswordSupportState: appPasswordSupportState)
3133
self.productsRemote = ProductsRemote(network: network)
3234
self.variationsRemote = ProductVariationsRemote(network: network)
3335
self.grdbManager = grdbManager
36+
self.isLocalCatalogEnabled = isLocalCatalogEnabled
3437
}
3538

3639
public func defaultStrategy(analytics: POSItemFetchAnalyticsTracking) -> PointOfSalePurchasableItemFetchStrategy {
@@ -41,9 +44,13 @@ public final class PointOfSaleItemFetchStrategyFactory: PointOfSaleItemFetchStra
4144
}
4245
public func searchStrategy(searchTerm: String,
4346
analytics: POSItemFetchAnalyticsTracking) -> PointOfSalePurchasableItemFetchStrategy {
44-
// Use local search if GRDB manager is available, otherwise fall back to remote search
45-
if let localStrategy = localSearchStrategy(searchTerm: searchTerm, analytics: analytics) {
46-
return localStrategy
47+
// Use local search if explicitly enabled and GRDB manager is available
48+
if isLocalCatalogEnabled, let grdbManager = grdbManager {
49+
return PointOfSaleLocalSearchPurchasableItemFetchStrategy(siteID: siteID,
50+
searchTerm: searchTerm,
51+
grdbManager: grdbManager,
52+
variationsRemote: variationsRemote,
53+
analytics: analytics)
4754
}
4855
return PointOfSaleSearchPurchasableItemFetchStrategy(siteID: siteID,
4956
searchTerm: searchTerm,
@@ -58,26 +65,6 @@ public final class PointOfSaleItemFetchStrategyFactory: PointOfSaleItemFetchStra
5865
productsRemote: productsRemote,
5966
variationsRemote: variationsRemote)
6067
}
61-
62-
/// Creates a local search strategy using the GRDB catalog
63-
/// - Parameters:
64-
/// - searchTerm: The search term to query
65-
/// - analytics: Analytics tracker
66-
/// - pageSize: Number of items per page (default: 25)
67-
/// - Returns: A local search strategy if GRDB manager is available, otherwise nil
68-
public func localSearchStrategy(searchTerm: String,
69-
analytics: POSItemFetchAnalyticsTracking,
70-
pageSize: Int = 25) -> PointOfSalePurchasableItemFetchStrategy? {
71-
guard let grdbManager else {
72-
return nil
73-
}
74-
return PointOfSaleLocalSearchPurchasableItemFetchStrategy(siteID: siteID,
75-
searchTerm: searchTerm,
76-
grdbManager: grdbManager,
77-
variationsRemote: variationsRemote,
78-
analytics: analytics,
79-
pageSize: pageSize)
80-
}
8168
}
8269

8370
public final class PointOfSaleFixedItemFetchStrategyFactory: PointOfSaleItemFetchStrategyFactoryProtocol {

WooCommerce/Classes/POS/TabBar/POSTabCoordinator.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@ final class POSTabCoordinator {
4747
/// Local catalog eligibility service - created asynchronously during init
4848
private(set) var localCatalogEligibilityService: POSLocalCatalogEligibilityServiceProtocol?
4949

50-
private lazy var posItemFetchStrategyFactory: PointOfSaleItemFetchStrategyFactory = {
50+
/// Creates item fetch strategy factory with current local catalog eligibility
51+
private func createItemFetchStrategyFactory(isLocalCatalogEnabled: Bool) -> PointOfSaleItemFetchStrategyFactory {
5152
PointOfSaleItemFetchStrategyFactory(siteID: siteID,
5253
credentials: credentials,
5354
selectedSite: defaultSitePublisher,
5455
appPasswordSupportState: isAppPasswordSupported,
55-
grdbManager: ServiceLocator.grdbManager)
56-
}()
56+
grdbManager: ServiceLocator.grdbManager,
57+
isLocalCatalogEnabled: isLocalCatalogEnabled)
58+
}
5759

58-
private lazy var posPopularItemFetchStrategyFactory: PointOfSaleFixedItemFetchStrategyFactory = {
59-
PointOfSaleFixedItemFetchStrategyFactory(fixedStrategy: posItemFetchStrategyFactory.popularStrategy())
60-
}()
60+
/// Creates popular item fetch strategy factory with current local catalog eligibility
61+
private func createPopularItemFetchStrategyFactory(isLocalCatalogEnabled: Bool) -> PointOfSaleFixedItemFetchStrategyFactory {
62+
let itemFactory = createItemFetchStrategyFactory(isLocalCatalogEnabled: isLocalCatalogEnabled)
63+
return PointOfSaleFixedItemFetchStrategyFactory(fixedStrategy: itemFactory.popularStrategy())
64+
}
6165

6266
private lazy var posCouponFetchStrategyFactory: PointOfSaleCouponFetchStrategyFactory = {
6367
PointOfSaleCouponFetchStrategyFactory(siteID: siteID,
@@ -230,8 +234,8 @@ private extension POSTabCoordinator {
230234
appPasswordSupportState: isAppPasswordSupported) {
231235
let posView = PointOfSaleEntryPointView(
232236
siteID: siteID,
233-
itemFetchStrategyFactory: posItemFetchStrategyFactory,
234-
popularItemFetchStrategyFactory: posPopularItemFetchStrategyFactory,
237+
itemFetchStrategyFactory: createItemFetchStrategyFactory(isLocalCatalogEnabled: isLocalCatalogEligible),
238+
popularItemFetchStrategyFactory: createPopularItemFetchStrategyFactory(isLocalCatalogEnabled: isLocalCatalogEligible),
235239
couponProvider: posCouponProvider,
236240
couponFetchStrategyFactory: posCouponFetchStrategyFactory,
237241
orderListFetchStrategyFactory: POSOrderListFetchStrategyFactory(

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16594,6 +16594,7 @@
1659416594
"$(inherited)",
1659516595
"@executable_path/Frameworks",
1659616596
);
16597+
MARKETING_VERSION = 23.8;
1659716598
OTHER_SWIFT_FLAGS = "$(inherited)";
1659816599
PRODUCT_BUNDLE_IDENTIFIER = com.automattic.alpha.woocommerce;
1659916600
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -17399,6 +17400,7 @@
1739917400
"$(inherited)",
1740017401
"@executable_path/Frameworks",
1740117402
);
17403+
MARKETING_VERSION = 23.8;
1740217404
OTHER_SWIFT_FLAGS = "$(inherited)";
1740317405
PRODUCT_BUNDLE_IDENTIFIER = com.automattic.woocommerce;
1740417406
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -17428,6 +17430,7 @@
1742817430
"$(inherited)",
1742917431
"@executable_path/Frameworks",
1743017432
);
17433+
MARKETING_VERSION = 23.8;
1743117434
OTHER_SWIFT_FLAGS = "$(inherited)";
1743217435
PRODUCT_BUNDLE_IDENTIFIER = com.automattic.woocommerce;
1743317436
PRODUCT_NAME = "$(TARGET_NAME)";

0 commit comments

Comments
 (0)