Manos Chorianopoulos

SM deals public func

...@@ -92,6 +92,17 @@ import SwiftEventBus ...@@ -92,6 +92,17 @@ import SwiftEventBus
92 } 92 }
93 } 93 }
94 94
95 + SwiftEventBus.onBackgroundThread(self, name: "unified_coupons_fetched") { result in
96 +
97 + DispatchQueue.main.async {
98 + self.unifiedCoupons = swiftApi().getUnifiedCouponList()
99 + // TODO: Maybe add this
100 + self.matchOldSMCoupons()
101 + self.updateMarketBadge()
102 + self.tableView.reloadData()
103 + }
104 + }
105 +
95 // TODO: DELETE ===> 106 // TODO: DELETE ===>
96 // let coupon = swiftApi.ActiveDFYCouponModel() 107 // let coupon = swiftApi.ActiveDFYCouponModel()
97 // coupon._value = "12" 108 // coupon._value = "12"
...@@ -117,8 +128,7 @@ import SwiftEventBus ...@@ -117,8 +128,7 @@ import SwiftEventBus
117 // TODO: DELETE <=== 128 // TODO: DELETE <===
118 129
119 // TODO: Uncomment when UnifiedCoupons will be shown again 130 // TODO: Uncomment when UnifiedCoupons will be shown again
120 -// getUnifiedCouponsRequest() 131 +// getCouponsSetsDealsRequest()
121 - getCouponsSetsDealsRequest()
122 132
123 setBackButton() 133 setBackButton()
124 setNavigationTitle("My Rewards") 134 setNavigationTitle("My Rewards")
...@@ -446,6 +456,7 @@ import SwiftEventBus ...@@ -446,6 +456,7 @@ import SwiftEventBus
446 emptyImage.image = UIImage(named: "ic_empty_wallet_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) 456 emptyImage.image = UIImage(named: "ic_empty_wallet_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
447 emptyLabel.text = "Δεν έχεις κάποιον ενεργό κωδικό ή κουπόνι! Μπες τώρα στην ενότητα COSMOTE For You και βρες αποκλειστικές προσφορές!" 457 emptyLabel.text = "Δεν έχεις κάποιον ενεργό κωδικό ή κουπόνι! Μπες τώρα στην ενότητα COSMOTE For You και βρες αποκλειστικές προσφορές!"
448 458
459 + matchOldSMCoupons()
449 updateMarketBadge() 460 updateMarketBadge()
450 461
451 // TODO: DELETE if emptyView is needed again 462 // TODO: DELETE if emptyView is needed again
...@@ -505,6 +516,9 @@ import SwiftEventBus ...@@ -505,6 +516,9 @@ import SwiftEventBus
505 self.coupons = swiftApi().getCouponList() 516 self.coupons = swiftApi().getCouponList()
506 // TODO: Uncomment when UnifiedCoupons will be shown again 517 // TODO: Uncomment when UnifiedCoupons will be shown again
507 self.unifiedCoupons = swiftApi().getUnifiedCouponList() 518 self.unifiedCoupons = swiftApi().getUnifiedCouponList()
519 + // TODO: Maybe add this
520 + // self.matchOldSMCoupons()
521 + // <===
508 self.updateMarketBadge() 522 self.updateMarketBadge()
509 self.tableView.reloadData() 523 self.tableView.reloadData()
510 524
......
...@@ -21,6 +21,7 @@ public struct GlobalVariables { ...@@ -21,6 +21,7 @@ public struct GlobalVariables {
21 static var couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets 21 static var couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets
22 static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = [] 22 static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = []
23 static var oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = [] 23 static var oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = []
24 + static var unifiedCouponsDiscount: Float = 0.0
24 static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel() 25 static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel()
25 static var consumer: swiftApi.ProfileModel? 26 static var consumer: swiftApi.ProfileModel?
26 static var consumerInternal: swiftApi.ProfileModel? 27 static var consumerInternal: swiftApi.ProfileModel?
...@@ -4697,6 +4698,16 @@ public class swiftApi { ...@@ -4697,6 +4698,16 @@ public class swiftApi {
4697 } 4698 }
4698 4699
4699 4700
4701 + public func setUnifiedCouponsDiscount(_ discount: Float) {
4702 + GlobalVariables.unifiedCouponsDiscount = discount
4703 + }
4704 +
4705 +
4706 + public func getUnifiedCouponsDiscount() -> Float {
4707 + return GlobalVariables.unifiedCouponsDiscount
4708 + }
4709 +
4710 +
4700 public class LoyaltyGiftsForYouPackage: Codable { 4711 public class LoyaltyGiftsForYouPackage: Codable {
4701 private var title: String 4712 private var title: String
4702 private var imageUrl: String 4713 private var imageUrl: String
...@@ -7299,4 +7310,76 @@ public class swiftApi { ...@@ -7299,4 +7310,76 @@ public class swiftApi {
7299 } 7310 }
7300 7311
7301 7312
7313 + public func getUnifiedCouponsDeals(_ successCallback: @escaping (_ responseData: Array<UnifiedCouponModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
7314 +
7315 + swiftApi().getCouponSetsDealsAsync(getCouponsSetsDealsCallback, failureCallback: {errorCode in
7316 + failureCallback(errorCode)
7317 + })
7318 +
7319 + func getCouponsSetsDealsCallback (_ couponsData: Array<swiftApi.CouponSetItemModel>?) -> Void {
7320 + if (couponsData != nil) {
7321 +
7322 + DispatchQueue.main.async {
7323 + swiftApi().getUnifiedCouponsAsync(getUnifiedCouponsCallback, failureCallback: {errorCode in
7324 + failureCallback(errorCode)
7325 + })
7326 + }
7327 + } else {
7328 + successCallback(nil)
7329 + }
7330 + }
7331 +
7332 + func getUnifiedCouponsCallback (_ couponsData: Array<swiftApi.UnifiedCouponModel>?) -> Void {
7333 + if (couponsData != nil) {
7334 + DispatchQueue.main.async {
7335 + // self.matchOldSMCoupons()
7336 + SwiftEventBus.post("unified_coupons_fetched")
7337 + successCallback(couponsData)
7338 + }
7339 + } else {
7340 + successCallback(nil)
7341 + }
7342 + }
7343 + }
7344 +
7345 +
7346 + public func matchOldSMCoupons() -> Void {
7347 + var oldUnifiedCouponsArray:Array<swiftApi.CouponItemModel> = []
7348 +
7349 + for smCouponSet in swiftApi().getCouponSetsDealsList() {
7350 + for oldCoupon in swiftApi().getAllOldCouponList() {
7351 + if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
7352 +
7353 + oldCoupon.setCouponSetData(smCouponSet);
7354 + oldUnifiedCouponsArray.append(oldCoupon);
7355 +
7356 + break;
7357 + }
7358 + }
7359 + }
7360 +
7361 + oldUnifiedCouponsArray.sort(by: {
7362 + let date1 = $0.redeemed_date
7363 + let date2 = $1.redeemed_date
7364 +
7365 + if ((date1 != nil) && (date2 != nil)) {
7366 + return date1!.compare(date2!) == .orderedDescending
7367 + } else {
7368 + return false
7369 + }
7370 +
7371 + })
7372 + swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
7373 +
7374 +
7375 + var tempUnifiedCouponsDiscount:Float = 0.0
7376 + for coupon in oldUnifiedCouponsArray {
7377 + if let discountFloat = Float(coupon.discount ?? "0.0") {
7378 + tempUnifiedCouponsDiscount += discountFloat
7379 + }
7380 + }
7381 + swiftApi().setUnifiedCouponsDiscount(tempUnifiedCouponsDiscount)
7382 + }
7383 +
7384 +
7302 } 7385 }
......