1: <?php
2: namespace Opencart\Catalog\Controller\Mail;
3: /**
4: * Class Transaction
5: *
6: * @package Opencart\Catalog\Controller\Mail
7: */
8: class Transaction extends \Opencart\System\Engine\Controller {
9: // catalog/model/account/customer/addTransaction/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: $this->load->language('mail/transaction');
21:
22: $this->load->model('account/customer');
23:
24: $customer_info = $this->model_account_customer->getCustomer($args[0]);
25:
26: if ($customer_info) {
27: $this->load->model('setting/store');
28:
29: $store_info = $this->model_setting_store->getStore($customer_info['store_id']);
30:
31: if ($store_info) {
32: $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
33: $store_url = $store_info['store_url'];
34: } else {
35: $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
36: $store_url = $this->config->get('config_url');
37: }
38:
39: $this->load->model('localisation/language');
40:
41: $language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
42:
43: if ($language_info) {
44: $language_code = $language_info['code'];
45: } else {
46: $language_code = $this->config->get('config_language');
47: }
48:
49: // Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
50: $this->load->language('default', 'mail', $language_code);
51: $this->load->language('mail/transaction', 'mail', $language_code);
52:
53: // Add language vars to the template folder
54: $results = $this->language->all('mail');
55:
56: foreach ($results as $key => $value) {
57: $data[$key] = $value;
58: }
59:
60: $subject = sprintf($this->language->get('mail_text_subject'), $store_name);
61:
62: $data['text_received'] = sprintf($this->language->get('mail_text_received'), $store_name);
63:
64: $data['amount'] = $this->currency->format($args[2], $this->config->get('config_currency'));
65:
66: $this->load->model('account/transaction');
67:
68: $data['total'] = $this->currency->format($this->model_account_transaction->getTransactionTotal($args[0]), $this->config->get('config_currency'));
69:
70: $data['store'] = $store_name;
71: $data['store_url'] = $store_url;
72:
73: if ($this->config->get('config_mail_engine')) {
74: $mail_option = [
75: 'parameter' => $this->config->get('config_mail_parameter'),
76: 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
77: 'smtp_username' => $this->config->get('config_mail_smtp_username'),
78: 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
79: 'smtp_port' => $this->config->get('config_mail_smtp_port'),
80: 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
81: ];
82:
83: $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
84: $mail->setTo($customer_info['email']);
85: $mail->setFrom($this->config->get('config_email'));
86: $mail->setSender($store_name);
87: $mail->setSubject($subject);
88: $mail->setHtml($this->load->view('mail/transaction', $data));
89: $mail->send();
90: }
91: }
92: }
93: }
94: