1: | <?php
2: | namespace Opencart\Catalog\Model\Localisation;
3: | /**
4: | * Class Currency
5: | *
6: | * @package Opencart\Catalog\Model\Localisation
7: | */
8: | class Currency extends \Opencart\System\Engine\Model {
9: | /**
10: | * Edit Value By Code
11: | *
12: | * @param string $code
13: | * @param float $value
14: | *
15: | * @return void
16: | */
17: | public function editValueByCode(string $code, float $value): void {
18: | $this->db->query("UPDATE `" . DB_PREFIX . "currency` SET `value` = '" . (float)$value . "', `date_modified` = NOW() WHERE `code` = '" . $this->db->escape($code) . "'");
19: |
20: | $this->cache->delete('currency');
21: | }
22: |
23: | /**
24: | * Get Currency
25: | *
26: | * @param int $currency_id
27: | *
28: | * @return array<string, mixed>
29: | */
30: | public function getCurrency(int $currency_id): array {
31: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `currency_id` = '" . (int)$currency_id . "'");
32: |
33: | return $query->row;
34: | }
35: |
36: | /**
37: | * Get Currency By Code
38: | *
39: | * @param string $currency
40: | *
41: | * @return array<string, mixed>
42: | */
43: | public function getCurrencyByCode(string $currency): array {
44: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `code` = '" . $this->db->escape($currency) . "' AND `status` = '1'");
45: |
46: | return $query->row;
47: | }
48: |
49: | /**
50: | * Get Currencies
51: | *
52: | * @return array<string, array<string, mixed>>
53: | */
54: | public function getCurrencies(): array {
55: | $sql = "SELECT * FROM `" . DB_PREFIX . "currency` WHERE `status` = '1' ORDER BY `title` ASC";
56: |
57: | $currency_data = $this->cache->get('currency.' . md5($sql));
58: |
59: | if (!$currency_data) {
60: | $currency_data = [];
61: |
62: | $query = $this->db->query($sql);
63: |
64: | foreach ($query->rows as $result) {
65: | $currency_data[$result['code']] = [
66: | 'currency_id' => $result['currency_id'],
67: | 'title' => $result['title'],
68: | 'code' => $result['code'],
69: | 'symbol_left' => $result['symbol_left'],
70: | 'symbol_right' => $result['symbol_right'],
71: | 'decimal_place' => $result['decimal_place'],
72: | 'value' => $result['value'],
73: | 'status' => $result['status'],
74: | 'date_modified' => $result['date_modified']
75: | ];
76: | }
77: |
78: | $this->cache->set('currency.' . md5($sql), $currency_data);
79: | }
80: |
81: | return $currency_data;
82: | }
83: | }
84: |

OpenCart API API documentation generated by ApiGen dev-master