1: | <?php
|
2: | namespace Opencart\Catalog\Controller\Mail;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Affiliate extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: |
|
18: | public function index(string &$route, array &$args, &$output): void {
|
19: | $this->load->language('mail/affiliate');
|
20: |
|
21: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
22: |
|
23: | $subject = sprintf($this->language->get('text_subject'), $store_name);
|
24: |
|
25: | $data['text_welcome'] = sprintf($this->language->get('text_welcome'), $store_name);
|
26: |
|
27: | $this->load->model('account/customer_group');
|
28: |
|
29: | if ($this->customer->isLogged()) {
|
30: | $customer_group_id = $this->customer->getGroupId();
|
31: | } else {
|
32: | $customer_group_id = $args[1]['customer_group_id'];
|
33: | }
|
34: |
|
35: | $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
|
36: |
|
37: | if ($customer_group_info) {
|
38: | $data['approval'] = ($this->config->get('config_affiliate_approval') || $customer_group_info['approval']);
|
39: | } else {
|
40: | $data['approval'] = '';
|
41: | }
|
42: |
|
43: | $data['login'] = $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language'), true);
|
44: |
|
45: | $data['store'] = $store_name;
|
46: | $data['store_url'] = $this->config->get('config_url');
|
47: |
|
48: | if ($this->config->get('config_mail_engine')) {
|
49: | $mail_option = [
|
50: | 'parameter' => $this->config->get('config_mail_parameter'),
|
51: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
52: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
53: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
54: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
55: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
56: | ];
|
57: |
|
58: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
59: |
|
60: | if ($this->customer->isLogged()) {
|
61: | $mail->setTo($this->customer->getEmail());
|
62: | } else {
|
63: | $mail->setTo($args[1]['email']);
|
64: | }
|
65: |
|
66: | $mail->setFrom($this->config->get('config_email'));
|
67: | $mail->setSender($store_name);
|
68: | $mail->setSubject($subject);
|
69: | $mail->setHtml($this->load->view('mail/affiliate', $data));
|
70: | $mail->send();
|
71: | }
|
72: | }
|
73: |
|
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | |
82: | |
83: | |
84: |
|
85: | public function alert(string &$route, array &$args, &$output): void {
|
86: |
|
87: | if (in_array('affiliate', (array)$this->config->get('config_mail_alert'))) {
|
88: | $this->load->language('mail/affiliate');
|
89: |
|
90: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
91: |
|
92: | $subject = $this->language->get('text_new_affiliate');
|
93: |
|
94: | if ($this->customer->isLogged()) {
|
95: | $customer_group_id = $this->customer->getGroupId();
|
96: |
|
97: | $data['firstname'] = $this->customer->getFirstName();
|
98: | $data['lastname'] = $this->customer->getLastName();
|
99: | $data['email'] = $this->customer->getEmail();
|
100: | $data['telephone'] = $this->customer->getTelephone();
|
101: | } else {
|
102: | $customer_group_id = $args[1]['customer_group_id'];
|
103: |
|
104: | $data['firstname'] = $args[1]['firstname'];
|
105: | $data['lastname'] = $args[1]['lastname'];
|
106: | $data['email'] = $args[1]['email'];
|
107: | $data['telephone'] = $args[1]['telephone'];
|
108: | }
|
109: |
|
110: | $data['website'] = html_entity_decode($args[1]['website'], ENT_QUOTES, 'UTF-8');
|
111: | $data['company'] = $args[1]['company'];
|
112: |
|
113: | $this->load->model('account/customer_group');
|
114: |
|
115: | $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
|
116: |
|
117: | if ($customer_group_info) {
|
118: | $data['customer_group'] = $customer_group_info['name'];
|
119: | } else {
|
120: | $data['customer_group'] = '';
|
121: | }
|
122: |
|
123: | $data['store'] = $store_name;
|
124: | $data['store_url'] = $this->config->get('config_url');
|
125: |
|
126: | if ($this->config->get('config_mail_engine')) {
|
127: | $mail_option = [
|
128: | 'parameter' => $this->config->get('config_mail_parameter'),
|
129: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
130: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
131: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
132: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
133: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
134: | ];
|
135: |
|
136: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
137: | $mail->setTo($this->config->get('config_email'));
|
138: | $mail->setFrom($this->config->get('config_email'));
|
139: | $mail->setSender($store_name);
|
140: | $mail->setSubject($subject);
|
141: | $mail->setHtml($this->load->view('mail/affiliate_alert', $data));
|
142: | $mail->send();
|
143: |
|
144: |
|
145: | $emails = explode(',', $this->config->get('config_mail_alert_email'));
|
146: |
|
147: | foreach ($emails as $email) {
|
148: | if (oc_strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
149: | $mail->setTo(trim($email));
|
150: | $mail->send();
|
151: | }
|
152: | }
|
153: | }
|
154: | }
|
155: | }
|
156: | }
|
157: | |