1: | <?php
2: | namespace Opencart\Catalog\Controller\Startup;
3: | /**
4: | * Class Currency
5: | *
6: | * @package Opencart\Catalog\Controller\Startup
7: | */
8: | class Currency extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @return void
11: | */
12: | public function index(): void {
13: | $code = '';
14: |
15: | $this->load->model('localisation/currency');
16: |
17: | $currencies = $this->model_localisation_currency->getCurrencies();
18: |
19: | if (isset($this->session->data['currency'])) {
20: | $code = $this->session->data['currency'];
21: | }
22: |
23: | if (isset($this->request->cookie['currency']) && !array_key_exists($code, $currencies)) {
24: | $code = $this->request->cookie['currency'];
25: | }
26: |
27: | if (!array_key_exists($code, $currencies)) {
28: | $code = $this->config->get('config_currency');
29: | }
30: |
31: | if (!isset($this->session->data['currency']) || $this->session->data['currency'] != $code) {
32: | $this->session->data['currency'] = $code;
33: | }
34: |
35: | // Set a new currency cookie if the code does not match the current one
36: | if (!isset($this->request->cookie['currency']) || $this->request->cookie['currency'] != $code) {
37: | $option = [
38: | 'expires' => time() + 60 * 60 * 24 * 30,
39: | 'path' => '/',
40: | 'SameSite' => 'Lax'
41: | ];
42: |
43: | setcookie('currency', $code, $option);
44: | }
45: |
46: | $this->registry->set('currency', new \Opencart\System\Library\Cart\Currency($this->registry));
47: | }
48: | }
49: |

OpenCart API API documentation generated by ApiGen dev-master