Manos Chorianopoulos

fix couponSets categorization

This diff is collapsed. Click to expand it.
......@@ -234,6 +234,30 @@ import UIKit
var categorySections: [SectionModel] = []
var processedCouponSets: Set<String> = [] // Track processed coupon sets to avoid duplicates
// Extract promoted couponsets for "Top offers" section
let promotedCouponSets = couponSets.filter { $0._promoted }
print("🌟 [MyRewardsViewController] Found \(promotedCouponSets.count) promoted couponsets")
// Create "Top offers" section if we have promoted couponsets
if !promotedCouponSets.isEmpty {
// Bind merchant data to promoted couponsets
for couponSet in promotedCouponSets {
if let merchant = merchants.first(where: { $0._uuid == couponSet._merchant_uuid }) {
couponSet._merchant = merchant
print(" 🔗 Bound merchant '\(merchant._name)' to promoted coupon set '\(couponSet._name)'")
}
}
let topOffersSection = SectionModel(
sectionType: .myRewardsHorizontalCouponsets,
title: "Top offers",
items: promotedCouponSets,
itemType: .couponSets
)
categorySections.append(topOffersSection)
print(" ✅ Created 'Top offers' section with \(promotedCouponSets.count) items")
}
print("🔄 [MyRewardsViewController] Processing categories for filtering...")
for category in merchantCategories {
......@@ -283,6 +307,8 @@ import UIKit
}
}
// COMMENTED OUT: Don't show unmatched couponsets - only show categorized ones
/*
// Handle any remaining unmatched coupon sets
let unmatchedCouponSets = couponSets.filter { couponSet in
!processedCouponSets.contains(couponSet._uuid)
......@@ -307,16 +333,18 @@ import UIKit
)
categorySections.append(unmatchedSection)
}
*/
// Sort sections by title for consistent ordering
// Sort sections by title for consistent ordering, but keep "Top offers" at the top
categorySections.sort { section1, section2 in
let title1 = section1.title ?? ""
let title2 = section2.title ?? ""
// Put "Άλλες Προσφορές" at the end
if title1 == "Άλλες Προσφορές" { return false }
if title2 == "Άλλες Προσφορές" { return true }
// Put "Top offers" at the beginning
if title1 == "Top offers" { return true }
if title2 == "Top offers" { return false }
// All other sections sorted alphabetically
return title1.localizedCaseInsensitiveCompare(title2) == .orderedAscending
}
......