1: | <?php
2: | namespace Opencart\Admin\Controller\Mail;
3: | /**
4: | * Class Customer
5: | *
6: | * @package Opencart\Admin\Controller\Mail
7: | */
8: | class Customer extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Approve
11: | *
12: | * @param string $route
13: | * @param array<int, mixed> $args
14: | * @param mixed $output
15: | *
16: | * @throws \Exception
17: | *
18: | * @return void
19: | */
20: | public function approve(string &$route, array &$args, &$output): void {
21: | if (isset($args[0])) {
22: | $customer_id = (int)$args[0];
23: | } else {
24: | $customer_id = 0;
25: | }
26: |
27: | $this->load->model('customer/customer');
28: |
29: | $customer_info = $this->model_customer_customer->getCustomer($customer_id);
30: |
31: | if ($customer_info) {
32: | $this->load->model('setting/store');
33: |
34: | $store_info = $this->model_setting_store->getStore($customer_info['store_id']);
35: |
36: | if ($store_info) {
37: | $this->load->model('setting/setting');
38: |
39: | $store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
40: | $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
41: | $store_url = $store_info['url'];
42: | } else {
43: | $store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
44: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
45: | $store_url = HTTP_CATALOG;
46: | }
47: |
48: | $this->load->model('localisation/language');
49: |
50: | $language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
51: |
52: | if ($language_info) {
53: | $language_code = $language_info['code'];
54: | } else {
55: | $language_code = $this->config->get('config_language');
56: | }
57: |
58: | // Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
59: | $this->load->language('default', 'mail', $language_code);
60: | $this->load->language('mail/customer_approve', 'mail', $language_code);
61: |
62: | // Add language vars to the template folder
63: | $results = $this->language->all('mail');
64: |
65: | foreach ($results as $key => $value) {
66: | $data[$key] = $value;
67: | }
68: |
69: | $this->load->model('tool/image');
70: |
71: | if (is_file(DIR_IMAGE . $store_logo)) {
72: | $data['logo'] = $store_url . 'image/' . $store_logo;
73: | } else {
74: | $data['logo'] = '';
75: | }
76: |
77: | $subject = sprintf($this->language->get('mail_text_subject'), $store_name);
78: |
79: | $data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
80: |
81: | $data['login'] = $store_url . 'index.php?route=account/login';
82: |
83: | $data['store'] = $store_name;
84: | $data['store_url'] = $store_url;
85: |
86: | if ($this->config->get('config_mail_engine')) {
87: | $mail_option = [
88: | 'parameter' => $this->config->get('config_mail_parameter'),
89: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
90: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
91: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
92: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
93: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
94: | ];
95: |
96: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
97: | $mail->setTo($customer_info['email']);
98: | $mail->setFrom($this->config->get('config_email'));
99: | $mail->setSender($store_name);
100: | $mail->setSubject($subject);
101: | $mail->setHtml($this->load->view('mail/customer_approve', $data));
102: | $mail->send();
103: | }
104: | }
105: | }
106: |
107: | /**
108: | * Deny
109: | *
110: | * @param string $route
111: | * @param array<int, mixed> $args
112: | * @param mixed $output
113: | *
114: | * @throws \Exception
115: | *
116: | * @return void
117: | */
118: | public function deny(string &$route, array &$args, &$output): void {
119: | if (isset($args[0])) {
120: | $customer_id = (int)$args[0];
121: | } else {
122: | $customer_id = 0;
123: | }
124: |
125: | $this->load->model('customer/customer');
126: |
127: | $customer_info = $this->model_customer_customer->getCustomer($customer_id);
128: |
129: | if ($customer_info) {
130: | $this->load->model('setting/store');
131: |
132: | $store_info = $this->model_setting_store->getStore($customer_info['store_id']);
133: |
134: | if ($store_info) {
135: | $this->load->model('setting/setting');
136: |
137: | $store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $customer_info['store_id']), ENT_QUOTES, 'UTF-8');
138: | $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
139: | $store_url = $store_info['url'];
140: | } else {
141: | $store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
142: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
143: | $store_url = HTTP_CATALOG;
144: | }
145: |
146: | $this->load->model('localisation/language');
147: |
148: | $language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
149: |
150: | if ($language_info) {
151: | $language_code = $language_info['code'];
152: | } else {
153: | $language_code = $this->config->get('config_language');
154: | }
155: |
156: | // Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
157: | $this->load->language('default', 'mail', $language_code);
158: | $this->load->language('mail/customer_deny', 'mail', $language_code);
159: |
160: | // Add language vars to the template folder
161: | $results = $this->language->all('mail');
162: |
163: | foreach ($results as $key => $value) {
164: | $data[$key] = $value;
165: | }
166: |
167: | $this->load->model('tool/image');
168: |
169: | if (is_file(DIR_IMAGE . $store_logo)) {
170: | $data['logo'] = $store_url . 'image/' . $store_logo;
171: | } else {
172: | $data['logo'] = '';
173: | }
174: |
175: | $subject = sprintf($this->language->get('mail_text_subject'), $store_name);
176: |
177: | $data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
178: |
179: | $data['contact'] = $store_url . 'index.php?route=information/contact';
180: |
181: | $data['store'] = $store_name;
182: | $data['store_url'] = $store_url;
183: |
184: | if ($this->config->get('config_mail_engine')) {
185: | $mail_option = [
186: | 'parameter' => $this->config->get('config_mail_parameter'),
187: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
188: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
189: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
190: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
191: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
192: | ];
193: |
194: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
195: | $mail->setTo($customer_info['email']);
196: | $mail->setFrom($this->config->get('config_email'));
197: | $mail->setSender($store_name);
198: | $mail->setSubject($subject);
199: | $mail->setHtml($this->load->view('mail/customer_deny', $data));
200: | $mail->send();
201: | }
202: | }
203: | }
204: | }
205: |

OpenCart API API documentation generated by ApiGen dev-master