1: | <?php
2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Currency;
3: | /**
4: | * Class ECB
5: | *
6: | * @package Opencart\Catalog\Controller\Extension\Opencart\Currency
7: | */
8: | class ECB 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_ecb_status')) {
18: | $curl = curl_init();
19: |
20: | curl_setopt($curl, CURLOPT_URL, 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
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: | if ($response) {
32: | $dom = new \DOMDocument('1.0', 'UTF-8');
33: | $dom->loadXml($response);
34: |
35: | $cube = $dom->getElementsByTagName('Cube')->item(0);
36: |
37: | $currencies = [];
38: |
39: | $currencies['EUR'] = 1.0000;
40: |
41: | foreach ($cube->getElementsByTagName('Cube') as $currency) {
42: | if ($currency->getAttribute('currency')) {
43: | $currencies[$currency->getAttribute('currency')] = $currency->getAttribute('rate');
44: | }
45: | }
46: |
47: | if (count($currencies) > 1) {
48: | $this->load->model('localisation/currency');
49: |
50: | $results = $this->model_localisation_currency->getCurrencies();
51: |
52: | foreach ($results as $result) {
53: | if (isset($currencies[$result['code']])) {
54: | $from = $currencies['EUR'];
55: |
56: | $to = $currencies[$result['code']];
57: |
58: | $this->model_localisation_currency->editValueByCode($result['code'], 1 / ($currencies[$default] * ($from / $to)));
59: | }
60: | }
61: | }
62: |
63: | $this->model_localisation_currency->editValueByCode($default, 1.00000);
64: |
65: | $this->cache->delete('currency');
66: | }
67: | }
68: | }
69: | }
70: |

OpenCart API API documentation generated by ApiGen dev-master