Showing
1 changed file
with
73 additions
and
0 deletions
| ... | @@ -499,6 +499,41 @@ public class swiftApi { | ... | @@ -499,6 +499,41 @@ public class swiftApi { |
| 499 | return GlobalVariables.dfyCoupons | 499 | return GlobalVariables.dfyCoupons |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | + | ||
| 503 | + public class ShopAvailabilityItemModel: Codable { | ||
| 504 | + private var merchant_uuid: String? | ||
| 505 | + private var product_url: String? | ||
| 506 | + | ||
| 507 | + init() { | ||
| 508 | + self.merchant_uuid = "" | ||
| 509 | + self.product_url = "" | ||
| 510 | + } | ||
| 511 | + | ||
| 512 | + public init(dictionary: [String: Any]) { | ||
| 513 | + self.merchant_uuid = dictionary["merchant_uuid"] as? String? ?? "" | ||
| 514 | + self.product_url = dictionary["product_url"] as? String? ?? "" | ||
| 515 | + } | ||
| 516 | + | ||
| 517 | + public var _merchant_uuid: String { | ||
| 518 | + get { // getter | ||
| 519 | + return self.merchant_uuid ?? "" | ||
| 520 | + } | ||
| 521 | + set(newValue) { //setter | ||
| 522 | + self.merchant_uuid = newValue | ||
| 523 | + } | ||
| 524 | + } | ||
| 525 | + | ||
| 526 | + public var _product_url: String { | ||
| 527 | + get { // getter | ||
| 528 | + return self.product_url ?? "" | ||
| 529 | + } | ||
| 530 | + set(newValue) { //setter | ||
| 531 | + self.product_url = newValue | ||
| 532 | + } | ||
| 533 | + } | ||
| 534 | + } | ||
| 535 | + | ||
| 536 | + | ||
| 502 | public class CouponSetItemModel: Codable { | 537 | public class CouponSetItemModel: Codable { |
| 503 | public let uuid: String? | 538 | public let uuid: String? |
| 504 | public let admin_name: String? | 539 | public let admin_name: String? |
| ... | @@ -520,6 +555,9 @@ public class swiftApi { | ... | @@ -520,6 +555,9 @@ public class swiftApi { |
| 520 | // Universal Coupons | 555 | // Universal Coupons |
| 521 | public let couponset_type: String? | 556 | public let couponset_type: String? |
| 522 | 557 | ||
| 558 | + // PopupMerchantsViewController List | ||
| 559 | + public let shop_availability: Array<ShopAvailabilityItemModel>? | ||
| 560 | + | ||
| 523 | public init(dictionary: [String: Any]) { | 561 | public init(dictionary: [String: Any]) { |
| 524 | self.uuid = dictionary["uuid"] as? String? ?? "" | 562 | self.uuid = dictionary["uuid"] as? String? ?? "" |
| 525 | self.admin_name = dictionary["admin_name"] as? String? ?? "" | 563 | self.admin_name = dictionary["admin_name"] as? String? ?? "" |
| ... | @@ -570,6 +608,41 @@ public class swiftApi { | ... | @@ -570,6 +608,41 @@ public class swiftApi { |
| 570 | self.expiration = "" | 608 | self.expiration = "" |
| 571 | } | 609 | } |
| 572 | 610 | ||
| 611 | + // shop_availability Example | ||
| 612 | + // {"shop_availability":"[{\"merchant_uuid\": \"9742752bcf904a269707c40b286e66de\", \"product_url\": \"https://www.ab.gr/el/eshop/Galaktokomika-Fytika-Rofimata-and-Eidi-Psygeioy/Gala-and-Fytika-Rofimata/Fytika-Rofimata/Fytiko-Rofima-Amygdalo-Choris-Prosthiki-Zacharis-1lt/p/7438640\"}]"} | ||
| 613 | + | ||
| 614 | + if let extra_fields = dictionary["extra_fields"] as? [String: Any] { | ||
| 615 | + if let shopAvailabilityString = extra_fields["shop_availability"] as? String { | ||
| 616 | + // Convert the cleaned string to JSON data | ||
| 617 | + if let shopData = shopAvailabilityString.data(using: .utf8) { | ||
| 618 | + do { | ||
| 619 | + // Parse JSON data as an array of dictionaries | ||
| 620 | + if let shopArray = try JSONSerialization.jsonObject(with: shopData, options: []) as? [[String: Any]] { | ||
| 621 | + var shopItems: Array<ShopAvailabilityItemModel> = [] | ||
| 622 | + // Iterate through the shopArray and populate ShopAvailabilityItemModel objects | ||
| 623 | + for shopDict in shopArray { | ||
| 624 | + let tempShop = ShopAvailabilityItemModel(dictionary: shopDict) | ||
| 625 | + shopItems.append(tempShop) | ||
| 626 | + } | ||
| 627 | + self.shop_availability = shopItems | ||
| 628 | + | ||
| 629 | + } else { | ||
| 630 | + self.shop_availability = [] | ||
| 631 | + } | ||
| 632 | + } catch { | ||
| 633 | + self.shop_availability = [] | ||
| 634 | + print("Error parsing shop availability: \(error)") | ||
| 635 | + } | ||
| 636 | + } else { | ||
| 637 | + self.shop_availability = [] | ||
| 638 | + } | ||
| 639 | + } else { | ||
| 640 | + self.shop_availability = [] | ||
| 641 | + } | ||
| 642 | + | ||
| 643 | + } else { | ||
| 644 | + self.shop_availability = [] | ||
| 645 | + } | ||
| 573 | 646 | ||
| 574 | } | 647 | } |
| 575 | 648 | ... | ... |
-
Please register or login to post a comment