Manos Chorianopoulos

fix CampaignItemModel, setCCMSLoyaltyCampaigns

......@@ -76,9 +76,10 @@ public class swiftApi {
let mergedGFYCampaigns = GlobalVariables.campaigns.filter {
let tempCampaign = $0
let isGFY = tempCampaign.offer_category == "gifts_for_you"
let hasExtraFields = tempCampaign.hasExtraFields ?? false
let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.loyaltyCampaignId }
return isGFY && (!hasExtraFields || loyaltyCampaignIdExists)
let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true)
let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true")
let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid }
return isGFY && (!isCcmsOffer || (isCcmsOffer && loyaltyCampaignIdExists))
}
GlobalVariables.campaigns = GlobalVariables.campaigns.filter { $0.offer_category != "gifts_for_you" } + mergedGFYCampaigns
......@@ -415,7 +416,7 @@ public class swiftApi {
public let message: String?
public let loyaltyCampaignId: String?
public let hasExtraFields: Bool?
public let ccms_offer: Bool?
public let ccms_offer: String?
init(dictionary: [String: Any]) {
self.index_url = dictionary["index_url"] as? String? ?? ""
......@@ -439,19 +440,19 @@ public class swiftApi {
self.subcategory = extra_fields_parsed["subcategory"] as? String? ?? ""
self.loyaltyCampaignId = extra_fields_parsed["loyaltyCampaignId"] as? String? ?? ""
self.hasExtraFields = true
self.ccms_offer = extra_fields_parsed["ccms_offer"] as? Bool? ?? false
self.ccms_offer = extra_fields_parsed["ccms_offer"] as? String? ?? "false"
} else {
self.subcategory = ""
self.loyaltyCampaignId = ""
self.hasExtraFields = false
self.ccms_offer = false
self.ccms_offer = "false"
print("bad json")
}
} catch let error as NSError {
self.subcategory = ""
self.loyaltyCampaignId = ""
self.hasExtraFields = false
self.ccms_offer = false
self.ccms_offer = "false"
print(error)
}
......