refactor setCCMSLoyaltyCampaigns, add mergeGFYCCMSLoyaltyCampaigns, mergeMFYCCMSLoyaltyCampaigns
Showing
1 changed file
with
44 additions
and
4 deletions
... | @@ -73,11 +73,15 @@ public class swiftApi { | ... | @@ -73,11 +73,15 @@ public class swiftApi { |
73 | let ccmsCampaign: Array<LoyaltyContextualOfferModel> = campaigns | 73 | let ccmsCampaign: Array<LoyaltyContextualOfferModel> = campaigns |
74 | 74 | ||
75 | GlobalVariables.ccmsCampaigns = campaigns | 75 | GlobalVariables.ccmsCampaigns = campaigns |
76 | + } | ||
77 | + | ||
78 | + public func mergeGFYCCMSLoyaltyCampaigns(campaigns: Array<LoyaltyContextualOfferModel>) -> Array<CampaignItemModel> { | ||
79 | + let ccmsCampaign: Array<LoyaltyContextualOfferModel> = campaigns | ||
76 | 80 | ||
77 | let mergedGFYCampaigns = GlobalVariables.campaigns.filter { | 81 | let mergedGFYCampaigns = GlobalVariables.campaigns.filter { |
78 | let tempCampaign = $0 | 82 | let tempCampaign = $0 |
79 | let isGFY = tempCampaign.offer_category == "gifts_for_you" | 83 | let isGFY = tempCampaign.offer_category == "gifts_for_you" |
80 | - let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true) | 84 | +// let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true) |
81 | let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") | 85 | let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") |
82 | let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid } | 86 | let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid } |
83 | return isGFY && (!isCcmsOffer || (isCcmsOffer && loyaltyCampaignIdExists)) | 87 | return isGFY && (!isCcmsOffer || (isCcmsOffer && loyaltyCampaignIdExists)) |
... | @@ -86,7 +90,7 @@ public class swiftApi { | ... | @@ -86,7 +90,7 @@ public class swiftApi { |
86 | let matchedCampaigns = GlobalVariables.campaigns.filter { | 90 | let matchedCampaigns = GlobalVariables.campaigns.filter { |
87 | let tempCampaign = $0 | 91 | let tempCampaign = $0 |
88 | let isGFY = tempCampaign.offer_category == "gifts_for_you" | 92 | let isGFY = tempCampaign.offer_category == "gifts_for_you" |
89 | - let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true) | 93 | +// let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true) |
90 | let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") | 94 | let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") |
91 | let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid } | 95 | let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid } |
92 | return isGFY && isCcmsOffer && loyaltyCampaignIdExists | 96 | return isGFY && isCcmsOffer && loyaltyCampaignIdExists |
... | @@ -98,9 +102,45 @@ public class swiftApi { | ... | @@ -98,9 +102,45 @@ public class swiftApi { |
98 | print("=====================================") | 102 | print("=====================================") |
99 | 103 | ||
100 | 104 | ||
101 | - GlobalVariables.campaigns = GlobalVariables.campaigns.filter { $0.offer_category != "gifts_for_you" } + mergedGFYCampaigns | 105 | + let totalCampaigns = GlobalVariables.campaigns.filter { $0.offer_category != "gifts_for_you" } + mergedGFYCampaigns |
106 | + | ||
107 | + print("TOTAL: Campaigns Sum=" + String(totalCampaigns.count) + " campaigns to display") | ||
108 | + | ||
109 | + return mergedGFYCampaigns | ||
110 | + } | ||
111 | + | ||
112 | + public func mergeMFYCCMSLoyaltyCampaigns(campaigns: Array<LoyaltyContextualOfferModel>) -> Array<CampaignItemModel> { | ||
113 | + let ccmsCampaign: Array<LoyaltyContextualOfferModel> = campaigns | ||
114 | + | ||
115 | + let mergedMFYCampaigns = GlobalVariables.campaigns.filter { | ||
116 | + let tempCampaign = $0 | ||
117 | + let isMFY = tempCampaign.offer_category == "more_for_you" | ||
118 | +// let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true) | ||
119 | + let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") | ||
120 | + let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid } | ||
121 | + return isMFY && (!isCcmsOffer || (isCcmsOffer && loyaltyCampaignIdExists)) | ||
122 | + } | ||
123 | + | ||
124 | + let matchedCampaigns = GlobalVariables.campaigns.filter { | ||
125 | + let tempCampaign = $0 | ||
126 | + let isMFY = tempCampaign.offer_category == "more_for_you" | ||
127 | +// let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true) | ||
128 | + let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") | ||
129 | + let loyaltyCampaignIdExists = ccmsCampaign.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid } | ||
130 | + return isMFY && isCcmsOffer && loyaltyCampaignIdExists | ||
131 | + } | ||
132 | + | ||
133 | + print("Got L:{" + String(GlobalVariables.campaigns.count) + "} LOYALTY campaigns") | ||
134 | + print("Got C:{" + String(campaigns.count) + "} CCMS campaigns") | ||
135 | + print("Matched M:{" + String(matchedCampaigns.count) + "} CCMS campaigns") | ||
136 | + print("=====================================") | ||
137 | + | ||
138 | + | ||
139 | + let totalCampaigns = GlobalVariables.campaigns.filter { $0.offer_category != "more_for_you" } + mergedMFYCampaigns | ||
140 | + | ||
141 | + print("TOTAL: Campaigns Sum=" + String(totalCampaigns.count) + " campaigns to display") | ||
102 | 142 | ||
103 | - print("TOTAL: Campaigns Sum=" + String(GlobalVariables.campaigns.count) + " campaigns to display") | 143 | + return mergedMFYCampaigns |
104 | } | 144 | } |
105 | 145 | ||
106 | public func getCCMSLoyaltyCampaigns() -> Array<LoyaltyContextualOfferModel> { | 146 | public func getCCMSLoyaltyCampaigns() -> Array<LoyaltyContextualOfferModel> { | ... | ... |
-
Please register or login to post a comment