Manos Chorianopoulos

SM deals public func

......@@ -92,6 +92,17 @@ import SwiftEventBus
}
}
SwiftEventBus.onBackgroundThread(self, name: "unified_coupons_fetched") { result in
DispatchQueue.main.async {
self.unifiedCoupons = swiftApi().getUnifiedCouponList()
// TODO: Maybe add this
self.matchOldSMCoupons()
self.updateMarketBadge()
self.tableView.reloadData()
}
}
// TODO: DELETE ===>
// let coupon = swiftApi.ActiveDFYCouponModel()
// coupon._value = "12"
......@@ -117,8 +128,7 @@ import SwiftEventBus
// TODO: DELETE <===
// TODO: Uncomment when UnifiedCoupons will be shown again
// getUnifiedCouponsRequest()
getCouponsSetsDealsRequest()
// getCouponsSetsDealsRequest()
setBackButton()
setNavigationTitle("My Rewards")
......@@ -446,6 +456,7 @@ import SwiftEventBus
emptyImage.image = UIImage(named: "ic_empty_wallet_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
emptyLabel.text = "Δεν έχεις κάποιον ενεργό κωδικό ή κουπόνι! Μπες τώρα στην ενότητα COSMOTE For You και βρες αποκλειστικές προσφορές!"
matchOldSMCoupons()
updateMarketBadge()
// TODO: DELETE if emptyView is needed again
......@@ -505,6 +516,9 @@ import SwiftEventBus
self.coupons = swiftApi().getCouponList()
// TODO: Uncomment when UnifiedCoupons will be shown again
self.unifiedCoupons = swiftApi().getUnifiedCouponList()
// TODO: Maybe add this
// self.matchOldSMCoupons()
// <===
self.updateMarketBadge()
self.tableView.reloadData()
......
......@@ -21,6 +21,7 @@ public struct GlobalVariables {
static var couponsetsDealsList: Array<swiftApi.CouponSetItemModel> = [] // Supermarket couponsets
static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = []
static var oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = []
static var unifiedCouponsDiscount: Float = 0.0
static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel()
static var consumer: swiftApi.ProfileModel?
static var consumerInternal: swiftApi.ProfileModel?
......@@ -4697,6 +4698,16 @@ public class swiftApi {
}
public func setUnifiedCouponsDiscount(_ discount: Float) {
GlobalVariables.unifiedCouponsDiscount = discount
}
public func getUnifiedCouponsDiscount() -> Float {
return GlobalVariables.unifiedCouponsDiscount
}
public class LoyaltyGiftsForYouPackage: Codable {
private var title: String
private var imageUrl: String
......@@ -7299,4 +7310,76 @@ public class swiftApi {
}
public func getUnifiedCouponsDeals(_ successCallback: @escaping (_ responseData: Array<UnifiedCouponModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
swiftApi().getCouponSetsDealsAsync(getCouponsSetsDealsCallback, failureCallback: {errorCode in
failureCallback(errorCode)
})
func getCouponsSetsDealsCallback (_ couponsData: Array<swiftApi.CouponSetItemModel>?) -> Void {
if (couponsData != nil) {
DispatchQueue.main.async {
swiftApi().getUnifiedCouponsAsync(getUnifiedCouponsCallback, failureCallback: {errorCode in
failureCallback(errorCode)
})
}
} else {
successCallback(nil)
}
}
func getUnifiedCouponsCallback (_ couponsData: Array<swiftApi.UnifiedCouponModel>?) -> Void {
if (couponsData != nil) {
DispatchQueue.main.async {
// self.matchOldSMCoupons()
SwiftEventBus.post("unified_coupons_fetched")
successCallback(couponsData)
}
} else {
successCallback(nil)
}
}
}
public func matchOldSMCoupons() -> Void {
var oldUnifiedCouponsArray:Array<swiftApi.CouponItemModel> = []
for smCouponSet in swiftApi().getCouponSetsDealsList() {
for oldCoupon in swiftApi().getAllOldCouponList() {
if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
oldCoupon.setCouponSetData(smCouponSet);
oldUnifiedCouponsArray.append(oldCoupon);
break;
}
}
}
oldUnifiedCouponsArray.sort(by: {
let date1 = $0.redeemed_date
let date2 = $1.redeemed_date
if ((date1 != nil) && (date2 != nil)) {
return date1!.compare(date2!) == .orderedDescending
} else {
return false
}
})
swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
var tempUnifiedCouponsDiscount:Float = 0.0
for coupon in oldUnifiedCouponsArray {
if let discountFloat = Float(coupon.discount ?? "0.0") {
tempUnifiedCouponsDiscount += discountFloat
}
}
swiftApi().setUnifiedCouponsDiscount(tempUnifiedCouponsDiscount)
}
}
......