Manos Chorianopoulos

PopupMerchantsViewController dynamic list

...@@ -655,20 +655,35 @@ import AVFoundation ...@@ -655,20 +655,35 @@ import AVFoundation
655 655
656 @IBAction func redeemButtomAction(_ sender: Any) { 656 @IBAction func redeemButtomAction(_ sender: Any) {
657 if (isSMCoupon == true) { 657 if (isSMCoupon == true) {
658 + var availableShopsList:Array<swiftApi.ShopAvailabilityItemModel> = []
659 + let smCouponsetsList = swiftApi().getCouponSetsDealsList()
660 + let couponsetUuid = coupon?.couponset_uuid
661 + for couponset in smCouponsetsList {
662 + if (couponset.uuid == couponsetUuid) {
663 + availableShopsList = couponset.shop_availability ?? []
664 + break;
665 + }
666 + }
667 +
668 + if (availableShopsList.count > 0) {
658 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self)) 669 let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
659 if let popupVC = storyboard.instantiateViewController(withIdentifier: "PopupMerchantsViewController") as? SwiftWarplyFramework.PopupMerchantsViewController { 670 if let popupVC = storyboard.instantiateViewController(withIdentifier: "PopupMerchantsViewController") as? SwiftWarplyFramework.PopupMerchantsViewController {
660 popupVC.modalPresentationStyle = .overCurrentContext 671 popupVC.modalPresentationStyle = .overCurrentContext
661 popupVC.modalTransitionStyle = .crossDissolve 672 popupVC.modalTransitionStyle = .crossDissolve
662 - popupVC.coupon = coupon 673 + popupVC.availableShopsList = availableShopsList
663 -// popupVC.headerText = "Βρες το προϊον στα supermarket" 674 + // popupVC.headerText = "Βρες το προϊον στα supermarket"
664 -// popupVC.buttonTitle = "Βρες το" 675 + // popupVC.buttonTitle = "Βρες το"
665 popupVC.buttonIcon = "shopping_cart" 676 popupVC.buttonIcon = "shopping_cart"
666 -// popupVC.footerText = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία." 677 + // popupVC.footerText = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία."
667 678
668 self.present(popupVC, animated: true, completion: nil) 679 self.present(popupVC, animated: true, completion: nil)
669 } 680 }
670 681
671 } else { 682 } else {
683 + // TODO: add error popup
684 + }
685 +
686 + } else {
672 let couponSetData: swiftApi.CouponSetItemModel? = self.coupon?.couponset_data 687 let couponSetData: swiftApi.CouponSetItemModel? = self.coupon?.couponset_data
673 let couponName = couponSetData?.name ?? "" 688 let couponName = couponSetData?.name ?? ""
674 689
......
...@@ -23,6 +23,8 @@ class MerchantTableViewCell: UITableViewCell { ...@@ -23,6 +23,8 @@ class MerchantTableViewCell: UITableViewCell {
23 // Delegate variable 23 // Delegate variable
24 weak var delegate: MerchantTableViewCellDelegate? 24 weak var delegate: MerchantTableViewCellDelegate?
25 25
26 + let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
27 +
26 var postImageURL: String? { 28 var postImageURL: String? {
27 didSet { 29 didSet {
28 if let url = postImageURL { 30 if let url = postImageURL {
...@@ -71,9 +73,14 @@ class MerchantTableViewCell: UITableViewCell { ...@@ -71,9 +73,14 @@ class MerchantTableViewCell: UITableViewCell {
71 contentView.frame = contentView.frame.inset(by: margins) 73 contentView.frame = contentView.frame.inset(by: margins)
72 } 74 }
73 75
74 - func configureCell(merchant: swiftApi.MerchantModel, buttonTitle: String, iconImage: String?) { 76 + func configureCell(shop: swiftApi.ShopAvailabilityItemModel, buttonTitle: String, iconImage: String?) {
75 77
78 + for merchant in merchantList {
79 + if (merchant._uuid == shop._merchant_uuid) {
76 self.postImageURL = merchant._img_preview 80 self.postImageURL = merchant._img_preview
81 + break;
82 + }
83 + }
77 84
78 buttonTitleLable.text = buttonTitle 85 buttonTitleLable.text = buttonTitle
79 86
......
...@@ -13,14 +13,13 @@ class PopupMerchantsViewController: UIViewController { ...@@ -13,14 +13,13 @@ class PopupMerchantsViewController: UIViewController {
13 @IBOutlet weak var closeButton: UIButton! 13 @IBOutlet weak var closeButton: UIButton!
14 @IBOutlet weak var tableView: DynamicSizeTableView! 14 @IBOutlet weak var tableView: DynamicSizeTableView!
15 15
16 - public var coupon: swiftApi.CouponItemModel? 16 + public var availableShopsList:Array<swiftApi.ShopAvailabilityItemModel> = []
17 +// public var coupon: swiftApi.CouponItemModel?
17 public var headerText: String? = "Βρες το προϊον στα supermarket" 18 public var headerText: String? = "Βρες το προϊον στα supermarket"
18 public var buttonTitle: String? = "Βρες το" 19 public var buttonTitle: String? = "Βρες το"
19 public var buttonIcon: String? 20 public var buttonIcon: String?
20 public var footerText: String? = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία." 21 public var footerText: String? = "Η διαθεσιμότητα ενδέχεται να διαφέρει ανάλογα με την τοποθεσία."
21 22
22 - let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
23 -
24 override func viewDidLoad() { 23 override func viewDidLoad() {
25 super.viewDidLoad() 24 super.viewDidLoad()
26 25
...@@ -59,7 +58,7 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour ...@@ -59,7 +58,7 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour
59 58
60 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 59 public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
61 if (section == 0) { 60 if (section == 0) {
62 - return self.merchantList.count 61 + return self.availableShopsList.count
63 } else if (section == 1) { 62 } else if (section == 1) {
64 return 1 63 return 1
65 } else { 64 } else {
...@@ -82,7 +81,7 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour ...@@ -82,7 +81,7 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour
82 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 81 public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
83 if (indexPath.section == 0) { 82 if (indexPath.section == 0) {
84 let cell = tableView.dequeueReusableCell(withIdentifier: "MerchantTableViewCellId", for: indexPath) as! MerchantTableViewCell 83 let cell = tableView.dequeueReusableCell(withIdentifier: "MerchantTableViewCellId", for: indexPath) as! MerchantTableViewCell
85 - cell.configureCell(merchant: merchantList[indexPath.row], buttonTitle: self.buttonTitle ?? "Βρες το", iconImage: buttonIcon) 84 + cell.configureCell(shop: availableShopsList[indexPath.row], buttonTitle: self.buttonTitle ?? "Βρες το", iconImage: buttonIcon)
86 85
87 // Set the delegate to self 86 // Set the delegate to self
88 cell.delegate = self 87 cell.delegate = self
...@@ -98,19 +97,8 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour ...@@ -98,19 +97,8 @@ extension PopupMerchantsViewController: UITableViewDelegate, UITableViewDataSour
98 } 97 }
99 98
100 public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 99 public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
101 -// self.dismiss(animated: true, completion: {}) 100 + // Do nothing - tap handled with protocol
102 - 101 +// print(" didSelectRowAt Button tapped in row \(indexPath.row)")
103 - // TODO: DELETE LOGS
104 - print(" didSelectRowAt Button tapped in row \(indexPath.row)")
105 -
106 - // TODO: Open merchant url
107 -
108 - // Logs
109 -// let couponSetData: swiftApi.CouponSetItemModel? = coupons[indexPath.row].couponset_data
110 -// print("Coupon clicked: " + (coupons[indexPath.row].coupon ?? ""))
111 -// print("Coupon Name clicked: " + (couponSetData?.name ?? ""))
112 -// print("Coupon Description clicked: " + (couponSetData?.short_description ?? ""))
113 -// print("Coupon Expiration clicked: " + (coupons[indexPath.row].expiration ?? ""))
114 102
115 } 103 }
116 104
...@@ -138,11 +126,14 @@ extension PopupMerchantsViewController: MerchantTableViewCellDelegate { ...@@ -138,11 +126,14 @@ extension PopupMerchantsViewController: MerchantTableViewCellDelegate {
138 func didTapButton(in cell: MerchantTableViewCell) { 126 func didTapButton(in cell: MerchantTableViewCell) {
139 // Find the index path of the cell where the button was tapped 127 // Find the index path of the cell where the button was tapped
140 if let indexPath = tableView.indexPath(for: cell) { 128 if let indexPath = tableView.indexPath(for: cell) {
141 - // TODO: DELETE LOGS 129 + let urlString = availableShopsList[indexPath.row]._product_url
142 - print("Button tapped in row \(indexPath.row)") 130 + if let url = URL(string: urlString){
143 - print("Button tapped cell: \(cell)") 131 + if UIApplication.shared.canOpenURL(url) {
144 - // Handle the button tap action here 132 + UIApplication.shared.open(url, options: [:], completionHandler: nil)
145 } 133 }
146 } 134 }
135 + }
136 +
137 + }
147 138
148 } 139 }
......