1: <?php
2: namespace Opencart\Catalog\Controller\Mail;
3: /**
4: * Class Review
5: *
6: * @package Opencart\Catalog\Controller\Mail
7: */
8: class Review extends \Opencart\System\Engine\Controller {
9: // catalog/model/catalog/review/addReview/after
10: /**
11: * @param string $route
12: * @param array<int, mixed> $args
13: * @param mixed $output
14: *
15: * @throws \Exception
16: *
17: * @return void
18: */
19: public function index(string &$route, array &$args, &$output): void {
20: if (in_array('review', (array)$this->config->get('config_mail_alert'))) {
21: $this->load->language('mail/review');
22:
23: $this->load->model('catalog/product');
24:
25: $product_info = $this->model_catalog_product->getProduct((int)$args[0]);
26:
27: if ($product_info) {
28: $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
29:
30: $subject = sprintf($this->language->get('text_subject'), $store_name);
31:
32: $data['product'] = html_entity_decode($product_info['name'], ENT_QUOTES, 'UTF-8');
33: $data['reviewer'] = html_entity_decode($args[1]['author'], ENT_QUOTES, 'UTF-8');
34: $data['rating'] = (int)$args[1]['rating'];
35: $data['text'] = nl2br($args[1]['text']);
36:
37: $data['store'] = $store_name;
38: $data['store_url'] = $this->config->get('config_url');
39:
40: if ($this->config->get('config_mail_engine')) {
41: $mail_option = [
42: 'parameter' => $this->config->get('config_mail_parameter'),
43: 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
44: 'smtp_username' => $this->config->get('config_mail_smtp_username'),
45: 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
46: 'smtp_port' => $this->config->get('config_mail_smtp_port'),
47: 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
48: ];
49:
50: $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
51: $mail->setTo($this->config->get('config_email'));
52: $mail->setFrom($this->config->get('config_email'));
53: $mail->setSender($store_name);
54: $mail->setSubject($subject);
55: $mail->setHtml($this->load->view('mail/review', $data));
56: $mail->send();
57:
58: // Send to additional alert emails
59: $emails = explode(',', (string)$this->config->get('config_mail_alert_email'));
60:
61: foreach ($emails as $email) {
62: if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
63: $mail->setTo(trim($email));
64: $mail->send();
65: }
66: }
67: }
68: }
69: }
70: }
71: }
72: