first commit
This commit is contained in:
152
catalog/controller/mail/affiliate.php
Normal file
152
catalog/controller/mail/affiliate.php
Normal file
@ -0,0 +1,152 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Affiliate
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Affiliate 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 {
|
||||
$this->load->language('mail/affiliate');
|
||||
|
||||
$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_welcome'] = sprintf($this->language->get('text_welcome'), $store_name);
|
||||
|
||||
$this->load->model('account/customer_group');
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$customer_group_id = $this->customer->getGroupId();
|
||||
} else {
|
||||
$customer_group_id = $args[1]['customer_group_id'];
|
||||
}
|
||||
|
||||
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
|
||||
|
||||
if ($customer_group_info) {
|
||||
$data['approval'] = ($this->config->get('config_affiliate_approval') || $customer_group_info['approval']);
|
||||
} else {
|
||||
$data['approval'] = '';
|
||||
}
|
||||
|
||||
$data['login'] = $this->url->link('account/affiliate', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_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);
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$mail->setTo($this->customer->getEmail());
|
||||
} else {
|
||||
$mail->setTo($args[1]['email']);
|
||||
}
|
||||
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/affiliate', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function alert(string &$route, array &$args, mixed &$output): void {
|
||||
// Send to main admin email if new affiliate email is enabled
|
||||
if (in_array('affiliate', (array)$this->config->get('config_mail_alert'))) {
|
||||
$this->load->language('mail/affiliate');
|
||||
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$subject = $this->language->get('text_new_affiliate');
|
||||
|
||||
if ($this->customer->isLogged()) {
|
||||
$customer_group_id = $this->customer->getGroupId();
|
||||
|
||||
$data['firstname'] = $this->customer->getFirstName();
|
||||
$data['lastname'] = $this->customer->getLastName();
|
||||
$data['email'] = $this->customer->getEmail();
|
||||
$data['telephone'] = $this->customer->getTelephone();
|
||||
} else {
|
||||
$customer_group_id = $args[1]['customer_group_id'];
|
||||
|
||||
$data['firstname'] = $args[1]['firstname'];
|
||||
$data['lastname'] = $args[1]['lastname'];
|
||||
$data['email'] = $args[1]['email'];
|
||||
$data['telephone'] = $args[1]['telephone'];
|
||||
}
|
||||
|
||||
$data['website'] = html_entity_decode($args[1]['website'], ENT_QUOTES, 'UTF-8');
|
||||
$data['company'] = $args[1]['company'];
|
||||
|
||||
$this->load->model('account/customer_group');
|
||||
|
||||
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
|
||||
|
||||
if ($customer_group_info) {
|
||||
$data['customer_group'] = $customer_group_info['name'];
|
||||
} else {
|
||||
$data['customer_group'] = '';
|
||||
}
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_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($this->config->get('config_email'));
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/affiliate_alert', $data));
|
||||
$mail->send();
|
||||
|
||||
// Send to additional alert emails if new affiliate email is enabled
|
||||
$emails = explode(',', $this->config->get('config_mail_alert_email'));
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if (oc_strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->setTo(trim($email));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
catalog/controller/mail/forgotten.php
Normal file
60
catalog/controller/mail/forgotten.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Forgotten
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Forgotten extends \Opencart\System\Engine\Controller {
|
||||
// catalog/model/account/customer/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 ($args[0] && $args[1]) {
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
|
||||
|
||||
if ($customer_info) {
|
||||
$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('account/forgotten.reset', 'language=' . $this->config->get('config_language') . '&email=' . urlencode($args[0]) . '&code=' . $args[1], true);
|
||||
$data['ip'] = $this->request->server['REMOTE_ADDR'];
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_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($args[0]);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/forgotten', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
192
catalog/controller/mail/gdpr.php
Normal file
192
catalog/controller/mail/gdpr.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Gdpr
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Gdpr extends \Opencart\System\Engine\Controller {
|
||||
// catalog/model/account/gdpr/addGdpr
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
// $args[0] $code
|
||||
// $args[1] $email
|
||||
// $args[2] $action
|
||||
|
||||
if (isset($args[0])) {
|
||||
$code = $args[0];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$email = $args[1];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$action = $args[2];
|
||||
} else {
|
||||
$action = '';
|
||||
}
|
||||
|
||||
$this->load->language('mail/gdpr');
|
||||
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if ($this->config->get('config_logo')) {
|
||||
$data['logo'] = $this->config->get('config_url') . 'image/' . html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$data['text_request'] = $this->language->get('text_' . $action);
|
||||
|
||||
$data['button_confirm'] = $this->language->get('button_' . $action);
|
||||
|
||||
$data['confirm'] = $this->url->link('information/gdpr.success', 'language=' . $this->config->get('config_language') . '&code=' . $code, true);
|
||||
|
||||
$data['ip'] = $this->request->server['REMOTE_ADDR'];
|
||||
|
||||
$data['store_name'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_url');
|
||||
|
||||
if ($this->config->get('config_mail_engine') && $email) {
|
||||
$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(sprintf($this->language->get('text_subject'), $store_name));
|
||||
$mail->setHtml($this->load->view('mail/gdpr', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/gdpr/editStatus/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$gdpr_id = $args[0];
|
||||
} else {
|
||||
$gdpr_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$status = $args[1];
|
||||
} else {
|
||||
$status = 0;
|
||||
}
|
||||
|
||||
$this->load->model('account/gdpr');
|
||||
|
||||
$gdpr_info = $this->model_account_gdpr->getGdpr($gdpr_id);
|
||||
|
||||
if ($gdpr_info && $gdpr_info['action'] == 'remove' && $status == 3) {
|
||||
$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_SERVER;
|
||||
}
|
||||
|
||||
// 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 that 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('account/customer');
|
||||
|
||||
$customer_info = $this->model_account_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
638
catalog/controller/mail/order.php
Normal file
638
catalog/controller/mail/order.php
Normal file
@ -0,0 +1,638 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Order
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Order extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args): void {
|
||||
if (isset($args[0])) {
|
||||
$order_id = $args[0];
|
||||
} else {
|
||||
$order_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$order_status_id = $args[1];
|
||||
} else {
|
||||
$order_status_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$comment = $args[2];
|
||||
} else {
|
||||
$comment = '';
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$notify = $args[3];
|
||||
} else {
|
||||
$notify = '';
|
||||
}
|
||||
|
||||
// We need to grab the old order status ID
|
||||
$order_info = $this->model_checkout_order->getOrder($order_id);
|
||||
|
||||
if ($order_info) {
|
||||
// If the order status returns 0, then it becomes greater than 0. Therefore, we send the default html email
|
||||
if (!$order_info['order_status_id'] && $order_status_id) {
|
||||
$this->add($order_info, $order_status_id, $comment, $notify);
|
||||
}
|
||||
|
||||
// If the order status does not return 0, we send the update as a text email
|
||||
if ($order_info['order_status_id'] && $order_status_id && $notify) {
|
||||
$this->edit($order_info, $order_status_id, $comment, $notify);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $order_info
|
||||
* @param int $order_status_id
|
||||
* @param string $comment
|
||||
* @param bool $notify
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add(array $order_info, int $order_status_id, string $comment, bool $notify): void {
|
||||
// Check for any downloadable products
|
||||
$download_status = false;
|
||||
|
||||
$order_products = $this->model_checkout_order->getProducts($order_info['order_id']);
|
||||
|
||||
foreach ($order_products as $order_product) {
|
||||
// Check if there are any linked downloads
|
||||
$product_download_query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "product_to_download` WHERE `product_id` = '" . (int)$order_product['product_id'] . "'");
|
||||
|
||||
if ($product_download_query->row['total']) {
|
||||
$download_status = true;
|
||||
}
|
||||
}
|
||||
|
||||
$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');
|
||||
|
||||
if (!defined('HTTP_CATALOG')) {
|
||||
$store_url = HTTP_SERVER;
|
||||
} else {
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($order_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'];
|
||||
}
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
// 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/order_add', '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, $order_info['order_id']);
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$data['title'] = sprintf($this->language->get('mail_text_subject'), $store_name, $order_info['order_id']);
|
||||
|
||||
$data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $order_info['store_name']);
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $order_info['store_url'];
|
||||
|
||||
$data['customer_id'] = $order_info['customer_id'];
|
||||
$data['link'] = $order_info['store_url'] . 'index.php?route=account/order.info&order_id=' . $order_info['order_id'];
|
||||
|
||||
if ($download_status) {
|
||||
$data['download'] = $order_info['store_url'] . 'index.php?route=account/download';
|
||||
} else {
|
||||
$data['download'] = '';
|
||||
}
|
||||
|
||||
$data['order_id'] = $order_info['order_id'];
|
||||
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
|
||||
$data['payment_method'] = $order_info['payment_method']['name'];
|
||||
$data['shipping_method'] = $order_info['shipping_method']['name'];
|
||||
$data['email'] = $order_info['email'];
|
||||
$data['telephone'] = $order_info['telephone'];
|
||||
$data['ip'] = $order_info['ip'];
|
||||
|
||||
$order_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$order_info['language_id'] . "'");
|
||||
|
||||
if ($order_status_query->num_rows) {
|
||||
$data['order_status'] = $order_status_query->row['name'];
|
||||
} else {
|
||||
$data['order_status'] = '';
|
||||
}
|
||||
|
||||
if ($comment) {
|
||||
$data['comment'] = nl2br($comment);
|
||||
} else {
|
||||
$data['comment'] = '';
|
||||
}
|
||||
|
||||
// Payment Address
|
||||
if ($order_info['payment_address_format']) {
|
||||
$format = $order_info['payment_address_format'];
|
||||
} else {
|
||||
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
|
||||
}
|
||||
|
||||
$find = [
|
||||
'{firstname}',
|
||||
'{lastname}',
|
||||
'{company}',
|
||||
'{address_1}',
|
||||
'{address_2}',
|
||||
'{city}',
|
||||
'{postcode}',
|
||||
'{zone}',
|
||||
'{zone_code}',
|
||||
'{country}'
|
||||
];
|
||||
|
||||
$replace = [
|
||||
'firstname' => $order_info['payment_firstname'],
|
||||
'lastname' => $order_info['payment_lastname'],
|
||||
'company' => $order_info['payment_company'],
|
||||
'address_1' => $order_info['payment_address_1'],
|
||||
'address_2' => $order_info['payment_address_2'],
|
||||
'city' => $order_info['payment_city'],
|
||||
'postcode' => $order_info['payment_postcode'],
|
||||
'zone' => $order_info['payment_zone'],
|
||||
'zone_code' => $order_info['payment_zone_code'],
|
||||
'country' => $order_info['payment_country']
|
||||
];
|
||||
|
||||
$data['payment_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
|
||||
|
||||
// Shipping Address
|
||||
if ($order_info['shipping_address_format']) {
|
||||
$format = $order_info['shipping_address_format'];
|
||||
} else {
|
||||
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
|
||||
}
|
||||
|
||||
$find = [
|
||||
'{firstname}',
|
||||
'{lastname}',
|
||||
'{company}',
|
||||
'{address_1}',
|
||||
'{address_2}',
|
||||
'{city}',
|
||||
'{postcode}',
|
||||
'{zone}',
|
||||
'{zone_code}',
|
||||
'{country}'
|
||||
];
|
||||
|
||||
$replace = [
|
||||
'firstname' => $order_info['shipping_firstname'],
|
||||
'lastname' => $order_info['shipping_lastname'],
|
||||
'company' => $order_info['shipping_company'],
|
||||
'address_1' => $order_info['shipping_address_1'],
|
||||
'address_2' => $order_info['shipping_address_2'],
|
||||
'city' => $order_info['shipping_city'],
|
||||
'postcode' => $order_info['shipping_postcode'],
|
||||
'zone' => $order_info['shipping_zone'],
|
||||
'zone_code' => $order_info['shipping_zone_code'],
|
||||
'country' => $order_info['shipping_country']
|
||||
];
|
||||
|
||||
$data['shipping_address'] = str_replace(["\r\n", "\r", "\n"], '<br/>', preg_replace(["/\s\s+/", "/\r\r+/", "/\n\n+/"], '<br/>', trim(str_replace($find, $replace, $format))));
|
||||
|
||||
$this->load->model('tool/upload');
|
||||
|
||||
// Products
|
||||
$data['products'] = [];
|
||||
|
||||
foreach ($order_products as $order_product) {
|
||||
$option_data = [];
|
||||
|
||||
$order_options = $this->model_checkout_order->getOptions($order_info['order_id'], $order_product['order_product_id']);
|
||||
|
||||
foreach ($order_options as $order_option) {
|
||||
if ($order_option['type'] != 'file') {
|
||||
$value = $order_option['value'];
|
||||
} else {
|
||||
$upload_info = $this->model_tool_upload->getUploadByCode($order_option['value']);
|
||||
|
||||
if ($upload_info) {
|
||||
$value = $upload_info['name'];
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
}
|
||||
|
||||
$option_data[] = [
|
||||
'name' => $order_option['name'],
|
||||
'value' => (oc_strlen($value) > 20 ? oc_substr($value, 0, 20) . '..' : $value)
|
||||
];
|
||||
}
|
||||
|
||||
$description = '';
|
||||
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$subscription_info = $this->model_checkout_order->getSubscription($order_info['order_id'], $order_product['order_product_id']);
|
||||
|
||||
if ($subscription_info) {
|
||||
if ($subscription_info['trial_status']) {
|
||||
$trial_price = $this->currency->format($subscription_info['trial_price'] + ($this->config->get('config_tax') ? $subscription_info['trial_tax'] : 0), $order_info['currency_code'], $order_info['currency_value']);
|
||||
$trial_cycle = $subscription_info['trial_cycle'];
|
||||
$trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
|
||||
$trial_duration = $subscription_info['trial_duration'];
|
||||
|
||||
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
|
||||
}
|
||||
|
||||
$price = $this->currency->format($subscription_info['price'] + ($this->config->get('config_tax') ? $subscription_info['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']);
|
||||
$cycle = $subscription_info['cycle'];
|
||||
$frequency = $this->language->get('text_' . $subscription_info['frequency']);
|
||||
$duration = $subscription_info['duration'];
|
||||
|
||||
if ($duration) {
|
||||
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
|
||||
} else {
|
||||
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
|
||||
}
|
||||
}
|
||||
|
||||
$data['products'][] = [
|
||||
'name' => $order_product['name'],
|
||||
'model' => $order_product['model'],
|
||||
'option' => $option_data,
|
||||
'subscription' => $description,
|
||||
'quantity' => $order_product['quantity'],
|
||||
'price' => $this->currency->format($order_product['price'] + ($this->config->get('config_tax') ? $order_product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
|
||||
'total' => $this->currency->format($order_product['total'] + ($this->config->get('config_tax') ? ($order_product['tax'] * $order_product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
|
||||
'reward' => $order_product['reward']
|
||||
];
|
||||
}
|
||||
|
||||
// Vouchers
|
||||
$data['vouchers'] = [];
|
||||
|
||||
$order_vouchers = $this->model_checkout_order->getVouchers($order_info['order_id']);
|
||||
|
||||
foreach ($order_vouchers as $order_voucher) {
|
||||
$data['vouchers'][] = [
|
||||
'description' => $order_voucher['description'],
|
||||
'amount' => $this->currency->format($order_voucher['amount'], $order_info['currency_code'], $order_info['currency_value']),
|
||||
];
|
||||
}
|
||||
|
||||
// Order Totals
|
||||
$data['totals'] = [];
|
||||
|
||||
$order_totals = $this->model_checkout_order->getTotals($order_info['order_id']);
|
||||
|
||||
foreach ($order_totals as $order_total) {
|
||||
$data['totals'][] = [
|
||||
'title' => $order_total['title'],
|
||||
'text' => $this->currency->format($order_total['value'], $order_info['currency_code'], $order_info['currency_value']),
|
||||
];
|
||||
}
|
||||
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$from = $this->model_setting_setting->getValue('config_email', $order_info['store_id']);
|
||||
|
||||
if (!$from) {
|
||||
$from = $this->config->get('config_email');
|
||||
}
|
||||
|
||||
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($order_info['email']);
|
||||
$mail->setFrom($from);
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/order_invoice', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $order_info
|
||||
* @param int $order_status_id
|
||||
* @param string $comment
|
||||
* @param bool $notify
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function edit(array $order_info, int $order_status_id, string $comment, bool $notify): void {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if (!defined('HTTP_CATALOG')) {
|
||||
$store_url = HTTP_SERVER;
|
||||
} else {
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($order_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
}
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
// 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/order_edit', '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, $order_info['order_id']);
|
||||
|
||||
$data['order_id'] = $order_info['order_id'];
|
||||
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
|
||||
|
||||
$order_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$order_info['language_id'] . "'");
|
||||
|
||||
if ($order_status_query->num_rows) {
|
||||
$data['order_status'] = $order_status_query->row['name'];
|
||||
} else {
|
||||
$data['order_status'] = '';
|
||||
}
|
||||
|
||||
if ($order_info['customer_id']) {
|
||||
$data['link'] = $order_info['store_url'] . 'index.php?route=account/order.info&order_id=' . $order_info['order_id'];
|
||||
} else {
|
||||
$data['link'] = '';
|
||||
}
|
||||
|
||||
$data['comment'] = strip_tags($comment);
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$from = $this->model_setting_setting->getValue('config_email', $order_info['store_id']);
|
||||
|
||||
if (!$from) {
|
||||
$from = $this->config->get('config_email');
|
||||
}
|
||||
|
||||
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($order_info['email']);
|
||||
$mail->setFrom($from);
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/order_history', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/checkout/order/addHistory/before
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function alert(string &$route, array &$args): void {
|
||||
if (isset($args[0])) {
|
||||
$order_id = $args[0];
|
||||
} else {
|
||||
$order_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$order_status_id = $args[1];
|
||||
} else {
|
||||
$order_status_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$comment = $args[2];
|
||||
} else {
|
||||
$comment = '';
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$notify = $args[3];
|
||||
} else {
|
||||
$notify = '';
|
||||
}
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($order_id);
|
||||
|
||||
if ($order_info && !$order_info['order_status_id'] && $order_status_id && in_array('order', (array)$this->config->get('config_mail_alert'))) {
|
||||
$this->load->language('mail/order_alert');
|
||||
|
||||
$subject = html_entity_decode(sprintf($this->language->get('text_subject'), $this->config->get('config_name'), $order_info['order_id']), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$data['order_id'] = $order_info['order_id'];
|
||||
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
|
||||
|
||||
$order_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
if ($order_status_query->num_rows) {
|
||||
$data['order_status'] = $order_status_query->row['name'];
|
||||
} else {
|
||||
$data['order_status'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('tool/upload');
|
||||
|
||||
$data['products'] = [];
|
||||
|
||||
$order_products = $this->model_checkout_order->getProducts($order_id);
|
||||
|
||||
foreach ($order_products as $order_product) {
|
||||
$option_data = [];
|
||||
|
||||
$order_options = $this->model_checkout_order->getOptions($order_info['order_id'], $order_product['order_product_id']);
|
||||
|
||||
foreach ($order_options as $order_option) {
|
||||
if ($order_option['type'] != 'file') {
|
||||
$value = $order_option['value'];
|
||||
} else {
|
||||
$upload_info = $this->model_tool_upload->getUploadByCode($order_option['value']);
|
||||
|
||||
if ($upload_info) {
|
||||
$value = $upload_info['name'];
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
}
|
||||
|
||||
$option_data[] = [
|
||||
'name' => $order_option['name'],
|
||||
'value' => (oc_strlen($value) > 20 ? oc_substr($value, 0, 20) . '..' : $value)
|
||||
];
|
||||
}
|
||||
|
||||
$description = '';
|
||||
|
||||
$this->load->model('checkout/subscription');
|
||||
|
||||
$subscription_info = $this->model_checkout_order->getSubscription($order_info['order_id'], $order_product['order_product_id']);
|
||||
|
||||
if ($subscription_info) {
|
||||
if ($subscription_info['trial_status']) {
|
||||
$trial_price = $this->currency->format($subscription_info['trial_price'] + ($this->config->get('config_tax') ? $subscription_info['trial_tax'] : 0), $this->session->data['currency']);
|
||||
$trial_cycle = $subscription_info['trial_cycle'];
|
||||
$trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
|
||||
$trial_duration = $subscription_info['trial_duration'];
|
||||
|
||||
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
|
||||
}
|
||||
|
||||
$price = $this->currency->format($subscription_info['price'] + ($this->config->get('config_tax') ? $subscription_info['tax'] : 0), $this->session->data['currency']);
|
||||
$cycle = $subscription_info['cycle'];
|
||||
$frequency = $this->language->get('text_' . $subscription_info['frequency']);
|
||||
$duration = $subscription_info['duration'];
|
||||
|
||||
if ($duration) {
|
||||
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
|
||||
} else {
|
||||
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
|
||||
}
|
||||
}
|
||||
|
||||
$data['products'][] = [
|
||||
'name' => $order_product['name'],
|
||||
'model' => $order_product['model'],
|
||||
'quantity' => $order_product['quantity'],
|
||||
'option' => $option_data,
|
||||
'subscription' => $description,
|
||||
'total' => html_entity_decode($this->currency->format($order_product['total'] + ($this->config->get('config_tax') ? $order_product['tax'] * $order_product['quantity'] : 0), $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8')
|
||||
];
|
||||
}
|
||||
|
||||
$data['vouchers'] = [];
|
||||
|
||||
$order_vouchers = $this->model_checkout_order->getVouchers($order_id);
|
||||
|
||||
foreach ($order_vouchers as $order_voucher) {
|
||||
$data['vouchers'][] = [
|
||||
'description' => $order_voucher['description'],
|
||||
'amount' => html_entity_decode($this->currency->format($order_voucher['amount'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8')
|
||||
];
|
||||
}
|
||||
|
||||
$data['totals'] = [];
|
||||
|
||||
$order_totals = $this->model_checkout_order->getTotals($order_id);
|
||||
|
||||
foreach ($order_totals as $order_total) {
|
||||
$data['totals'][] = [
|
||||
'title' => $order_total['title'],
|
||||
'value' => html_entity_decode($this->currency->format($order_total['value'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8')
|
||||
];
|
||||
}
|
||||
|
||||
$data['comment'] = nl2br($order_info['comment']);
|
||||
|
||||
$data['store'] = html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8');
|
||||
$data['store_url'] = $order_info['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($this->config->get('config_email'));
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/order_alert', $data));
|
||||
$mail->send();
|
||||
|
||||
// Send to additional alert emails
|
||||
$emails = explode(',', $this->config->get('config_mail_alert_email'));
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->setTo(trim($email));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
144
catalog/controller/mail/register.php
Normal file
144
catalog/controller/mail/register.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Register
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Register extends \Opencart\System\Engine\Controller {
|
||||
// catalog/model/account/customer/addCustomer/after
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->language('mail/register');
|
||||
|
||||
$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_welcome'] = sprintf($this->language->get('text_welcome'), $store_name);
|
||||
|
||||
$this->load->model('account/customer_group');
|
||||
|
||||
if (isset($args[0]['customer_group_id'])) {
|
||||
$customer_group_id = (int)$args[0]['customer_group_id'];
|
||||
} else {
|
||||
$customer_group_id = (int)$this->config->get('config_customer_group_id');
|
||||
}
|
||||
|
||||
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
|
||||
|
||||
if ($customer_group_info) {
|
||||
$data['approval'] = $customer_group_info['approval'];
|
||||
} else {
|
||||
$data['approval'] = '';
|
||||
}
|
||||
|
||||
$data['login'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_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($args[0]['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/register', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
// catalog/model/account/customer/addCustomer/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function alert(string &$route, array &$args, mixed &$output): void {
|
||||
// Send to main admin email if new account email is enabled
|
||||
if (in_array('account', (array)$this->config->get('config_mail_alert'))) {
|
||||
$this->load->language('mail/register');
|
||||
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$subject = $this->language->get('text_new_customer');
|
||||
|
||||
$data['firstname'] = $args[0]['firstname'];
|
||||
$data['lastname'] = $args[0]['lastname'];
|
||||
|
||||
$data['login'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
|
||||
|
||||
$this->load->model('account/customer_group');
|
||||
|
||||
if (isset($args[0]['customer_group_id'])) {
|
||||
$customer_group_id = (int)$args[0]['customer_group_id'];
|
||||
} else {
|
||||
$customer_group_id = (int)$this->config->get('config_customer_group_id');
|
||||
}
|
||||
|
||||
$customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id);
|
||||
|
||||
if ($customer_group_info) {
|
||||
$data['customer_group'] = $customer_group_info['name'];
|
||||
} else {
|
||||
$data['customer_group'] = '';
|
||||
}
|
||||
|
||||
$data['email'] = $args[0]['email'];
|
||||
$data['telephone'] = $args[0]['telephone'];
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_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($this->config->get('config_email'));
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/register_alert', $data));
|
||||
$mail->send();
|
||||
|
||||
// Send to additional alert emails if new account email is enabled
|
||||
$emails = explode(',', (string)$this->config->get('config_mail_alert_email'));
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if (oc_strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->setTo(trim($email));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
70
catalog/controller/mail/review.php
Normal file
70
catalog/controller/mail/review.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Review
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Review extends \Opencart\System\Engine\Controller {
|
||||
// catalog/model/catalog/review/addReview/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 (in_array('review', (array)$this->config->get('config_mail_alert'))) {
|
||||
$this->load->language('mail/review');
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$product_info = $this->model_catalog_product->getProduct((int)$args[0]);
|
||||
|
||||
if ($product_info) {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$subject = sprintf($this->language->get('text_subject'), $store_name);
|
||||
|
||||
$data['product'] = html_entity_decode($product_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$data['reviewer'] = html_entity_decode($args[1]['name'], ENT_QUOTES, 'UTF-8');
|
||||
$data['rating'] = (int)$args[1]['rating'];
|
||||
$data['text'] = nl2br($args[1]['text']);
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_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($this->config->get('config_email'));
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/review', $data));
|
||||
$mail->send();
|
||||
|
||||
// Send to additional alert emails
|
||||
$emails = explode(',', (string)$this->config->get('config_mail_alert_email'));
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->setTo(trim($email));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
376
catalog/controller/mail/subscription.php
Normal file
376
catalog/controller/mail/subscription.php
Normal file
@ -0,0 +1,376 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Subscription
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Subscription extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args, &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$subscription_id = $args[0];
|
||||
} else {
|
||||
$subscription_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1]['subscription'])) {
|
||||
$subscription = $args[1]['subscription'];
|
||||
} else {
|
||||
$subscription = [];
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$comment = $args[2];
|
||||
} else {
|
||||
$comment = '';
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$notify = $args[3];
|
||||
} else {
|
||||
$notify = '';
|
||||
}
|
||||
/*
|
||||
$subscription['order_product_id']
|
||||
$subscription['customer_id']
|
||||
$subscription['order_id']
|
||||
$subscription['subscription_plan_id']
|
||||
$subscription['customer_payment_id'],
|
||||
$subscription['name']
|
||||
$subscription['description']
|
||||
$subscription['trial_price']
|
||||
$subscription['trial_frequency']
|
||||
$subscription['trial_cycle']
|
||||
$subscription['trial_duration']
|
||||
$subscription['trial_remaining']
|
||||
$subscription['trial_status']
|
||||
$subscription['price']
|
||||
$subscription['frequency']
|
||||
$subscription['cycle']
|
||||
$subscription['duration']
|
||||
$subscription['remaining']
|
||||
$subscription['date_next']
|
||||
$subscription['status']
|
||||
|
||||
|
||||
if ($subscription['trial_duration'] && $subscription['trial_remaining']) {
|
||||
$date_next = date('Y-m-d', strtotime('+' . $subscription['trial_cycle'] . ' ' . $subscription['trial_frequency']));
|
||||
} elseif ($subscription['duration'] && $subscription['remaining']) {
|
||||
$date_next = date('Y-m-d', strtotime('+' . $subscription['cycle'] . ' ' . $subscription['frequency']));
|
||||
}
|
||||
|
||||
// Subscription
|
||||
$this->load->model('account/subscription');
|
||||
|
||||
$filter_data = [
|
||||
'filter_subscription_id' => $subscription_id,
|
||||
'filter_date_next' => $date_next,
|
||||
'filter_subscription_status_id' => $this->config->get('config_subscription_active_status_id'),
|
||||
'start' => 0,
|
||||
'limit' => 1
|
||||
];
|
||||
|
||||
$subscriptions = $this->model_account_subscription->getSubscriptions($filter_data);
|
||||
|
||||
if ($subscriptions) {
|
||||
$this->load->language('mail/subscription');
|
||||
|
||||
foreach ($subscriptions as $value) {
|
||||
// Only match the latest order ID of the same customer ID
|
||||
// since new subscriptions cannot be re-added with the same
|
||||
// order ID; only as a new order ID added by an extension
|
||||
if ($value['customer_id'] == $subscription['customer_id'] && $value['order_id'] == $subscription['order_id']) {
|
||||
// Payment Methods
|
||||
$this->load->model('account/payment_method');
|
||||
|
||||
$payment_method = $this->model_account_payment_method->getPaymentMethod($value['customer_id'], $value['customer_payment_id']);
|
||||
|
||||
if ($payment_method) {
|
||||
// Subscription
|
||||
$this->load->model('checkout/subscription');
|
||||
|
||||
$subscription_order_product = $this->model_checkout_subscription->getSubscriptionByOrderProductId($value['order_product_id']);
|
||||
|
||||
if ($subscription_order_product) {
|
||||
// Orders
|
||||
$this->load->model('account/order');
|
||||
|
||||
// Order Products
|
||||
$order_product = $this->model_account_order->getProduct($value['order_id'], $value['order_product_id']);
|
||||
|
||||
if ($order_product && $order_product['order_product_id'] == $subscription['order_product_id']) {
|
||||
$products = $this->cart->getProducts();
|
||||
|
||||
$description = '';
|
||||
|
||||
foreach ($products as $product) {
|
||||
if ($product['product_id'] == $order_product['product_id']) {
|
||||
|
||||
|
||||
if ($product['subscription']['trial_status']) {
|
||||
$trial_price = $this->currency->format($this->tax->calculate($value['trial_price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->config->get('config_currency'));
|
||||
$trial_cycle = $value['trial_cycle'];
|
||||
$trial_frequency = $this->language->get('text_' . $value['trial_frequency']);
|
||||
$trial_duration = $value['trial_duration'];
|
||||
|
||||
$description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
|
||||
}
|
||||
|
||||
$price = $this->currency->format($this->tax->calculate($value['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->config->get('config_currency'));
|
||||
$cycle = $value['cycle'];
|
||||
$frequency = $this->language->get('text_' . $value['frequency']);
|
||||
$duration = $value['duration'];
|
||||
|
||||
if ($duration) {
|
||||
$description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
|
||||
} else {
|
||||
$description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Orders
|
||||
$this->load->model('checkout/order');
|
||||
|
||||
$order_info = $this->model_checkout_order->getOrder($value['order_id']);
|
||||
|
||||
if ($order_info) {
|
||||
// Stores
|
||||
$this->load->model('setting/store');
|
||||
|
||||
// Settings
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($order_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$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_SERVER;
|
||||
}
|
||||
|
||||
// Subscription Status
|
||||
$subscription_status_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$value['subscription_status_id'] . "' AND `language_id` = '" . (int)$order_info['language_id'] . "'");
|
||||
|
||||
if ($subscription_status_query->num_rows) {
|
||||
$data['order_status'] = $subscription_status_query->row['name'];
|
||||
} else {
|
||||
$data['order_status'] = '';
|
||||
}
|
||||
|
||||
// Languages
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
|
||||
|
||||
// We need to compare both language IDs as they both need to match.
|
||||
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/order_add', '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, $order_info['order_id']);
|
||||
|
||||
// Image files
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$data['title'] = sprintf($this->language->get('mail_text_subject'), $store_name, $order_info['order_id']);
|
||||
|
||||
$data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $order_info['store_name']);
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $order_info['store_url'];
|
||||
|
||||
$data['customer_id'] = $order_info['customer_id'];
|
||||
$data['link'] = $order_info['store_url'] . 'index.php?route=account/subscription.info&subscription_id=' . $subscription_id;
|
||||
|
||||
$data['order_id'] = $order_info['order_id'];
|
||||
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($value['date_added']));
|
||||
$data['payment_method'] = $order_info['payment_method'];
|
||||
$data['email'] = $order_info['email'];
|
||||
$data['telephone'] = $order_info['telephone'];
|
||||
$data['ip'] = $order_info['ip'];
|
||||
|
||||
// Order Totals
|
||||
$data['totals'] = [];
|
||||
|
||||
$order_totals = $this->model_checkout_order->getTotals($subscription['order_id']);
|
||||
|
||||
foreach ($order_totals as $order_total) {
|
||||
$data['totals'][] = [
|
||||
'title' => $order_total['title'],
|
||||
'text' => $this->currency->format($order_total['value'], $order_info['currency_code'], $order_info['currency_value']),
|
||||
];
|
||||
}
|
||||
|
||||
// Subscription
|
||||
if ($comment && $notify) {
|
||||
$data['comment'] = nl2br($comment);
|
||||
} else {
|
||||
$data['comment'] = '';
|
||||
}
|
||||
|
||||
$data['description'] = $value['description'];
|
||||
|
||||
// Products
|
||||
$data['name'] = $order_product['name'];
|
||||
$data['quantity'] = $order_product['quantity'];
|
||||
$data['price'] = $this->currency->format($order_product['price'], $order_info['currency_code'], $order_info['currency_value']);
|
||||
$data['total'] = $this->currency->format($order_product['total'], $order_info['currency_code'], $order_info['currency_value']);
|
||||
|
||||
$data['order'] = $this->url->link('account/order.info', 'order_id=' . $value['order_id']);
|
||||
$data['product'] = $this->url->link('product/product', 'product_id=' . $value['product_id']);
|
||||
|
||||
// Settings
|
||||
$from = $this->model_setting_setting->getValue('config_email', $order_info['store_id']);
|
||||
|
||||
if (!$from) {
|
||||
$from = $this->config->get('config_email');
|
||||
}
|
||||
|
||||
if ($this->config->get('payment_' . $payment_info['code'] . '_status')) {
|
||||
$this->load->model('extension/payment/' . $payment_info['code']);
|
||||
|
||||
// Promotion
|
||||
if (isset($this->{'model_extension_payment_' . $payment_info['code']}->promotion)) {
|
||||
$subscription_status_id = $this->{'model_extension_payment_' . $payment_info['code']}->promotion($value['subscription_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$config_subscription_active_status_id = $this->model_setting_setting->getValue('config_subscription_active_status_id', $store_info['store_id']);
|
||||
} else {
|
||||
$config_subscription_active_status_id = $this->config->get('config_subscription_active_status_id');
|
||||
}
|
||||
|
||||
if ($config_subscription_active_status_id == $subscription_status_id) {
|
||||
$subscription_info = $this->model_account_subscription->getSubscription($value['subscription_id']);
|
||||
|
||||
// Validate the latest subscription values with the ones edited
|
||||
// by promotional extensions
|
||||
if ($subscription_info && $subscription_info['status'] && $subscription_info['customer_id'] == $value['customer_id'] && $subscription_info['order_id'] == $value['order_id'] && $subscription_info['order_product_id'] == $value['order_product_id']) {
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$customer_info = $this->model_account_customer->getCustomer($subscription_info['customer_id']);
|
||||
|
||||
$frequencies = [
|
||||
'day',
|
||||
'week',
|
||||
'semi_month',
|
||||
'month',
|
||||
'year'
|
||||
];
|
||||
|
||||
// We need to validate frequencies in compliance of the admin subscription plans
|
||||
// as with the use of the APIs
|
||||
if ($customer_info && (int)$subscription_info['cycle'] >= 0 && $subscription_info['cycle'] == $value['cycle'] && in_array($subscription_info['frequency'], $frequencies)) {
|
||||
if ($subscription_info['frequency'] == 'semi_month') {
|
||||
$period = strtotime("2 weeks");
|
||||
} else {
|
||||
$period = strtotime($subscription_info['cycle'] . ' ' . $subscription_info['frequency']);
|
||||
}
|
||||
|
||||
// New customer once the trial period has ended
|
||||
$customer_period = strtotime($customer_info['date_added']);
|
||||
|
||||
$trial_period = 0;
|
||||
$validate_trial = 0;
|
||||
|
||||
// Trial
|
||||
if ($subscription_info['trial_cycle'] && $subscription_info['trial_frequency'] && $subscription_info['trial_cycle'] == $value['trial_cycle'] && $subscription_info['trial_frequency'] == $value['trial_frequency']) {
|
||||
if ($subscription_info['trial_frequency'] == 'semi_month') {
|
||||
$trial_period = strtotime("2 weeks");
|
||||
} else {
|
||||
$trial_period = strtotime($subscription_info['trial_cycle'] . ' ' . $subscription_info['trial_frequency']);
|
||||
}
|
||||
|
||||
$trial_period = ($trial_period - $customer_period);
|
||||
$validate_trial = round($trial_period / (60 * 60 * 24));
|
||||
}
|
||||
|
||||
// Calculates the remaining days between the subscription
|
||||
// promotional period and the date added period
|
||||
$period = ($period - $customer_period);
|
||||
|
||||
// Calculate remaining period of each features
|
||||
$period = round($period / (60 * 60 * 24));
|
||||
|
||||
// Promotional features description must be identical
|
||||
// until the time period has exceeded. Therefore, the current
|
||||
// period must be matched as well
|
||||
if (($period == 0 && ($validate_trial > 0 || !$validate_trial)) && $value['description'] == $description && $subscription_info['subscription_plan_id'] == $value['subscription_plan_id']) {
|
||||
// Products
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$product_subscription_info = $this->model_catalog_product->getSubscription($order_product['product_id'], $subscription_info['subscription_plan_id']);
|
||||
|
||||
if ($product_subscription_info) {
|
||||
// For the next billing cycle
|
||||
$this->model_account_subscription->addTransaction($value['subscription_id'], $value['order_id'], $this->language->get('text_promotion'), $subscription_info['amount'], $subscription_info['type'], $subscription_info['payment_method'], $subscription_info['payment_code']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mail
|
||||
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($order_info['email']);
|
||||
$mail->setFrom($from);
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/subscription', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
89
catalog/controller/mail/transaction.php
Normal file
89
catalog/controller/mail/transaction.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Transaction extends \Opencart\System\Engine\Controller {
|
||||
// catalog/model/account/customer/addTransaction/after
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->language('mail/transaction');
|
||||
|
||||
$this->load->model('account/customer');
|
||||
|
||||
$customer_info = $this->model_account_customer->getCustomer($args[0]);
|
||||
|
||||
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['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');
|
||||
}
|
||||
|
||||
// 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/transaction', '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_received'] = sprintf($this->language->get('mail_text_received'), $store_name);
|
||||
|
||||
$data['amount'] = $this->currency->format($args[2], $this->config->get('config_currency'));
|
||||
$data['total'] = $this->currency->format($this->model_account_customer->getTransactionTotal($args[0]), $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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
96
catalog/controller/mail/voucher.php
Normal file
96
catalog/controller/mail/voucher.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
namespace Opencart\Catalog\Controller\Mail;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package Opencart\Catalog\Controller\Mail
|
||||
*/
|
||||
class Voucher 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 {
|
||||
$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 ($order_info && in_array($order_info['order_status_id'], $this->config->get('config_complete_status'))) {
|
||||
// Send out any gift voucher mails
|
||||
$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 the email in the correct language
|
||||
$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');
|
||||
}
|
||||
|
||||
// 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/voucher', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
foreach ($voucher_query->rows as $voucher) {
|
||||
$from_name = html_entity_decode($voucher['from_name'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
// HTML Mail
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $from_name);
|
||||
|
||||
$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['amount'], $order_info['currency_code'], $order_info['currency_value']));
|
||||
$data['text_from'] = sprintf($this->language->get('mail_text_from'), $from_name);
|
||||
$data['text_redeem'] = sprintf($this->language->get('mail_text_redeem'), $voucher['code']);
|
||||
|
||||
if (is_file(DIR_IMAGE . $voucher['image'])) {
|
||||
$data['image'] = $this->config->get('config_url') . 'image/' . $voucher['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$data['message'] = nl2br($voucher['message']);
|
||||
|
||||
$data['store_name'] = $order_info['store_name'];
|
||||
$data['store_url'] = $order_info['store_url'];
|
||||
|
||||
$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($subject);
|
||||
$mail->setHtml($this->load->view('mail/voucher', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user