Manos Chorianopoulos

refactor setCCMSLoyaltyCampaigns, add mergeGFYCCMSLoyaltyCampaigns, mergeMFYCCMSLoyaltyCampaigns

......@@ -73,11 +73,15 @@ public class swiftApi {
let ccmsCampaign: Array<LoyaltyContextualOfferModel> = campaigns
GlobalVariables.ccmsCampaigns = campaigns
}
public func mergeGFYCCMSLoyaltyCampaigns(campaigns: Array<LoyaltyContextualOfferModel>) -> Array<CampaignItemModel> {
let ccmsCampaign: Array<LoyaltyContextualOfferModel> = campaigns
let mergedGFYCampaigns = GlobalVariables.campaigns.filter {
let tempCampaign = $0
let isGFY = tempCampaign.offer_category == "gifts_for_you"
let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true)
// 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))
......@@ -86,7 +90,7 @@ public class swiftApi {
let matchedCampaigns = GlobalVariables.campaigns.filter {
let tempCampaign = $0
let isGFY = tempCampaign.offer_category == "gifts_for_you"
let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true)
// 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 && loyaltyCampaignIdExists
......@@ -98,9 +102,45 @@ public class swiftApi {
print("=====================================")
GlobalVariables.campaigns = GlobalVariables.campaigns.filter { $0.offer_category != "gifts_for_you" } + mergedGFYCampaigns
let totalCampaigns = GlobalVariables.campaigns.filter { $0.offer_category != "gifts_for_you" } + mergedGFYCampaigns
print("TOTAL: Campaigns Sum=" + String(totalCampaigns.count) + " campaigns to display")
return mergedGFYCampaigns
}
public func mergeMFYCCMSLoyaltyCampaigns(campaigns: Array<LoyaltyContextualOfferModel>) -> Array<CampaignItemModel> {
let ccmsCampaign: Array<LoyaltyContextualOfferModel> = campaigns
let mergedMFYCampaigns = GlobalVariables.campaigns.filter {
let tempCampaign = $0
let isMFY = tempCampaign.offer_category == "more_for_you"
// 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 isMFY && (!isCcmsOffer || (isCcmsOffer && loyaltyCampaignIdExists))
}
let matchedCampaigns = GlobalVariables.campaigns.filter {
let tempCampaign = $0
let isMFY = tempCampaign.offer_category == "more_for_you"
// 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 isMFY && isCcmsOffer && loyaltyCampaignIdExists
}
print("Got L:{" + String(GlobalVariables.campaigns.count) + "} LOYALTY campaigns")
print("Got C:{" + String(campaigns.count) + "} CCMS campaigns")
print("Matched M:{" + String(matchedCampaigns.count) + "} CCMS campaigns")
print("=====================================")
let totalCampaigns = GlobalVariables.campaigns.filter { $0.offer_category != "more_for_you" } + mergedMFYCampaigns
print("TOTAL: Campaigns Sum=" + String(totalCampaigns.count) + " campaigns to display")
print("TOTAL: Campaigns Sum=" + String(GlobalVariables.campaigns.count) + " campaigns to display")
return mergedMFYCampaigns
}
public func getCCMSLoyaltyCampaigns() -> Array<LoyaltyContextualOfferModel> {
......