1: | <?php
2: | namespace Opencart\Catalog\Controller\Account;
3: | /**
4: | * Class Newsletter
5: | *
6: | * @package Opencart\Catalog\Controller\Account
7: | */
8: | class Newsletter extends \Opencart\System\Engine\Controller {
9: | /**
10: | * @return void
11: | */
12: | public function index(): void {
13: | $this->load->language('account/newsletter');
14: |
15: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
16: | $this->session->data['redirect'] = $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language'));
17: |
18: | $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
19: | }
20: |
21: | $this->document->setTitle($this->language->get('heading_title'));
22: |
23: | $data['breadcrumbs'] = [];
24: |
25: | $data['breadcrumbs'][] = [
26: | 'text' => $this->language->get('text_home'),
27: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
28: | ];
29: |
30: | $data['breadcrumbs'][] = [
31: | 'text' => $this->language->get('text_account'),
32: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
33: | ];
34: |
35: | $data['breadcrumbs'][] = [
36: | 'text' => $this->language->get('text_newsletter'),
37: | 'href' => $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
38: | ];
39: |
40: | $data['save'] = $this->url->link('account/newsletter.save', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
41: | $data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
42: |
43: | $data['newsletter'] = $this->customer->getNewsletter();
44: |
45: | $data['column_left'] = $this->load->controller('common/column_left');
46: | $data['column_right'] = $this->load->controller('common/column_right');
47: | $data['content_top'] = $this->load->controller('common/content_top');
48: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
49: | $data['footer'] = $this->load->controller('common/footer');
50: | $data['header'] = $this->load->controller('common/header');
51: |
52: | $this->response->setOutput($this->load->view('account/newsletter', $data));
53: | }
54: |
55: | /**
56: | * Save
57: | *
58: | * @return void
59: | */
60: | public function save(): void {
61: | $this->load->language('account/newsletter');
62: |
63: | $json = [];
64: |
65: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
66: | $this->session->data['redirect'] = $this->url->link('account/newsletter', 'language=' . $this->config->get('config_language'));
67: |
68: | $json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
69: | }
70: |
71: | if (!$json) {
72: | $this->load->model('account/customer');
73: |
74: | $this->model_account_customer->editNewsletter($this->customer->getId(), $this->request->post['newsletter']);
75: |
76: | $this->session->data['success'] = $this->language->get('text_success');
77: |
78: | $json['redirect'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true);
79: | }
80: |
81: | $this->response->addHeader('Content-Type: application/json');
82: | $this->response->setOutput(json_encode($json));
83: | }
84: | }
85: |

OpenCart API API documentation generated by ApiGen dev-master