Skip to content

Commit 558285c

Browse files
authored
[Woo POS] Restore checkStoreCouponSettings to PointOfSaleCouponService (#15481)
2 parents 64c61f8 + 90d1e8f commit 558285c

File tree

10 files changed

+848
-607
lines changed

10 files changed

+848
-607
lines changed

Yosemite/Yosemite.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
012848DC2D9ED55B00A9C69B /* SettingStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012848DB2D9ED55700A9C69B /* SettingStoreMethods.swift */; };
11+
012848DE2D9EDAC100A9C69B /* MockCouponStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012848DD2D9EDAC100A9C69B /* MockCouponStoreMethods.swift */; };
12+
012848E22D9EDF2D00A9C69B /* MockSettingStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012848E12D9EDF2D00A9C69B /* MockSettingStoreMethods.swift */; };
1013
0139C2B02D91D1C600C78FDE /* POSCart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0139C2AF2D91D1C400C78FDE /* POSCart.swift */; };
1114
016A776B2D9D30C90004FCD6 /* PointOfSaleCouponServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A776A2D9D30C10004FCD6 /* PointOfSaleCouponServiceTests.swift */; };
12-
016A89D82D9D6DB50004FCD6 /* CouponService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A89D72D9D6DAE0004FCD6 /* CouponService.swift */; };
15+
016A89D82D9D6DB50004FCD6 /* CouponStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A89D72D9D6DAE0004FCD6 /* CouponStoreMethods.swift */; };
1316
016EFCAE2C4155650016BDAA /* OrderItem+BasePrice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016EFCAD2C4155650016BDAA /* OrderItem+BasePrice.swift */; };
1417
016EFCB02C41559D0016BDAA /* OrderItem+BasePriceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016EFCAF2C41559D0016BDAA /* OrderItem+BasePriceTests.swift */; };
1518
01AAD8122D92DE110081D60B /* CouponsError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01AAD8112D92DE0F0081D60B /* CouponsError.swift */; };
@@ -556,9 +559,12 @@
556559
/* End PBXCopyFilesBuildPhase section */
557560

558561
/* Begin PBXFileReference section */
562+
012848DB2D9ED55700A9C69B /* SettingStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingStoreMethods.swift; sourceTree = "<group>"; };
563+
012848DD2D9EDAC100A9C69B /* MockCouponStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCouponStoreMethods.swift; sourceTree = "<group>"; };
564+
012848E12D9EDF2D00A9C69B /* MockSettingStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSettingStoreMethods.swift; sourceTree = "<group>"; };
559565
0139C2AF2D91D1C400C78FDE /* POSCart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSCart.swift; sourceTree = "<group>"; };
560566
016A776A2D9D30C10004FCD6 /* PointOfSaleCouponServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleCouponServiceTests.swift; sourceTree = "<group>"; };
561-
016A89D72D9D6DAE0004FCD6 /* CouponService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponService.swift; sourceTree = "<group>"; };
567+
016A89D72D9D6DAE0004FCD6 /* CouponStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponStoreMethods.swift; sourceTree = "<group>"; };
562568
016EFCAD2C4155650016BDAA /* OrderItem+BasePrice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderItem+BasePrice.swift"; sourceTree = "<group>"; };
563569
016EFCAF2C41559D0016BDAA /* OrderItem+BasePriceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OrderItem+BasePriceTests.swift"; sourceTree = "<group>"; };
564570
01AAD8112D92DE0F0081D60B /* CouponsError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponsError.swift; sourceTree = "<group>"; };
@@ -1118,7 +1124,8 @@
11181124
016A89D42D9D6D980004FCD6 /* Helpers */ = {
11191125
isa = PBXGroup;
11201126
children = (
1121-
016A89D72D9D6DAE0004FCD6 /* CouponService.swift */,
1127+
012848DB2D9ED55700A9C69B /* SettingStoreMethods.swift */,
1128+
016A89D72D9D6DAE0004FCD6 /* CouponStoreMethods.swift */,
11221129
);
11231130
path = Helpers;
11241131
sourceTree = "<group>";
@@ -1998,6 +2005,8 @@
19982005
B5C9DE1D2087FF20006B910A /* Mocks */ = {
19992006
isa = PBXGroup;
20002007
children = (
2008+
012848E12D9EDF2D00A9C69B /* MockSettingStoreMethods.swift */,
2009+
012848DD2D9EDAC100A9C69B /* MockCouponStoreMethods.swift */,
20012010
20CF75B72CF4C3AD00ACCF4A /* MockPOSOrdersRemote.swift */,
20022011
6801E41B2D1007D000F9DF46 /* MockPOSReceiptsRemote.swift */,
20032012
207D2D1C2CFA0CEF00F79204 /* MockPOSOrderableItem.swift */,
@@ -2408,7 +2417,7 @@
24082417
CE4FD4522350FB5400A16B31 /* OrderItemTaxRefund+ReadOnlyConvertible.swift in Sources */,
24092418
31A89EE6278CC38F002A588E /* StripeAccount+PaymentGatewayAccount.swift in Sources */,
24102419
02FF055223D983F30058E6E7 /* MediaExportService.swift in Sources */,
2411-
016A89D82D9D6DB50004FCD6 /* CouponService.swift in Sources */,
2420+
016A89D82D9D6DB50004FCD6 /* CouponStoreMethods.swift in Sources */,
24122421
45010695239A6CDE00E24722 /* TaxAction.swift in Sources */,
24132422
B9DFE4C02AA2136100174004 /* TaxRate+ReadOnlyConvertible.swift in Sources */,
24142423
03FBDA222631521100ACE257 /* CouponAction.swift in Sources */,
@@ -2629,6 +2638,7 @@
26292638
B93E03282A960CAD009CA9C1 /* TaxBasedOnSetting.swift in Sources */,
26302639
CE12FBDB221F406100C59248 /* OrderStatus+ReadOnlyConvertible.swift in Sources */,
26312640
74D42DBC221C983F00B4977D /* ShipmentTracking+ReadOnlyConvertible.swift in Sources */,
2641+
012848DC2D9ED55B00A9C69B /* SettingStoreMethods.swift in Sources */,
26322642
247CE87A258332B400F9D9D1 /* MockNotificationActionHandler.swift in Sources */,
26332643
CCCF3A8129C07DD9001D3507 /* ProductBundleItem+ReadOnlyConvertible.swift in Sources */,
26342644
B9AECD3E2850F41100E78584 /* OrderCardPresentPaymentEligibilityAction.swift in Sources */,
@@ -2849,6 +2859,7 @@
28492859
DE87F40C2D2F839700869522 /* AppSettingsStoreTests+ProductFilterHistory.swift in Sources */,
28502860
20D210C12B177EEF0099E517 /* WooPaymentsPayoutServiceTests.swift in Sources */,
28512861
D87F615E2265B1BC0031A13B /* AppSettingsStoreTests.swift in Sources */,
2862+
012848E22D9EDF2D00A9C69B /* MockSettingStoreMethods.swift in Sources */,
28522863
207D2D1B2CFA06BD00F79204 /* POSCartItemTests.swift in Sources */,
28532864
02E7FFD52562226B00C53030 /* ShippingLabelStoreTests.swift in Sources */,
28542865
031FD8A026FC970400B315C7 /* RosettaTestingHelper.swift in Sources */,
@@ -2867,6 +2878,7 @@
28672878
748525AC218A45360036DF75 /* NotificationStoreTests.swift in Sources */,
28682879
26E5A09225A8A453000DF8F6 /* ProductAttributeTermStoreTests.swift in Sources */,
28692880
020C908124C7D71D001E2BEB /* MockProductVariationsRemote.swift in Sources */,
2881+
012848DE2D9EDAC100A9C69B /* MockCouponStoreMethods.swift in Sources */,
28702882
020C907D24C729D6001E2BEB /* MockProductVariation.swift in Sources */,
28712883
7499936820EFC0ED00CF01CD /* OrderNoteStoreTests.swift in Sources */,
28722884
578CE7972475FD8200492EBF /* MockProductReview.swift in Sources */,

Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol {
1818
private var siteID: Int64
1919
private let currencyFormatter: CurrencyFormatter
2020
private let storage: StorageManagerType?
21-
private let couponService: CouponServiceProtocol
21+
private let couponStoreMethods: CouponStoreMethodsProtocol
22+
private let settingsStoreMethods: SettingStoreMethodsProtocol
2223

2324
init(siteID: Int64,
2425
currencySettings: CurrencySettings,
25-
couponService: CouponServiceProtocol,
26+
couponStoreMethods: CouponStoreMethodsProtocol,
27+
settingStoreMethods: SettingStoreMethodsProtocol,
2628
storage: StorageManagerType) {
2729
self.siteID = siteID
2830
self.currencyFormatter = CurrencyFormatter(currencySettings: currencySettings)
2931
self.storage = storage
30-
self.couponService = couponService
32+
self.couponStoreMethods = couponStoreMethods
33+
self.settingsStoreMethods = settingStoreMethods
3134
}
3235

3336
public convenience init(siteID: Int64,
@@ -38,7 +41,8 @@ public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol {
3841
let remote = CouponsRemote(network: network)
3942
self.init(siteID: siteID,
4043
currencySettings: currencySettings,
41-
couponService: CouponService(storageManager: storage, remote: remote),
44+
couponStoreMethods: CouponStoreMethods(storageManager: storage, remote: remote),
45+
settingStoreMethods: SettingStoreMethods(storageManager: storage, network: network),
4246
storage: storage)
4347
}
4448

@@ -99,7 +103,7 @@ private extension PointOfSaleCouponService {
99103

100104
func syncCouponsFromRemote(pageNumber: Int) async {
101105
await withCheckedContinuation { continuation in
102-
couponService.synchronizeCoupons(
106+
couponStoreMethods.synchronizeCoupons(
103107
siteID: siteID,
104108
pageNumber: pageNumber,
105109
pageSize: 25,
@@ -111,7 +115,17 @@ private extension PointOfSaleCouponService {
111115
}
112116

113117
private func checkStoreCouponSettings() async -> Bool {
114-
// TODO: WOOMOB-250
115-
return true
118+
await withCheckedContinuation { continuation in
119+
settingsStoreMethods.retrieveCouponSetting(siteID: siteID) { result in
120+
switch result {
121+
case let .success(isEnabled):
122+
debugPrint("Coupons enabled? \(isEnabled)")
123+
continuation.resume(returning: isEnabled)
124+
case let .failure(error):
125+
debugPrint("Coupons settings error: \(error)")
126+
continuation.resume(returning: false)
127+
}
128+
}
129+
}
116130
}
117131
}

0 commit comments

Comments
 (0)