Manos Chorianopoulos

added getMerchants requests at MyRewardsVC

......@@ -43,6 +43,9 @@ import UIKit
// Coupon sets data
var couponSets: [CouponSetItemModel] = []
// Merchants data
var merchants: [MerchantModel] = []
// Profile data
var profileModel: ProfileModel?
var profileSection: SectionModel?
......@@ -151,27 +154,57 @@ import UIKit
self.couponSets = couponSets
// Create coupon sets section with real data
if !self.couponSets.isEmpty {
let couponSetsSection = SectionModel(
sectionType: .myRewardsHorizontalCouponsets,
title: "Προσφορές",
items: self.couponSets,
itemType: .couponSets
)
self.sections.append(couponSetsSection)
}
// Load merchants after getting coupon sets
self.loadMerchants()
// Reload table view with new sections
DispatchQueue.main.async {
self.tableView.reloadData()
}
} failureCallback: { [weak self] errorCode in
print("Failed to load coupon sets: \(errorCode)")
// No sections added on failure - table will be empty
}
}
// MARK: - Merchants Loading
private func loadMerchants() {
// Load merchants from WarplySDK (using enhanced getMerchants method)
WarplySDK.shared.getMerchants { [weak self] merchants in
guard let self = self, let merchants = merchants else {
// If merchants fail to load, still create coupon sets section without filtering
self?.createCouponSetsSection()
return
}
self.merchants = merchants
print("✅ [MyRewardsViewController] Loaded \(merchants.count) merchants")
// For now, create the coupon sets section without filtering
// Later this will be enhanced to filter by merchant categories
self.createCouponSetsSection()
} failureCallback: { [weak self] errorCode in
print("Failed to load merchants: \(errorCode)")
// If merchants fail, still show coupon sets without filtering
self?.createCouponSetsSection()
}
}
private func createCouponSetsSection() {
// Create coupon sets section with real data
if !self.couponSets.isEmpty {
let couponSetsSection = SectionModel(
sectionType: .myRewardsHorizontalCouponsets,
title: "Προσφορές",
items: self.couponSets,
itemType: .couponSets
)
self.sections.append(couponSetsSection)
}
// Reload table view with new sections
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
// MARK: - Profile Loading
public func loadProfile() {
// Always attempt to load profile, regardless of authentication status
......