Manos Chorianopoulos

new universal coupon fixes

......@@ -127,14 +127,19 @@ extension AnalysisItemViewCell {
titleLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == couponSetData?.merchant_uuid) {
// itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
titleLabel.text = merchant._admin_name
break;
}
}
// for merchant in merchantList {
// // if (merchant._uuid == couponSetData?.merchant_uuid) {
// if (merchant._uuid == item.merchant_uuid) {
// // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
// self.postImageURL = merchant._img_preview
// titleLabel.text = merchant._admin_name
// break;
// }
// }
let merchantDetails: swiftApi.MerchantModel? = item.merchant_details
self.postImageURL = merchantDetails?._img_preview
titleLabel.text = merchantDetails?._admin_name
dateLabel.text = item.redeemed ?? "" // expiration
// itemImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
......@@ -164,14 +169,18 @@ extension AnalysisItemViewCell {
titleLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == item.merchant_uuid) {
// itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
titleLabel.text = merchant._admin_name
break;
}
}
// for merchant in merchantList {
// if (merchant._uuid == item.merchant_uuid) {
// // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
// self.postImageURL = merchant._img_preview
// titleLabel.text = merchant._admin_name
// break;
// }
// }
let merchantDetails: swiftApi.MerchantModel? = item.merchant_details
self.postImageURL = merchantDetails?._img_preview
titleLabel.text = merchantDetails?._admin_name
// titleLabel.text = item.name
// self.postImageURL = item.image
......
......@@ -144,15 +144,18 @@ import AVFoundation
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
var merchantUuid: String = ""
if (isMarket == true) {
// if (isMarket == true) {
merchantUuid = coupon?.merchant_uuid ?? ""
} else {
merchantUuid = couponSetData?.merchant_uuid ?? ""
}
// } else {
// merchantUuid = couponSetData?.merchant_uuid ?? ""
// }
// for merchant in merchantList {
// if (merchant._uuid == merchantUuid) {
// let htmlMerchDescrText = merchant._body
for merchant in merchantList {
if (merchant._uuid == merchantUuid) {
let htmlMerchDescrText = merchant._body
let merchantDetails: swiftApi.MerchantModel? = coupon?.merchant_details
let htmlMerchDescrText = merchantDetails?._body ?? ""
if (isMarket != true && htmlMerchDescrText != "") {
merchantDescrTextView.attributedText = htmlMerchDescrText.htmlToAttributedString
......@@ -173,9 +176,9 @@ import AVFoundation
couponCodeLabelTopSpace.constant = CGFloat(0)
}
break;
}
}
// break;
// }
// }
couponView.layer.cornerRadius = 16
couponNumberLabel.text = coupon?.coupon ?? ""
......@@ -518,7 +521,7 @@ import AVFoundation
if (isMarket == true) {
vc.isMarket = true
} else {
vc.couponSet = coupon?.couponset_data
vc.coupon = coupon
}
self.navigationController?.pushViewController(vc, animated: true)
......
......@@ -23,6 +23,9 @@ import UIKit
var postImageURL: String? {
didSet {
if let url = postImageURL {
// TODO: DELETE LOGS
print("=== postImageURL: ",url)
self.couponImage.image = UIImage() // UIImage(named: "loading")
UIImage.loadImageUsingCacheWithUrlString(url) { image in
......@@ -79,14 +82,19 @@ import UIKit
nameLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == couponSetData?.merchant_uuid) {
// couponImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
nameLabel.text = merchant._admin_name
break;
}
}
// for merchant in merchantList {
// // if (merchant._uuid == couponSetData?.merchant_uuid) {
// if (merchant._uuid == coupon.merchant_uuid) {
// // couponImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
// self.postImageURL = merchant._img_preview
// nameLabel.text = merchant._admin_name
// break;
// }
// }
let merchantDetails: swiftApi.MerchantModel? = coupon.merchant_details
self.postImageURL = merchantDetails?._img_preview
nameLabel.text = merchantDetails?._admin_name
// couponImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
// nameLabel.text = couponSetData?.name ?? ""
......
......@@ -28,7 +28,7 @@ import MapKit
@IBOutlet weak var addressImageView: UIImageView!
// public
public var couponSet: swiftApi.CouponSetItemModel?
public var coupon: swiftApi.CouponItemModel?
public var isMarket: Bool? = false
var merchantsArray:Array<swiftApi.MerchantModel> = []
var selectedMerchant: swiftApi.MerchantModel?
......@@ -132,8 +132,8 @@ import MapKit
}
showLoading()
if (couponSet != nil) {
if let merchantUuid: String = couponSet?.merchant_uuid {
if (coupon != nil) {
if let merchantUuid: String = coupon?.merchant_uuid {
swiftApi().getMultilingualMerchantsAsync([], false, 0.0, [], "", 0, [merchantUuid], getMerchantsCallback)
showContent()
}
......@@ -209,12 +209,34 @@ import MapKit
alert.addAction(UIAlertAction(title: "Δες το eshop", style: .default, handler: { action in
switch action.style{
case .default:
if (self.couponSet != nil) {
if let merchantUuid: String = self.couponSet?.merchant_uuid {
for item in swiftApi().getMerchantList() {
if (item._uuid == merchantUuid) {
let eshopWebsite = item._website
if (self.coupon != nil) {
// if let merchantUuid: String = self.coupon?.merchant_uuid {
// for item in swiftApi().getMerchantList() {
// if (item._uuid == merchantUuid) {
// let eshopWebsite = item._website
// if (eshopWebsite != "") {
// guard let websiteUrl = URL(string: eshopWebsite) else {
// print("Error creating URL")
// return
// }
// // check if link can be opened.
// guard UIApplication.shared.canOpenURL(websiteUrl) else {
// return
// }
// swiftApi().logTrackersEvent("click", "SeeShopWebsite")
// UIApplication.shared.open(websiteUrl, options: [:], completionHandler: nil)
// break;
// }
// }
// }
// }
let merchantDetails: swiftApi.MerchantModel? = self.coupon?.merchant_details
let eshopWebsite = merchantDetails?._website ?? ""
if (eshopWebsite != "") {
guard let websiteUrl = URL(string: eshopWebsite) else {
......@@ -232,9 +254,6 @@ import MapKit
break;
}
}
}
}
}
// if (self.merchantsArray.count > 0) {
// for item in self.merchantsArray {
// let eshopWebsite = item._website
......
......@@ -513,6 +513,9 @@ public class swiftApi {
public let discount_type: String? // "value" / "percentage" / "plus_one"
public let final_price: Float?
// Universal Coupons
public let couponset_type: String?
public init(dictionary: [String: Any]) {
self.uuid = dictionary["uuid"] as? String? ?? ""
self.admin_name = dictionary["admin_name"] as? String? ?? ""
......@@ -531,6 +534,9 @@ public class swiftApi {
self.discount_type = dictionary["discount_type"] as? String? ?? ""
// self.final_price = dictionary["final_price"] as? Float? ?? 0.0
// Universal Coupons
self.couponset_type = dictionary["couponset_type"] as? String? ?? ""
if let double_final_price = dictionary["final_price"] as? Double {
self.final_price = Float(double_final_price)
}
......@@ -738,6 +744,9 @@ public class swiftApi {
public let short_description: String?
public let terms: String?
// Universal Coupons
public let merchant_details: MerchantModel?
public init(dictionary: [String: Any]) {
self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? ""
......@@ -775,33 +784,30 @@ public class swiftApi {
self.short_description = dictionary["short_description"] as? String? ?? ""
self.terms = dictionary["terms"] as? String? ?? ""
// TODO: DELETE
// if let couponSetData = dictionary["couponset_data"] as? [String: Any]? ?? ["":""] {
//
// let tempCouponset = CouponSetItemModel(dictionary: couponSetData)
//
// self.couponset_data = tempCouponset
// } else {
// self.couponset_data = nil
// }
if let couponSetData = dictionary["couponset_data"] as? [String: Any] {
let tempCouponset = CouponSetItemModel(dictionary: couponSetData)
self.couponset_data = tempCouponset
// Universal Coupons ==>
} else if let couponSetDetails = dictionary["couponset_details"] as? [String: Any] {
let tempCouponset = CouponSetItemModel(dictionary: couponSetDetails)
self.couponset_data = tempCouponset
} else {
self.couponset_data = nil
}
if let couponSetDetails = dictionary["couponset_details"] as? [String: Any] {
if let merchantDetails = dictionary["merchant_details"] as? [String: Any] {
let tempCouponset = CouponSetItemModel(dictionary: couponSetDetails)
let tempMerchantDetails = MerchantModel(dictionary: merchantDetails)
self.couponset_data = tempCouponset
self.merchant_details = tempMerchantDetails
} else {
self.couponset_data = nil
self.merchant_details = nil
}
// <==
let expirationString = dictionary["expiration"] as? String? ?? ""
......@@ -1087,6 +1093,7 @@ public class swiftApi {
})
}
// Old implementation
// public func getCouponsAsync(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void, failureCallback: @escaping (_ errorCode: Int) -> Void) -> Void {
// CouponsDataModel().getCouponsData(getCouponsCallback, failureCallback: failureCallback)
// }
......@@ -1107,46 +1114,6 @@ public class swiftApi {
swiftApi().getCouponsUniversalAsync(language: "el", getCouponsCallback, failureCallback: failureCallback)
// swiftApi().getCouponsUniversalAsync(language: "el", getCouponsUniversalCallback) { errorCode in
// // TODO: DELETE LOGS
// print("========= getCouponsUniversalRequest ERROR CODE =========", errorCode)
// failureCallback(errorCode)
// }
// func getCouponsUniversalCallback (_ responseData: Array<swiftApi.CouponItemModel>?) -> Void {
// if (responseData != nil) {
// DispatchQueue.main.async {
// // TODO: DELETE LOGS
// print("========= getCouponsUniversalRequest responseData =========")
// print(responseData)
// var activeCoupons = responseData.filter({ return $0.status == 1 })
// // sort activeCoupons by expiration date
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "dd/MM/yyyy"
// activeCoupons.sort(by: {
// let date1 = dateFormatter.date(from: $0.expiration ?? "")
// let date2 = dateFormatter.date(from: $1.expiration ?? "")
// if ((date1 != nil) && (date2 != nil)) {
// return date1!.compare(date2!) == .orderedAscending
// } else {
// return false
// }
// })
// getCouponsCallback(activeCoupons)
// }
// } else {
// // TODO: DELETE LOGS
// print("========= getCouponsUniversalRequest ERROR =========")
// getCouponsCallback(nil)
// }
// }
instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
func couponSetsCallback(_ couponSetsData: [AnyHashable : Any]?) -> Void {
......@@ -8391,15 +8358,6 @@ public class swiftApi {
if let responseDataDictionary = responseData as? [String: AnyObject] {
// TODO: DELETE LOGS
print("=== responseDataDictionary ===")
print(responseDataDictionary)
print("=== responseDataDictionary result ===")
print(responseDataDictionary["result"])
print("=== responseDataDictionary status ===")
print(responseDataDictionary["status"])
if (responseDataDictionary["status"] as? Int == 1) {
let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
dynatraceEvent._eventName = "custom_success_user_coupons_loyalty"
......@@ -8414,17 +8372,16 @@ public class swiftApi {
}
}
// TODO: DELETE LOGS
print("=== AllCoupons NEW ===")
print(couponsArray.count)
// setAllOldCouponList uncluding Supermarkets ==>
swiftApi().setAllOldCouponList(couponsArray)
// <==
swiftApi().setCouponList(couponsArray)
swiftApi().setOldCouponList(couponsArray)
var activeCoupons = couponsArray.filter({ return $0.status == 1 })
let noSMCoupons = couponsArray.filter({ return $0.couponset_data?.couponset_type != "supermarket" })
swiftApi().setCouponList(noSMCoupons)
swiftApi().setOldCouponList(noSMCoupons)
var activeCoupons = noSMCoupons.filter({ return $0.status == 1 })
// sort activeCoupons by expiration date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
......