Back to Opencart

File catalog\controller\mail\voucher.php

docs/api/source-catalog.controller.mail.voucher.html

4.1.0.38.7 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Catalog\Controller\Mail; | | 3: | /** | | 4: | * Class Voucher | | 5: | * | | 6: | * @package Opencart\Catalog\Controller\Mail | | 7: | */ | | 8: | class Voucher extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * @param string $route | | 11: | * @param array<int, mixed> $args | | 12: | * @param mixed $output | | 13: | * | | 14: | * @throws \Exception | | 15: | * | | 16: | * @return void | | 17: | */ | | 18: | public function index(string &$route, array &$args, &$output): void { | | 19: | $this->load->model('checkout/order'); | | 20: | | | 21: | $order_info = $this->model_checkout_order->getOrder($args[0]); | | 22: | | | 23: | // If order status in the complete range create any vouchers that where in the order need to be made available. | | 24: | if ($order_info && in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) { | | 25: | // Send out any gift voucher mails | | 26: | $voucher_query = $this->db->query("SELECT *, vtd.name AS theme FROM " . DB\_PREFIX . "voucher v LEFT JOIN " . DB\_PREFIX . "voucher\_theme vt ON (v.voucher\_theme\_id = vt.voucher\_theme\_id) LEFT JOIN " . DB\_PREFIX . "voucher\_theme\_description vtd ON (vt.voucher\_theme\_id = vtd.voucher\_theme\_id) WHERE v.order\_id = '" . (int)$order_info['order_id'] . "' AND vtd.language_id = '" . (int)$order_info['language_id'] . "'"); | | 27: | | | 28: | if ($voucher_query->num_rows) { | | 29: | // Send the email in the correct language | | 30: | $this->load->model('localisation/language'); | | 31: | | | 32: | $language_info = $this->model_localisation_language->getLanguage($order_info['language_id']); | | 33: | | | 34: | if ($language_info) { | | 35: | $language_code = $language_info['code']; | | 36: | } else { | | 37: | $language_code = $this->config->get('config_language'); | | 38: | } | | 39: | | | 40: | // Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool. | | 41: | $this->load->language('default', 'mail', $language_code); | | 42: | $this->load->language('mail/voucher', 'mail', $language_code); | | 43: | | | 44: | // Add language vars to the template folder | | 45: | $results = $this->language->all('mail'); | | 46: | | | 47: | foreach ($results as $key => $value) { | | 48: | $data[$key] = $value; | | 49: | } | | 50: | | | 51: | if ($this->config->get('config_mail_engine')) { | | 52: | $mail_option = [ | | 53: | 'parameter' => $this->config->get('config_mail_parameter'), | | 54: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'), | | 55: | 'smtp_username' => $this->config->get('config_mail_smtp_username'), | | 56: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'), | | 57: | 'smtp_port' => $this->config->get('config_mail_smtp_port'), | | 58: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout') | | 59: | ]; | | 60: | | | 61: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option); | | 62: | | | 63: | foreach ($voucher_query->rows as $voucher) { | | 64: | $from_name = html_entity_decode($voucher['from_name'], ENT_QUOTES, 'UTF-8'); | | 65: | | | 66: | // HTML Mail | | 67: | $subject = sprintf($this->language->get('mail_text_subject'), $from_name); | | 68: | | | 69: | $data['title'] = sprintf($this->language->get('mail_text_subject'), $from_name); | | 70: | | | 71: | $data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])); | | 72: | $data['text_from'] = sprintf($this->language->get('mail_text_from'), $from_name); | | 73: | $data['text_redeem'] = sprintf($this->language->get('mail_text_redeem'), $voucher['code']); | | 74: | | | 75: | if (is_file(DIR_IMAGE . $voucher['image'])) { | | 76: | $data['image'] = $this->config->get('config_url') . 'image/' . $voucher['image']; | | 77: | } else { | | 78: | $data['image'] = ''; | | 79: | } | | 80: | | | 81: | $data['message'] = nl2br($voucher['message']); | | 82: | | | 83: | $data['store_name'] = $order_info['store_name']; | | 84: | $data['store_url'] = $order_info['store_url']; | | 85: | | | 86: | $mail->setTo($voucher['to_email']); | | 87: | $mail->setFrom($this->config->get('config_email')); | | 88: | $mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); | | 89: | $mail->setSubject($subject); | | 90: | $mail->setHtml($this->load->view('mail/voucher', $data)); | | 91: | $mail->send(); | | 92: | } | | 93: | } | | 94: | } | | 95: | } | | 96: | } | | 97: | } | | 98: | |

OpenCart API API documentation generated by ApiGen dev-master