first commit

This commit is contained in:
sujan
2024-08-06 18:06:00 +05:45
commit a2fa49071a
2745 changed files with 391199 additions and 0 deletions

View File

@ -0,0 +1,174 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Affiliate
*
* @package Opencart\Admin\Controller\Mail
*/
class Affiliate extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function approve(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$customer_id = (int)$args[0];
} else {
$customer_id = 0;
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
if ($customer_info) {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
if ($store_info) {
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/affiliate_approve', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
$data['login'] = $store_url . 'index.php?route=affiliate/login';
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($customer_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/affiliate_approve', $data));
$mail->send();
}
}
}
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function deny(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$customer_id = (int)$args[0];
} else {
$customer_id = 0;
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
if ($customer_info) {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
if ($store_info) {
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/affiliate_deny', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
$data['contact'] = $store_url . 'index.php?route=information/contact';
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($customer_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/affiliate_deny', $data));
$mail->send();
}
}
}
}

View File

@ -0,0 +1,119 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Authorize
*
* @package Opencart\Admin\Controller\Mail
*/
class Authorize extends \Opencart\System\Engine\Controller {
// admin/model/user/user/editCode/after
/**
* @param $route
* @param $args
* @param $output
*
* @return void
* @throws \Exception
*/
public function index(&$route, &$args, &$output) {
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = '';
}
$email = $this->user->getEmail();
if (isset($this->session->data['code'])) {
$code = $this->session->data['code'];
} else {
$code = '';
}
if ($email && $code && ($route == 'common/authorize.send') && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->load->language('mail/authorize');
$data['username'] = $this->user->getUsername();
$data['code'] = $code;
$data['ip'] = $this->request->server['REMOTE_ADDR'];
$data['store'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($email);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($this->config->get('config_name'));
$mail->setSubject($this->language->get('text_subject'));
$mail->setText($this->load->view('mail/authorize', $data));
$mail->send();
}
}
}
// admin/model/user/user/editCode/after
/**
* @param $route
* @param $args
* @param $output
*
* @return void
* @throws \Exception
*/
public function reset(&$route, &$args, &$output) {
if (isset($this->request->get['route'])) {
$route = $this->request->get['route'];
} else {
$route = '';
}
if (isset($args[0])) {
$email = (string)$args[0];
} else {
$email = '';
}
if (isset($args[1])) {
$code = (string)$args[1];
} else {
$code = '';
}
if ($email && $code && ($route == 'common/authorize.confirm') && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->load->language('mail/authorize_reset');
$data['username'] = $this->user->getUsername();
$data['reset'] = $this->url->link('common/authorize.reset', 'email=' . $email . '&code=' . $code, true);
$data['ip'] = $this->request->server['REMOTE_ADDR'];
$data['store'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($email);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($this->config->get('config_name'));
$mail->setSubject($this->language->get('text_subject'));
$mail->setText($this->load->view('mail/authorize_reset', $data));
$mail->send();
}
}
}
}

View File

@ -0,0 +1,198 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Customer
*
* @package Opencart\Admin\Controller\Mail
*/
class Customer extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function approve(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$customer_id = (int)$args[0];
} else {
$customer_id = 0;
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
if ($customer_info) {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/customer_approve', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
$data['login'] = $store_url . 'index.php?route=account/login';
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($customer_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/customer_approve', $data));
$mail->send();
}
}
}
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function deny(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$customer_id = (int)$args[0];
} else {
$customer_id = 0;
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
if ($customer_info) {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $customer_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/customer_deny', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
$data['contact'] = $store_url . 'index.php?route=information/contact';
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($customer_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/customer_deny', $data));
$mail->send();
}
}
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Forgotten
*
* @package Opencart\Admin\Controller\Mail
*/
class Forgotten extends \Opencart\System\Engine\Controller {
/**
*
* admin/model/user/user/editCode/after
*
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = '';
}
if (isset($args[0])) {
$email = urldecode((string)$args[0]);
} else {
$email = '';
}
if (isset($args[1])) {
$code = (string)$args[1];
} else {
$code = '';
}
if ($email && $code && ($route == 'common/forgotten.confirm') && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->load->language('mail/forgotten');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$subject = sprintf($this->language->get('text_subject'), $store_name);
$data['text_greeting'] = sprintf($this->language->get('text_greeting'), $store_name);
$data['reset'] = $this->url->link('common/forgotten.reset', 'email=' . $email . '&code=' . $code, true);
$data['ip'] = $this->request->server['REMOTE_ADDR'];
$data['store'] = $store_name;
$data['store_url'] = $this->config->get('config_store_url');
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($email);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/forgotten', $data));
$mail->send();
}
}
}
}

View File

@ -0,0 +1,493 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Gdpr
*
* @package Opencart\Admin\Controller\Mail
*/
class Gdpr extends \Opencart\System\Engine\Controller {
// admin/model/customer/gdpr/editStatus
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
*/
public function index(string &$route, array &$args, mixed &$output): void {
$this->load->model('customer/gdpr');
$gdpr_info = $this->model_customer_gdpr->getGdpr($args[0]);
if ($gdpr_info) {
// Choose which mail to send
// Export plus complete
if ($gdpr_info['action'] == 'export' && (int)$args[1] == 3) {
$this->export($gdpr_info);
}
// Approve plus processing
if ($gdpr_info['action'] == 'approve' && (int)$args[1] == 2) {
$this->approve($gdpr_info);
}
// Remove plus complete
if ($gdpr_info['action'] == 'remove' && (int)$args[1] == 3) {
$this->remove($gdpr_info);
}
// Deny
if ($args[1] == -1) {
$this->deny($gdpr_info);
}
}
}
/**
* @param array $gdpr_info
*
* @return void
* @throws \Exception
*/
public function export(array $gdpr_info): void {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
// Send the email in the correct language
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/gdpr_export', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
if ($customer_info) {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
} else {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
}
// Personal info
if ($customer_info) {
$data['customer_id'] = $customer_info['customer_id'];
$data['firstname'] = $customer_info['firstname'];
$data['lastname'] = $customer_info['lastname'];
$data['email'] = $customer_info['email'];
$data['telephone'] = $customer_info['telephone'];
}
// Addresses
$data['addresses'] = [];
if ($customer_info) {
$results = $this->model_customer_customer->getAddresses($customer_info['customer_id']);
foreach ($results as $result) {
$address = [
'firstname' => $result['firstname'],
'lastname' => $result['lastname'],
'address_1' => $result['address_1'],
'address_2' => $result['address_2'],
'city' => $result['city'],
'postcode' => $result['postcode'],
'country' => $result['country'],
'zone' => $result['zone']
];
if (!in_array($address, $data['addresses'])) {
$data['addresses'][] = $address;
}
}
}
// Order Addresses
$this->load->model('sale/order');
$results = $this->model_sale_order->getOrders(['filter_email' => $gdpr_info['email']]);
foreach ($results as $result) {
$order_info = $this->model_sale_order->getOrder($result['order_id']);
if ($order_info['payment_country_id']) {
$address = [
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'country' => $order_info['payment_country'],
'zone' => $order_info['payment_zone']
];
if (!in_array($address, $data['addresses'])) {
$data['addresses'][] = $address;
}
}
if ($order_info['shipping_country_id']) {
$address = [
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'country' => $order_info['shipping_country'],
'zone' => $order_info['shipping_zone']
];
if (!in_array($address, $data['addresses'])) {
$data['addresses'][] = $address;
}
}
}
// Ip's
$data['ips'] = [];
if ($customer_info) {
$results = $this->model_customer_customer->getIps($customer_info['customer_id']);
foreach ($results as $result) {
$data['ips'][] = [
'ip' => $result['ip'],
'date_added' => date($this->language->get('mail_datetime_format'), strtotime($result['date_added']))
];
}
}
$data['store_name'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($gdpr_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/gdpr_export', $data));
$mail->send();
}
}
/**
* @param array $gdpr_info
*
* @return void
* @throws \Exception
*/
public function approve(array $gdpr_info): void {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
// Send the email in the correct language
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/gdpr_approve', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
if ($customer_info) {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
} else {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
}
$data['text_gdpr'] = sprintf($this->language->get('mail_text_gdpr'), $this->config->get('config_gdpr_limit'));
$data['text_a'] = sprintf($this->language->get('mail_text_a'), $this->config->get('config_gdpr_limit'));
$data['store_name'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($gdpr_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/gdpr_approve', $data));
$mail->send();
}
}
/**
* @param array $gdpr_info
*
* @return void
* @throws \Exception
*/
public function deny(array $gdpr_info): void {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
// Send the email in the correct language
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/gdpr_deny', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$data['text_request'] = $this->language->get('mail_text_' . $gdpr_info['action']);
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
if ($customer_info) {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
} else {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
}
$data['store_name'] = $store_name;
$data['store_url'] = $store_url;
$data['contact'] = $store_url . 'index.php?route=information/contact';
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($gdpr_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/gdpr_deny', $data));
$mail->send();
}
}
/**
* @param array $gdpr_info
*
* @return void
* @throws \Exception
*/
public function remove(array $gdpr_info): void {
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
if ($store_info) {
$this->load->model('setting/setting');
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
// Send the email in the correct language
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/gdpr_delete', 'mail', $language_code);
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$this->load->model('tool/image');
if (is_file(DIR_IMAGE . $store_logo)) {
$data['logo'] = $store_url . 'image/' . $store_logo;
} else {
$data['logo'] = '';
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
if ($customer_info) {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
} else {
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
}
$data['store_name'] = $store_name;
$data['store_url'] = $store_url;
$data['contact'] = $store_url . 'index.php?route=information/contact';
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($gdpr_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/gdpr_delete', $data));
$mail->send();
}
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Returns
*
* @package Opencart\Admin\Controller\Mail
*/
class Returns extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$return_id = $args[0];
} else {
$return_id = '';
}
if (isset($args[1])) {
$return_status_id = $args[1];
} else {
$return_status_id = '';
}
if (isset($args[2])) {
$comment = $args[2];
} else {
$comment = '';
}
if (isset($args[3])) {
$notify = $args[3];
} else {
$notify = '';
}
if ($notify) {
$this->load->model('sale/returns');
$return_info = $this->model_sale_returns->getReturn($return_id);
if ($return_info) {
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($return_info['order_id']);
if ($order_info) {
$store_name = html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8');
$store_url = $order_info['store_url'];
} else {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($return_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/returns', 'mail', $language_code);
$subject = sprintf($this->language->get('mail_text_subject'), $store_name, $return_id);
$data['return_id'] = $return_id;
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($return_info['date_modified']));
$data['return_status'] = $return_info['return_status'];
$data['comment'] = nl2br($comment);
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($return_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/returns', $data));
$mail->send();
}
}
}
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Reward
*
* @package Opencart\Admin\Controller\Mail
*/
class Reward extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string $route, array $args, mixed $output): void {
if (isset($args[0])) {
$customer_id = (int)$args[0];
} else {
$customer_id = 0;
}
if (isset($args[1])) {
$description = (string)$args[1];
} else {
$description = '';
}
if (isset($args[2])) {
$points = (int)$args[2];
} else {
$points = 0;
}
if (isset($args[3])) {
$order_id = (int)$args[3];
} else {
$order_id = 0;
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
if ($customer_info) {
$this->load->language('mail/reward');
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
if ($store_info) {
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['url'];
} else {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = HTTP_CATALOG;
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/reward', 'mail', $language_code);
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$data['text_received'] = sprintf($this->language->get('mail_text_received'), $points);
$data['text_total'] = sprintf($this->language->get('mail_text_total'), $this->model_customer_customer->getRewardTotal($customer_id));
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($customer_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/reward', $data));
$mail->send();
}
}
}
}

View File

@ -0,0 +1,284 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Subscription
*
* @package Opencart\Admin\Controller\Mail
*/
class Subscription extends \Opencart\System\Engine\Controller {
// admin/controller/sale/subscription/addHistory/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function history(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$subscription_id = $args[0];
} else {
$subscription_id = 0;
}
if (isset($args[1])) {
$subscription_status_id = $args[1];
} else {
$subscription_status_id = 0;
}
if (isset($args[2])) {
$comment = $args[2];
} else {
$comment = '';
}
if (isset($args[3])) {
$notify = $args[3];
} else {
$notify = '';
}
// Subscription
$this->load->model('sale/subscription');
$filter_data = [
'filter_subscription_id' => $subscription_id,
'filter_subscription_status_id' => $subscription_status_id,
'filter_date_next' => date('Y-m-d H:i:s')
];
$subscriptions = $this->model_checkout_subscription->getSubscriptions($filter_data);
if ($subscriptions) {
foreach ($subscriptions as $subscription) {
// Subscription histories
$history_total = $this->model_sale_subscription->getTotalHistoriesBySubscriptionStatusId($subscription_status_id);
// The charge() method handles the subscription statuses in the cron/subscription
// controller from the catalog whereas an extension needs to return the active subscription status
if ($history_total && $subscription['subscription_status_id'] == $subscription_status_id) {
// Subscription Statuses
$this->load->model('localisation/subscription_status');
$subscription_status_info = $this->model_localisation_subscription_status->getSubscriptionStatus($subscription_status_id);
if ($subscription_status_info) {
// Customers
$this->load->model('customer/customer');
// Customer payment
$customer_payment_info = $this->model_customer_customer->getPaymentMehod($subscription['customer_id'], $subscription['customer_payment_id']);
if ($customer_payment_info) {
// Since the customer payment is integrated into the customer/customer page,
// we need to gather the customer's information rather than the order
$customer_info = $this->model_customer_customer->getCustomer($subscription['customer_id']);
if ($customer_info) {
// Settings
$this->load->model('setting/setting');
// Store
$store_info = $this->model_setting_setting->getSetting('config', $customer_info['store_id']);
if ($store_info) {
$from = $store_info['config_email'];
$store_name = $store_info['config_name'];
$store_url = $store_info['config_url'];
$alert_email = $store_info['config_mail_alert_email'];
} else {
$from = $this->config->get('config_email');
$store_name = $this->config->get('config_name');
$store_url = HTTP_CATALOG;
$alert_email = $this->config->get('config_mail_alert_email');
}
// Languages
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
if ($comment && $notify) {
$data['comment'] = nl2br($comment);
} else {
$data['comment'] = '';
}
$data['subscription_status'] = $subscription_status_info['name'];
// Languages
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/subscription', 'mail', $language_code);
$data['date_added'] = date($this->language->get('mail_date_format_short'), $subscription['date_added']);
// Text
$data['text_comment'] = $this->language->get('mail_text_comment');
$data['text_date_added'] = $this->language->get('mail_text_date_added');
$data['text_footer'] = $this->language->get('mail_text_footer');
$data['text_subscription_status'] = $this->language->get('mail_text_subscription_status');
if ($this->config->get('config_mail_engine')) {
$mail = new \Opencart\System\Library\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($customer_info['email']);
$mail->setFrom($from);
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($this->language->get('mail_text_subject'), $store_name), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->load->view('mail/subscription_history', $data));
$mail->send();
}
}
}
}
}
}
}
}
}
// admin/controller/sale/subscription/addTransaction/after
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function transaction(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$subscription_id = $args[0];
} else {
$subscription_id = 0;
}
if (isset($args[1])) {
$order_id = $args[1];
} else {
$order_id = 0;
}
if (isset($args[2])) {
$comment = $args[2];
} else {
$comment = '';
}
if (isset($args[3])) {
$amount = $args[3];
} else {
$amount = '';
}
if (isset($args[4])) {
$type = $args[4];
} else {
$type = '';
}
if (isset($args[5])) {
$payment_method = $args[5];
} else {
$payment_method = '';
}
if (isset($args[6])) {
$payment_code = $args[6];
} else {
$payment_code = '';
}
// Subscription
$this->load->model('sale/subscription');
$filter_data = [
'filter_subscription_id' => $subscription_id,
'filter_subscription_status_id' => $this->config->get('config_subscription_canceled_status_id'),
'filter_date_next' => date('Y-m-d H:i:s')
];
$subscriptions = $this->model_checkout_subscription->getSubscriptions($filter_data);
if ($subscriptions) {
foreach ($subscriptions as $subscription) {
$transaction_total = $this->model_sale_subscription->getTotalTransactions($subscription_id);
if ($transaction_total) {
// Orders
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
// In this case, since we're canceling a subscription,
// the order ID needs to be identical
if ($order_info && $subscription['order_id'] == $order_info['order_id']) {
// Same for the payment method
if ($order_info['payment_method'] == $subscription['payment_method'] && $subscription['payment_method'] == $payment_method) {
// Same for the payment code
if ($order_info['payment_code'] == $subscription['payment_code'] && $subscription['payment_code'] == $payment_code) {
$this->load->language('mail/subscription');
// Store
$from = $this->config->get('config_email');
$store_name = $this->config->get('config_name');
$store_url = HTTP_CATALOG;
$alert_email = $this->config->get('config_mail_alert_email');
if ($comment) {
$data['comment'] = nl2br($comment);
} else {
$data['comment'] = '';
}
$data['subscription_id'] = $subscription_id;
$data['payment_method'] = $payment_method;
$data['payment_code'] = $payment_code;
$data['date_added'] = date($this->language->get('date_format_short'), $subscription['date_added']);
if ($this->config->get('config_mail_engine')) {
$mail = new \Opencart\System\Library\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($from);
$mail->setFrom($from);
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($this->language->get('text_subject'), $store_name), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->load->view('mail/subscription_canceled', $data));
$mail->send();
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Transaction
*
* @package Opencart\Admin\Controller\Mail
*/
class Transaction extends \Opencart\System\Engine\Controller {
/**
* @param string $route
* @param array $args
* @param mixed $output
*
* @return void
* @throws \Exception
*/
public function index(string &$route, array &$args, mixed &$output): void {
if (isset($args[0])) {
$customer_id = $args[0];
} else {
$customer_id = 0;
}
if (isset($args[1])) {
$description = $args[1];
} else {
$description = '';
}
if (isset($args[2])) {
$amount = $args[2];
} else {
$amount = 0;
}
if (isset($args[3])) {
$order_id = $args[3];
} else {
$order_id = 0;
}
$this->load->model('customer/customer');
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
if ($customer_info) {
$this->load->language('mail/transaction');
$this->load->model('setting/store');
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
if ($store_info) {
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
$store_url = $store_info['store_url'];
} else {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$store_url = $this->config->get('config_url');
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/transaction', 'mail', $language_code);
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
$data['text_received'] = sprintf($this->language->get('mail_text_received'), $this->currency->format($amount, $this->config->get('config_currency')));
$data['text_total'] = sprintf($this->language->get('mail_text_total'), $this->currency->format($this->model_customer_customer->getTransactionTotal($customer_id), $this->config->get('config_currency')));
$data['store'] = $store_name;
$data['store_url'] = $store_url;
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($customer_info['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/transaction', $data));
$mail->send();
}
}
}
}

View File

@ -0,0 +1,130 @@
<?php
namespace Opencart\Admin\Controller\Mail;
/**
* Class Voucher
*
* @package Opencart\Admin\Controller\Mail
*/
class Voucher extends \Opencart\System\Engine\Controller {
/**
* @param int $voucher_id
*
* @return void
* @throws \Exception
*/
public function index(int $voucher_id): void {
$this->load->model('sale/order');
$voucher_info = $this->model_sale_voucher->getVoucher($voucher_id);
if ($voucher_info) {
// If voucher does not belong to an order
$this->load->language('mail/voucher');
if ($voucher_info['order_id']) {
$order_id = $voucher_info['order_id'];
} else {
$order_id = 0;
}
$order_info = $this->model_sale_order->getOrder($order_id);
// If voucher belongs to an order
if ($order_info) {
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
if ($language_info) {
$language_code = $language_info['code'];
} else {
$language_code = $this->config->get('config_language');
}
$this->load->language('default', 'mail', $language_code);
$this->load->language('mail/voucher', 'mail', $language_code);
$store_name = html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8');
// Add language vars to the template folder
$results = $this->language->all('mail');
foreach ($results as $key => $value) {
$data[$key] = $value;
}
$from_name = html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8');
$subject = sprintf($this->language->get('mail_text_subject'), $from_name);
// HTML Mail
$data['title'] = sprintf($this->language->get('mail_text_subject'), $from_name);
$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')))));
$data['text_from'] = sprintf($this->language->get('mail_text_from'), $from_name);
$data['text_redeem'] = sprintf($this->language->get('mail_text_redeem'), $voucher_info['code']);
$this->load->model('sale/voucher_theme');
$voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']);
if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) {
$data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image'];
} else {
$data['image'] = '';
}
$data['message'] = nl2br($voucher_info['message']);
$data['store_name'] = $store_name;
$data['store_url'] = $order_info['store_url'];
} else {
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$from_name = html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8');
$subject = html_entity_decode(sprintf($this->language->get('text_subject'), $from_name), ENT_QUOTES, 'UTF-8');
$data['title'] = sprintf($this->language->get('text_subject'), $from_name);
$data['text_greeting'] = sprintf($this->language->get('text_greeting'), $this->currency->format($voucher_info['amount'], $this->config->get('config_currency')));
$data['text_from'] = sprintf($this->language->get('text_from'), $from_name);
$data['text_redeem'] = sprintf($this->language->get('text_redeem'), $voucher_info['code']);
$this->load->model('sale/voucher_theme');
$voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']);
if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) {
$data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image'];
} else {
$data['image'] = '';
}
$data['message'] = nl2br($voucher_info['message']);
$data['store_name'] = $store_name;
$data['store_url'] = HTTP_CATALOG;
}
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
$mail->setTo($voucher_info['to_email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($store_name);
$mail->setSubject($subject);
$mail->setHtml($this->load->view('mail/voucher', $data));
$mail->send();
}
}
}
}