Showing
2 changed files
with
32 additions
and
4 deletions
This diff is collapsed. Click to expand it.
| ... | @@ -234,6 +234,30 @@ import UIKit | ... | @@ -234,6 +234,30 @@ import UIKit |
| 234 | var categorySections: [SectionModel] = [] | 234 | var categorySections: [SectionModel] = [] |
| 235 | var processedCouponSets: Set<String> = [] // Track processed coupon sets to avoid duplicates | 235 | var processedCouponSets: Set<String> = [] // Track processed coupon sets to avoid duplicates |
| 236 | 236 | ||
| 237 | + // Extract promoted couponsets for "Top offers" section | ||
| 238 | + let promotedCouponSets = couponSets.filter { $0._promoted } | ||
| 239 | + print("🌟 [MyRewardsViewController] Found \(promotedCouponSets.count) promoted couponsets") | ||
| 240 | + | ||
| 241 | + // Create "Top offers" section if we have promoted couponsets | ||
| 242 | + if !promotedCouponSets.isEmpty { | ||
| 243 | + // Bind merchant data to promoted couponsets | ||
| 244 | + for couponSet in promotedCouponSets { | ||
| 245 | + if let merchant = merchants.first(where: { $0._uuid == couponSet._merchant_uuid }) { | ||
| 246 | + couponSet._merchant = merchant | ||
| 247 | + print(" 🔗 Bound merchant '\(merchant._name)' to promoted coupon set '\(couponSet._name)'") | ||
| 248 | + } | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + let topOffersSection = SectionModel( | ||
| 252 | + sectionType: .myRewardsHorizontalCouponsets, | ||
| 253 | + title: "Top offers", | ||
| 254 | + items: promotedCouponSets, | ||
| 255 | + itemType: .couponSets | ||
| 256 | + ) | ||
| 257 | + categorySections.append(topOffersSection) | ||
| 258 | + print(" ✅ Created 'Top offers' section with \(promotedCouponSets.count) items") | ||
| 259 | + } | ||
| 260 | + | ||
| 237 | print("🔄 [MyRewardsViewController] Processing categories for filtering...") | 261 | print("🔄 [MyRewardsViewController] Processing categories for filtering...") |
| 238 | 262 | ||
| 239 | for category in merchantCategories { | 263 | for category in merchantCategories { |
| ... | @@ -283,6 +307,8 @@ import UIKit | ... | @@ -283,6 +307,8 @@ import UIKit |
| 283 | } | 307 | } |
| 284 | } | 308 | } |
| 285 | 309 | ||
| 310 | + // COMMENTED OUT: Don't show unmatched couponsets - only show categorized ones | ||
| 311 | + /* | ||
| 286 | // Handle any remaining unmatched coupon sets | 312 | // Handle any remaining unmatched coupon sets |
| 287 | let unmatchedCouponSets = couponSets.filter { couponSet in | 313 | let unmatchedCouponSets = couponSets.filter { couponSet in |
| 288 | !processedCouponSets.contains(couponSet._uuid) | 314 | !processedCouponSets.contains(couponSet._uuid) |
| ... | @@ -307,16 +333,18 @@ import UIKit | ... | @@ -307,16 +333,18 @@ import UIKit |
| 307 | ) | 333 | ) |
| 308 | categorySections.append(unmatchedSection) | 334 | categorySections.append(unmatchedSection) |
| 309 | } | 335 | } |
| 336 | + */ | ||
| 310 | 337 | ||
| 311 | - // Sort sections by title for consistent ordering | 338 | + // Sort sections by title for consistent ordering, but keep "Top offers" at the top |
| 312 | categorySections.sort { section1, section2 in | 339 | categorySections.sort { section1, section2 in |
| 313 | let title1 = section1.title ?? "" | 340 | let title1 = section1.title ?? "" |
| 314 | let title2 = section2.title ?? "" | 341 | let title2 = section2.title ?? "" |
| 315 | 342 | ||
| 316 | - // Put "Άλλες Προσφορές" at the end | 343 | + // Put "Top offers" at the beginning |
| 317 | - if title1 == "Άλλες Προσφορές" { return false } | 344 | + if title1 == "Top offers" { return true } |
| 318 | - if title2 == "Άλλες Προσφορές" { return true } | 345 | + if title2 == "Top offers" { return false } |
| 319 | 346 | ||
| 347 | + // All other sections sorted alphabetically | ||
| 320 | return title1.localizedCaseInsensitiveCompare(title2) == .orderedAscending | 348 | return title1.localizedCaseInsensitiveCompare(title2) == .orderedAscending |
| 321 | } | 349 | } |
| 322 | 350 | ... | ... |
-
Please register or login to post a comment