1: <?php
2: namespace Opencart\Catalog\Controller\Common;
3: /**
4: * Class Cookie
5: *
6: * @package Opencart\Catalog\Controller\Common
7: */
8: class Cookie extends \Opencart\System\Engine\Controller {
9: /**
10: * @return string
11: */
12: public function index(): string {
13: if ($this->config->get('config_cookie_id') && !isset($this->request->cookie['policy'])) {
14: $this->load->model('catalog/information');
15:
16: $information_info = $this->model_catalog_information->getInformation($this->config->get('config_cookie_id'));
17:
18: if ($information_info) {
19: $this->load->language('common/cookie');
20:
21: $data['text_cookie'] = sprintf($this->language->get('text_cookie'), $this->url->link('information/information.info', 'language=' . $this->config->get('config_language') . '&information_id=' . $information_info['information_id']));
22:
23: $data['agree'] = $this->url->link('common/cookie.confirm', 'language=' . $this->config->get('config_language') . '&agree=1');
24: $data['disagree'] = $this->url->link('common/cookie.confirm', 'language=' . $this->config->get('config_language') . '&agree=0');
25:
26: return $this->load->view('common/cookie', $data);
27: }
28: }
29:
30: return '';
31: }
32:
33: /**
34: * Confirm
35: *
36: * @return void
37: */
38: public function confirm(): void {
39: $json = [];
40:
41: if (isset($this->request->get['agree'])) {
42: $agree = $this->request->get['agree'];
43: } else {
44: $agree = '0';
45: }
46:
47: if ($this->config->get('config_cookie_id') && !isset($this->request->cookie['policy'])) {
48: $this->load->language('common/cookie');
49:
50: $option = [
51: 'expires' => time() + 60 * 60 * 24 * 365,
52: 'path' => $this->config->get('session_path'),
53: 'SameSite' => $this->config->get('config_session_samesite')
54: ];
55:
56: setcookie('policy', $agree, $option);
57:
58: $json['success'] = $this->language->get('text_success');
59: }
60:
61: $this->response->addHeader('Content-Type: application/json');
62: $this->response->setOutput(json_encode($json));
63: }
64: }
65: