| 1: | <?php
|
| 2: | namespace Opencart\Admin\Controller\Mail;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Voucher extends \Opencart\System\Engine\Controller {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: |
|
| 18: | public function index(int $voucher_id): void {
|
| 19: | $this->load->model('sale/order');
|
| 20: |
|
| 21: | $voucher_info = $this->model_sale_voucher->getVoucher($voucher_id);
|
| 22: |
|
| 23: | if ($voucher_info) {
|
| 24: |
|
| 25: | $this->load->language('mail/voucher');
|
| 26: |
|
| 27: | if ($voucher_info['order_id']) {
|
| 28: | $order_id = $voucher_info['order_id'];
|
| 29: | } else {
|
| 30: | $order_id = 0;
|
| 31: | }
|
| 32: |
|
| 33: | $order_info = $this->model_sale_order->getOrder($order_id);
|
| 34: |
|
| 35: |
|
| 36: | if ($order_info) {
|
| 37: | $this->load->model('localisation/language');
|
| 38: |
|
| 39: | $language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
|
| 40: |
|
| 41: | if ($language_info) {
|
| 42: | $language_code = $language_info['code'];
|
| 43: | } else {
|
| 44: | $language_code = $this->config->get('config_language');
|
| 45: | }
|
| 46: |
|
| 47: | $this->load->language('default', 'mail', $language_code);
|
| 48: | $this->load->language('mail/voucher', 'mail', $language_code);
|
| 49: |
|
| 50: | $store_name = html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8');
|
| 51: |
|
| 52: |
|
| 53: | $results = $this->language->all('mail');
|
| 54: |
|
| 55: | foreach ($results as $key => $value) {
|
| 56: | $data[$key] = $value;
|
| 57: | }
|
| 58: |
|
| 59: | $from_name = html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8');
|
| 60: |
|
| 61: | $subject = sprintf($this->language->get('mail_text_subject'), $from_name);
|
| 62: |
|
| 63: |
|
| 64: | $data['title'] = sprintf($this->language->get('mail_text_subject'), $from_name);
|
| 65: |
|
| 66: | $data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $this->currency->format($voucher_info['amount'], (!empty($order_info['currency_code']) ? $order_info['currency_code'] : $this->config->get('config_currency')), (!empty($order_info['currency_value']) ? $order_info['currency_value'] : $this->currency->getValue($this->config->get('config_currency')))));
|
| 67: | $data['text_from'] = sprintf($this->language->get('mail_text_from'), $from_name);
|
| 68: | $data['text_redeem'] = sprintf($this->language->get('mail_text_redeem'), $voucher_info['code']);
|
| 69: |
|
| 70: | $this->load->model('sale/voucher_theme');
|
| 71: |
|
| 72: | $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']);
|
| 73: |
|
| 74: | if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) {
|
| 75: | $data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image'];
|
| 76: | } else {
|
| 77: | $data['image'] = '';
|
| 78: | }
|
| 79: |
|
| 80: | $data['message'] = nl2br($voucher_info['message']);
|
| 81: |
|
| 82: | $data['store_name'] = $store_name;
|
| 83: | $data['store_url'] = $order_info['store_url'];
|
| 84: | } else {
|
| 85: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
| 86: |
|
| 87: | $from_name = html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8');
|
| 88: |
|
| 89: | $subject = html_entity_decode(sprintf($this->language->get('text_subject'), $from_name), ENT_QUOTES, 'UTF-8');
|
| 90: |
|
| 91: | $data['title'] = sprintf($this->language->get('text_subject'), $from_name);
|
| 92: |
|
| 93: | $data['text_greeting'] = sprintf($this->language->get('text_greeting'), $this->currency->format($voucher_info['amount'], $this->config->get('config_currency')));
|
| 94: | $data['text_from'] = sprintf($this->language->get('text_from'), $from_name);
|
| 95: | $data['text_redeem'] = sprintf($this->language->get('text_redeem'), $voucher_info['code']);
|
| 96: |
|
| 97: | $this->load->model('sale/voucher_theme');
|
| 98: |
|
| 99: | $voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']);
|
| 100: |
|
| 101: | if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) {
|
| 102: | $data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image'];
|
| 103: | } else {
|
| 104: | $data['image'] = '';
|
| 105: | }
|
| 106: |
|
| 107: | $data['message'] = nl2br($voucher_info['message']);
|
| 108: |
|
| 109: | $data['store_name'] = $store_name;
|
| 110: | $data['store_url'] = HTTP_CATALOG;
|
| 111: | }
|
| 112: |
|
| 113: | if ($this->config->get('config_mail_engine')) {
|
| 114: | $mail_option = [
|
| 115: | 'parameter' => $this->config->get('config_mail_parameter'),
|
| 116: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
| 117: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
| 118: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
| 119: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
| 120: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
| 121: | ];
|
| 122: |
|
| 123: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
| 124: | $mail->setTo($voucher_info['to_email']);
|
| 125: | $mail->setFrom($this->config->get('config_email'));
|
| 126: | $mail->setSender($store_name);
|
| 127: | $mail->setSubject($subject);
|
| 128: | $mail->setHtml($this->load->view('mail/voucher', $data));
|
| 129: | $mail->send();
|
| 130: | }
|
| 131: | }
|
| 132: | }
|
| 133: | }
|
| 134: | |