1: <?php
2: namespace Opencart\Catalog\Model\Localisation;
3: /**
4: * Class Country
5: *
6: * @package Opencart\Catalog\Model\Localisation
7: */
8: class Country extends \Opencart\System\Engine\Model {
9: /**
10: * Get Country
11: *
12: * @param int $country_id
13: *
14: * @return array<string, mixed>
15: */
16: public function getCountry(int $country_id): array {
17: $query = $this->db->query("SELECT *, `c`.`name` FROM `" . DB_PREFIX . "country` `c` LEFT JOIN `" . DB_PREFIX . "address_format` af ON (`c`.`address_format_id` = `af`.`address_format_id`) WHERE `c`.`country_id` = '" . (int)$country_id . "' AND `c`.`status` = '1'");
18:
19: return $query->row;
20: }
21:
22: /**
23: * Get Country By Iso Code 2
24: *
25: * @param string $iso_code_2
26: *
27: * @return array<int, array<string, mixed>>
28: */
29: public function getCountryByIsoCode2(string $iso_code_2): array {
30: $sql = "SELECT * FROM `" . DB_PREFIX . "country` WHERE `iso_code_2` = '" . $this->db->escape($iso_code_2) . "' AND `status` = '1'";
31:
32: $key = md5($sql);
33:
34: $country_data = $this->cache->get('country.' . $key);
35:
36: if (!$country_data) {
37: $query = $this->db->query($sql);
38:
39: $country_data = $query->rows;
40:
41: $this->cache->set('country.' . $key, $country_data);
42: }
43:
44: return $country_data;
45: }
46:
47: /**
48: * Get Country By Iso Code 3
49: *
50: * @param string $iso_code_3
51: *
52: * @return array<int, array<string, mixed>>
53: */
54: public function getCountryByIsoCode3(string $iso_code_3): array {
55: $sql = "SELECT * FROM `" . DB_PREFIX . "country` WHERE `iso_code_3` = '" . $this->db->escape($iso_code_3) . "' AND `status` = '1'";
56:
57: $key = md5($sql);
58:
59: $country_data = $this->cache->get('country.' . $key);
60:
61: if (!$country_data) {
62: $query = $this->db->query($sql);
63:
64: $country_data = $query->rows;
65:
66: $this->cache->set('country.' . md5($sql), $country_data);
67: }
68:
69: return $country_data;
70: }
71:
72: /**
73: * Get Countries
74: *
75: * @return array<int, array<string, mixed>>
76: */
77: public function getCountries(): array {
78: $sql = "SELECT *, `c`.`name` FROM `" . DB_PREFIX . "country` `c` LEFT JOIN `" . DB_PREFIX . "address_format` `af` ON (`c`.`address_format_id` = `af`.`address_format_id`) WHERE `c`.`status` = '1' ORDER BY `c`.`name` ASC";
79:
80: $key = md5($sql);
81:
82: $country_data = $this->cache->get('country.' . $key);
83:
84: if (!$country_data) {
85: $query = $this->db->query($sql);
86:
87: $country_data = $query->rows;
88:
89: $this->cache->set('country.' . $key, $country_data);
90: }
91:
92: return $country_data;
93: }
94: }
95: