1: | <?php
2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Currency;
3: | /**
4: | * Class Fixer
5: | *
6: | * @package Opencart\Catalog\Controller\Extension\Opencart\Currency
7: | */
8: | class Fixer extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Currency
11: | *
12: | * @param string $default
13: | *
14: | * @return void
15: | */
16: | public function currency(string $default = ''): void {
17: | if ($this->config->get('currency_fixer_status')) {
18: | $curl = curl_init();
19: |
20: | curl_setopt($curl, CURLOPT_URL, 'http://data.fixer.io/api/latest?access_key=' . $this->config->get('currency_fixer_api'));
21: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
22: | curl_setopt($curl, CURLOPT_HEADER, false);
23: | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
24: | curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
25: | curl_setopt($curl, CURLOPT_TIMEOUT, 30);
26: |
27: | $response = curl_exec($curl);
28: |
29: | curl_close($curl);
30: |
31: | $response_info = json_decode($response, true);
32: |
33: | if (is_array($response_info) && isset($response_info['rates'])) {
34: | // Compile all the rates into an array
35: | $currencies = [];
36: |
37: | $currencies['EUR'] = 1.0000;
38: |
39: | foreach ($response_info['rates'] as $key => $value) {
40: | $currencies[$key] = $value;
41: | }
42: |
43: | $this->load->model('localisation/currency');
44: |
45: | $results = $this->model_localisation_currency->getCurrencies();
46: |
47: | foreach ($results as $result) {
48: | if (isset($currencies[$result['code']])) {
49: | $from = $currencies['EUR'];
50: |
51: | $to = $currencies[$result['code']];
52: |
53: | $this->model_localisation_currency->editValueByCode($result['code'], 1 / ($currencies[$default] * ($from / $to)));
54: | }
55: | }
56: |
57: | $this->model_localisation_currency->editValueByCode($default, 1);
58: |
59: | $this->cache->delete('currency');
60: | }
61: | }
62: | }
63: | }
64: |

OpenCart API API documentation generated by ApiGen dev-master