1: | <?php
2: | namespace Opencart\Admin\Model\Localisation;
3: | /**
4: | * Class ReturnStatus
5: | *
6: | * @package Opencart\Admin\Model\Localisation
7: | */
8: | class ReturnStatus extends \Opencart\System\Engine\Model {
9: | /**
10: | * Add Return Status
11: | *
12: | * @param array<string, mixed> $data
13: | *
14: | * @return ?int
15: | */
16: | public function addReturnStatus(array $data): ?int {
17: | $return_status_id = 0;
18: |
19: | foreach ($data['return_status'] as $language_id => $return_status) {
20: | if (!$return_status_id) {
21: | $this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($return_status['name']) . "'");
22: |
23: | $return_status_id = $this->db->getLastId();
24: | } else {
25: | $this->model_localisation_return_status->addDescription($return_status_id, $language_id, $return_status);
26: | }
27: | }
28: |
29: | $this->cache->delete('return_status');
30: |
31: | return $return_status_id;
32: | }
33: |
34: | /**
35: | * Edit Return Status
36: | *
37: | * @param int $return_status_id
38: | * @param array<string, mixed> $data
39: | *
40: | * @return void
41: | */
42: | public function editReturnStatus(int $return_status_id, array $data): void {
43: | $this->deleteReturnStatus($return_status_id);
44: |
45: | foreach ($data['return_status'] as $language_id => $return_status) {
46: | $this->model_localisation_return_status->addDescription($return_status_id, $language_id, $return_status);
47: | }
48: |
49: | $this->cache->delete('return_status');
50: | }
51: |
52: | /**
53: | * Delete Return Status
54: | *
55: | * @param int $return_status_id
56: | *
57: | * @return void
58: | */
59: | public function deleteReturnStatus(int $return_status_id): void {
60: | $this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
61: |
62: | $this->cache->delete('return_status');
63: | }
64: |
65: | /**
66: | * Delete Return Statuses By Language ID
67: | *
68: | * @param int $language_id
69: | *
70: | * @return void
71: | */
72: | public function deleteReturnStatusesByLanguageId(int $language_id): void {
73: | $this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$language_id . "'");
74: |
75: | $this->cache->delete('return_status');
76: | }
77: |
78: | /**
79: | * Get Return Status
80: | *
81: | * @param int $return_status_id
82: | *
83: | * @return array<string, mixed>
84: | */
85: | public function getReturnStatus(int $return_status_id): array {
86: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
87: |
88: | return $query->row;
89: | }
90: |
91: | /**
92: | * Get Return Statuses
93: | *
94: | * @param array<string, mixed> $data
95: | *
96: | * @return array<int, array<string, mixed>>
97: | */
98: | public function getReturnStatuses(array $data = []): array {
99: | $sql = "SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `name`";
100: |
101: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
102: | $sql .= " DESC";
103: | } else {
104: | $sql .= " ASC";
105: | }
106: |
107: | if (isset($data['start']) || isset($data['limit'])) {
108: | if ($data['start'] < 0) {
109: | $data['start'] = 0;
110: | }
111: |
112: | if ($data['limit'] < 1) {
113: | $data['limit'] = 20;
114: | }
115: |
116: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
117: | }
118: |
119: | $key = md5($sql);
120: |
121: | $return_status_data = $this->cache->get('return_status.' . $key);
122: |
123: | if (!$return_status_data) {
124: | $query = $this->db->query($sql);
125: |
126: | $return_status_data = $query->rows;
127: |
128: | $this->cache->set('return_status.' . $key, $return_status_data);
129: | }
130: |
131: | return $return_status_data;
132: | }
133: |
134: | /**
135: | * Add Description
136: | *
137: | * @param int $return_status_id
138: | * @param int $language_id
139: | * @param array<string, mixed> $data
140: | *
141: | * @return void
142: | */
143: | public function addDescription(int $return_status_id, int $language_id, array $data): void {
144: | $this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `return_status_id` = '" . (int)$return_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($data['name']) . "'");
145: | }
146: |
147: | /**
148: | * Get Descriptions
149: | *
150: | * @param int $return_status_id
151: | *
152: | * @return array<int, array<string, string>>
153: | */
154: | public function getDescriptions(int $return_status_id): array {
155: | $return_status_data = [];
156: |
157: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
158: |
159: | foreach ($query->rows as $result) {
160: | $return_status_data[$result['language_id']] = ['name' => $result['name']];
161: | }
162: |
163: | return $return_status_data;
164: | }
165: |
166: | /**
167: | * Get Descriptions By Language ID
168: | *
169: | * @param int $language_id
170: | *
171: | * @return array<int, array<string, string>>
172: | */
173: | public function getDescriptionsByLanguageId(int $language_id): array {
174: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$language_id . "'");
175: |
176: | return $query->rows;
177: | }
178: |
179: | /**
180: | * Get Total Return Statuses
181: | *
182: | * @return int
183: | */
184: | public function getTotalReturnStatuses(): int {
185: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
186: |
187: | return (int)$query->row['total'];
188: | }
189: | }
190: |

OpenCart API API documentation generated by ApiGen dev-master