1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
<?php
class ControllerExtensionTotalVoucher extends Controller {
public function index() {
if ($this->config->get('total_voucher_status')) {
$this->load->language('extension/total/voucher');
if (isset($this->session->data['voucher'])) {
$data['voucher'] = $this->session->data['voucher'];
} else {
$data['voucher'] = '';
}
return $this->load->view('extension/total/voucher', $data);
}
}
public function voucher() {
$this->load->language('extension/total/voucher');
$json = array();
$this->load->model('extension/total/voucher');
if (isset($this->request->post['voucher'])) {
$voucher = $this->request->post['voucher'];
} else {
$voucher = '';
}
$voucher_info = $this->model_extension_total_voucher->getVoucher($voucher);
if (empty($this->request->post['voucher'])) {
$json['error'] = $this->language->get('error_empty');
} elseif ($voucher_info) {
$this->session->data['voucher'] = $this->request->post['voucher'];
$this->session->data['success'] = $this->language->get('text_success');
$json['redirect'] = $this->url->link('checkout/cart');
} else {
$json['error'] = $this->language->get('error_voucher');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function send($route, $args, $output) {
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($args[0]);
// If order status in the complete range create any vouchers that where in the order need to be made available.
if (in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) {
$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'] . "'");
if ($voucher_query->num_rows) {
// Send out any gift voucher mails
$language = new Language($order_info['language_code']);
$language->load($order_info['language_code']);
$language->load('mail/voucher');
foreach ($voucher_query->rows as $voucher) {
// HTML Mail
$data = array();
$data['title'] = sprintf($language->get('text_subject'), $voucher['from_name']);
$data['text_greeting'] = sprintf($language->get('text_greeting'), $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']));
$data['text_from'] = sprintf($language->get('text_from'), $voucher['from_name']);
$data['text_message'] = $language->get('text_message');
$data['text_redeem'] = sprintf($language->get('text_redeem'), $voucher['code']);
$data['text_footer'] = $language->get('text_footer');
if (is_file(DIR_IMAGE . $voucher['image'])) {
$data['image'] = $this->config->get('config_url') . 'image/' . $voucher['image'];
} else {
$data['image'] = '';
}
$data['store_name'] = $order_info['store_name'];
$data['store_url'] = $order_info['store_url'];
$data['message'] = nl2br($voucher['message']);
$mail = new Mail($this->config->get('config_mail_engine'));
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($voucher['to_email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($language->get('text_subject'), $voucher['from_name']), ENT_QUOTES, 'UTF-8'));
$mail->setHtml($this->load->view('mail/voucher', $data));
$mail->send();
}
}
}
}
}
|