From b4f03b3917ea591b96e790dd6dadaea78dfe0795 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 24 Feb 2025 11:08:44 +0530 Subject: [PATCH 01/13] Updated the flow of customer message and customer service --- .../sass/controllers/_customer-thread.sass | 15 + .../default/sass/controllers/_order.sass | 5 + .../helpers/list/list_header.tpl | 16 +- .../customer_threads/helpers/view/message.tpl | 11 +- .../customer_threads/helpers/view/view.tpl | 11 +- .../template/controllers/orders/form.tpl | 18 +- .../controllers/orders/helpers/view/view.tpl | 8 +- classes/CustomerMessage.php | 9 +- classes/CustomerThread.php | 48 ++- classes/PaymentModule.php | 4 +- controllers/admin/AdminCartsController.php | 3 +- .../admin/AdminCustomerThreadsController.php | 292 +++++++++++++----- controllers/admin/AdminEmailsController.php | 16 +- controllers/admin/AdminOrdersController.php | 12 +- controllers/front/ContactController.php | 115 ++++--- controllers/front/OrderDetailController.php | 14 +- install/data/db_structure.sql | 7 +- install/data/xml/configuration.xml | 9 + js/admin/customer_thread.js | 32 ++ mails/en/reply_msg.html | 96 +++--- mails/en/reply_msg.txt | 12 +- .../hotel-reservation-theme/contact-form.tpl | 78 +++-- .../css/contact-form.css | 4 +- .../css/order-detail.css | 4 +- .../hotel-reservation-theme/order-detail.tpl | 3 + 25 files changed, 553 insertions(+), 289 deletions(-) create mode 100644 js/admin/customer_thread.js diff --git a/admin/themes/default/sass/controllers/_customer-thread.sass b/admin/themes/default/sass/controllers/_customer-thread.sass index a3678333d..a0b8e1d65 100644 --- a/admin/themes/default/sass/controllers/_customer-thread.sass +++ b/admin/themes/default/sass/controllers/_customer-thread.sass @@ -48,7 +48,22 @@ @include left(1px) @include box-shadow(white 0 0 0 3px inset) +.submitReply + i[class^="icon-"] + display: block + width: 30px + height: 30px + margin: 0 auto + font-size: 28px + background: transparent + background-size: 26px + background-position: center +.table.customer_thread, #MeaningStatus + .text-success + color: #56CE56 + .text-warning + color: #FCC94F .message-item-initial h2 diff --git a/admin/themes/default/sass/controllers/_order.sass b/admin/themes/default/sass/controllers/_order.sass index 2cce1d798..18d934810 100644 --- a/admin/themes/default/sass/controllers/_order.sass +++ b/admin/themes/default/sass/controllers/_order.sass @@ -84,6 +84,11 @@ .panel-refund-request .refunded_amount margin-top: 2px +.order-notes + .panel-content + max-height: 240px + overflow: auto + .panel-guest_address .panel-heading align-items: center diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl index eb5a77d3c..4b0ded7a7 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl @@ -51,7 +51,7 @@ {l s='No new messages'} {else} - {$total_thread} + {$total_thread} {if $total_thread > 1}{l s='New messages'}{else}{l s='New message'}{/if} {/if} @@ -64,10 +64,10 @@ {l s='Meaning of status'} @@ -78,12 +78,12 @@ -{/block} \ No newline at end of file +{/block} diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/view/message.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/view/message.tpl index d006ce679..77b4f2d8e 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/view/message.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/view/message.tpl @@ -45,14 +45,15 @@ {if !$initial}

- {if $type == 'customer'} - {$message.customer_name|escape:'html':'UTF-8'} - {else} - {$message.employee_name|escape:'html':'UTF-8'} - {/if} + {if $type == 'customer'} + {$message.customer_name|escape:'html':'UTF-8'} + {else} + {$message.employee_name|escape:'html':'UTF-8'} + {/if}

{/if}   - {dateFormat date=$message.date_add full=0} - {$message.date_add|substr:11:5} + {if $message.private}{l s='Private'}{/if} {if isset($message.file_name)}   {l s="Attachment"}{/if} {if isset($message.product_name)}   {l s="Room type:"} {$message.product_name|escape:'html':'UTF-8'} {/if}

{$message.message|escape:'html':'UTF-8'|nl2br}

diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl index 2d4a2409f..fb68b64e7 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl @@ -30,11 +30,6 @@
{l s="Thread"}: #{$id_customer_thread|intval} - {if isset($next_thread) && $next_thread} - - {$next_thread.name} - - {/if}
@@ -116,7 +111,9 @@ {l s="Choose a template"} --> - + + +
@@ -180,5 +177,3 @@ {/block} - - diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index 105e6b608..4574f7277 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -282,6 +282,10 @@ }) $('#order_message').live('change', function(e) { e.preventDefault(); + let visibility = 0; + if ($('#visibility').prop('checked')) { + visibility = 1; + } $.ajax({ type:"POST", url: "{$link->getAdminLink('AdminCarts')|addslashes}", @@ -294,8 +298,9 @@ action: "updateOrderMessage", id_cart: id_cart, id_customer: id_customer, - message: $(this).val() - }, + message: $(this).val(), + visibility: visibility + }, success : function(res) { displaySummary(res); @@ -2170,6 +2175,15 @@ +
+ +

+ +

+
{if !$PS_CATALOG_MODE}
diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index 2f5c37c16..b823f98a1 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -704,7 +704,7 @@ {* Order Internal notes *} {if (sizeof($messages))} -
+
 {l s='Order Notes'}
@@ -1153,7 +1153,11 @@
 {l s='Messages'} {sizeof($customer_thread_message)} - {l s='Show all messages'} + {if $id_customer_thread} + {l s='Show all messages'} + {else} + {l s='Show all messages'} + {/if}
{if $can_edit} diff --git a/classes/CustomerMessage.php b/classes/CustomerMessage.php index a4b6c920d..6ac21bbef 100644 --- a/classes/CustomerMessage.php +++ b/classes/CustomerMessage.php @@ -32,6 +32,7 @@ class CustomerMessageCore extends ObjectModel public $message; public $file_name; public $ip_address; + public $id_product; public $user_agent; public $private; public $date_add; @@ -51,6 +52,7 @@ class CustomerMessageCore extends ObjectModel 'id_employee' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_customer_thread' => array('type' => self::TYPE_INT), 'ip_address' => array('type' => self::TYPE_STRING, 'validate' => 'isIp2Long', 'size' => 15), + 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'message' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 16777216), 'file_name' => array('type' => self::TYPE_STRING), 'user_agent' => array('type' => self::TYPE_STRING), @@ -72,7 +74,7 @@ class CustomerMessageCore extends ObjectModel ), ); - public static function getMessagesByOrderId($id_order, $private = true) + public static function getMessagesByOrderId($id_order, $private = true, $limit = false) { return Db::getInstance()->executeS(' SELECT cm.*, @@ -91,8 +93,9 @@ class CustomerMessageCore extends ObjectModel WHERE ct.id_order = '.(int)$id_order.' '.(!$private ? 'AND cm.`private` = 0' : '').' GROUP BY cm.id_customer_message - ORDER BY cm.date_add DESC - '); + ORDER BY cm.date_add DESC'. + (($limit) ? ' LIMIT '.(int) $limit: ' ') + ); } public static function getTotalCustomerMessages($where = null) diff --git a/classes/CustomerThread.php b/classes/CustomerThread.php index 7e1b721af..367499a0a 100644 --- a/classes/CustomerThread.php +++ b/classes/CustomerThread.php @@ -32,13 +32,20 @@ class CustomerThreadCore extends ObjectModel public $id_contact; public $id_customer; public $id_order; - public $id_product; + public $user_name; + public $phone; + public $subject; public $status; public $email; public $token; public $date_add; public $date_upd; + const QLO_CUSTOMER_THREAD_STATUS_OPEN = 1; + const QLO_CUSTOMER_THREAD_STATUS_PENDING1 = 2; + const QLO_CUSTOMER_THREAD_STATUS_PENDING2 = 3; + const QLO_CUSTOMER_THREAD_STATUS_CLOSED = 4; + /** * @see ObjectModel::$definition */ @@ -48,10 +55,12 @@ class CustomerThreadCore extends ObjectModel 'fields' => array( 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_contact' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'user_name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), + 'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32), + 'subject' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml'), 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_customer' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 254), 'token' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true), 'status' => array('type' => self::TYPE_STRING), @@ -158,15 +167,38 @@ class CustomerThreadCore extends ObjectModel return Db::getInstance()->executeS($sql); } - public static function getIdCustomerThreadByEmailAndIdOrder($email, $id_order, $id_contact = false) + public static function getIdCustomerThreadByEmailAndIdOrder($email, $id_order, $id_contact = false, $query = false) + { + return Db::getInstance()->getValue(' + SELECT a.`id_customer_thread` + FROM `'._DB_PREFIX_.'customer_thread` a + WHERE a.`email` = \''.pSQL($email).'\' + AND a.`id_shop` = '.(int)Context::getContext()->shop->id.' + AND a.`id_order` = '.(int)$id_order.' '. + (($id_contact) ? ' AND a.`id_contact`='.(int) $id_contact : ' '). + (($query) ? $query : ' ') + ); + } + + + public static function getIdCustomerThreadByIdOrder($idOrder) { return Db::getInstance()->getValue(' SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm - WHERE cm.email = \''.pSQL($email).'\' - AND cm.id_shop = '.(int)Context::getContext()->shop->id.' - AND cm.id_order = '.(int)$id_order.' '. - (($id_contact) ? ' AND cm.id_contact='.(int) $id_contact : ' ') + WHERE cm.id_shop = '.(int)Context::getContext()->shop->id.' + AND cm.id_order = '.(int)$idOrder + ); + } + + + public static function getIdCustomerThreadByToken($token) + { + return Db::getInstance()->getValue(' + SELECT cm.id_customer_thread + FROM '._DB_PREFIX_.'customer_thread cm + WHERE cm.id_shop = '.(int)Context::getContext()->shop->id.' + AND token = \''.pSQL($token).'\'' ); } @@ -234,7 +266,7 @@ class CustomerThreadCore extends ObjectModel return Db::getInstance()->getValue(' SELECT id_customer_thread FROM '._DB_PREFIX_.'customer_thread ct - WHERE ct.status = "open" + WHERE ct.status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.' AND ct.date_upd = ( SELECT date_add FROM '._DB_PREFIX_.'customer_message WHERE (id_employee IS NULL OR id_employee = 0) diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index 516a755ab..0dd260fa1 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -699,7 +699,7 @@ abstract class PaymentModuleCore extends Module $customer_thread->id_order = (int)$order->id; $customer_thread->id_lang = (int)$this->context->language->id; $customer_thread->email = $this->context->customer->email; - $customer_thread->status = 'open'; + $customer_thread->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $customer_thread->token = Tools::passwdGen(12); $customer_thread->add(); @@ -707,7 +707,7 @@ abstract class PaymentModuleCore extends Module $customer_message->id_customer_thread = $customer_thread->id; $customer_message->id_employee = 0; $customer_message->message = $update_message->message; - $customer_message->private = 0; + $customer_message->private = !Tools::getValue('visibility'); if (!$customer_message->add()) { $this->errors[] = Tools::displayError('An error occurred while saving message'); diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 2ce84593f..e4179e2fa 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -587,6 +587,7 @@ class AdminCartsControllerCore extends AdminController $message->message = $message_content; $message->id_cart = (int)$this->context->cart->id; $message->id_customer = (int)$this->context->cart->id_customer; + $message->private = !Tools::getValue('visibility'); $message->save(); } } elseif (Validate::isLoadedObject($message)) { @@ -598,7 +599,7 @@ class AdminCartsControllerCore extends AdminController public function ajaxProcessUpdateCurrency() { - if ($this->tabAccess['edit'] === '1') { + if ($this->tabAccess['edit'] === '1' || $this->tabAccess['add'] === '1') { $currency = new Currency((int)Tools::getValue('id_currency')); if (Validate::isLoadedObject($currency) && !$currency->deleted && $currency->active) { $this->context->cart->id_currency = (int)$currency->id; diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 2d7b52891..0916fb3eb 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -51,10 +51,22 @@ class AdminCustomerThreadsControllerCore extends AdminController } $icon_array = array( - 'open' => array('class' => 'icon-circle text-success', 'alt' => $this->l('Open')), - 'closed' => array('class' => 'icon-circle text-danger', 'alt' => $this->l('Closed')), - 'pending1' => array('class' => 'icon-circle text-warning', 'alt' => $this->l('Pending 1')), - 'pending2' => array('class' => 'icon-circle text-warning', 'alt' => $this->l('Pending 2')), + CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN => array( + 'class' => 'icon-circle text-success', + 'alt' => $this->l('Open') + ), + CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED => array( + 'class' => 'icon-circle text-danger', + 'alt' => $this->l('Closed') + ), + CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1 => array( + 'class' => 'icon-circle text-warning', + 'alt' => $this->l('Pending 1') + ), + CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2 => array( + 'class' => 'icon-circle text-warning', + 'alt' => $this->l('Pending 2') + ), ); $status_array = array(); @@ -67,7 +79,9 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->access_join = ' LEFT JOIN '._DB_PREFIX_.'orders ord ON (a.id_order = ord.id_order)'; $this->access_join .= ' LEFT JOIN '._DB_PREFIX_.'htl_booking_detail hbd ON (hbd.id_order = ord.id_order)'; if ($acsHtls = HotelBranchInformation::getProfileAccessedHotels($this->context->employee->id_profile, 1, 1)) { - $this->access_where = ' AND IF(a.`id_order`, hbd.`id_hotel` IN ('.implode(',', $acsHtls).'), 1)'; + $this->access_where = ' WHERE IF(a.`id_order`, hbd.`id_hotel` IN ('.implode(',', $acsHtls).'), 1)'; + } else { + $this->access_where = ' WHERE a.`id_order` = 0'; } $this->fields_list = array( @@ -79,12 +93,19 @@ class AdminCustomerThreadsControllerCore extends AdminController 'customer' => array( 'title' => $this->l('Customer'), 'filter_key' => 'customer', + 'callback' => 'getCustomerLink', 'tmpTableFilter' => true, ), 'email' => array( 'title' => $this->l('Email'), 'filter_key' => 'a!email', ), + 'phone' => array( + 'title' => $this->l('Phone'), + 'filter_key' => 'a!phone', + 'optional' => true, + 'visible_default' => true, + ), 'contact' => array( 'title' => $this->l('Type'), 'type' => 'select', @@ -92,12 +113,21 @@ class AdminCustomerThreadsControllerCore extends AdminController 'filter_key' => 'cl!id_contact', 'filter_type' => 'int', ), + 'subject' => array( + 'title' => $this->l('Subject'), + 'filter_key' => 'a!subject', + 'tmpTableFilter' => true, + 'maxlength' => 40, + 'optional' => true, + 'visible_default' => true, + ), 'language' => array( 'title' => $this->l('Language'), 'type' => 'select', 'list' => $language_array, 'filter_key' => 'l!id_lang', 'filter_type' => 'int', + 'optional' => true, ), 'status' => array( 'title' => $this->l('Status'), @@ -118,9 +148,10 @@ class AdminCustomerThreadsControllerCore extends AdminController 'filter_key' => 'messages', 'tmpTableFilter' => true, 'maxlength' => 40, + 'optional' => true, ), 'private' => array( - 'title' => $this->l('Private'), + 'title' => $this->l('Has Private'), 'type' => 'select', 'filter_key' => 'private', 'align' => 'center', @@ -135,6 +166,7 @@ class AdminCustomerThreadsControllerCore extends AdminController 'title' => $this->l('Last message'), 'havingFilter' => true, 'type' => 'datetime', + 'optional' => true, ), ); @@ -147,22 +179,61 @@ class AdminCustomerThreadsControllerCore extends AdminController ); $this->shopLinkType = 'shop'; + $arr = array(); + if ($contacts = Contact::getContacts($this->context->language->id)) { + foreach ($contacts as $contact) { + $arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']); + } + } $this->fields_options = array( 'contact' => array( 'title' => $this->l('Contact options'), 'fields' => array( 'PS_CUSTOMER_SERVICE_FILE_UPLOAD' => array( - 'title' => $this->l('Allow file uploading'), - 'hint' => $this->l('Allow customers to upload files using the contact page.'), - 'type' => 'bool' - ), + 'title' => $this->l('Allow file uploading'), + 'hint' => $this->l('Allow customers to upload files using the contact page.'), + 'type' => 'bool' + ), + 'PS_MAIL_EMAIL_MESSAGE' => array( + 'title' => $this->l('Send email to'), + 'desc' => $this->l('Where customers send messages from the order page.'), + 'validation' => 'isUnsignedId', + 'type' => 'select', + 'cast' => 'intval', + 'identifier' => 'email_message', + 'list' => $arr + ), + 'PS_CUSTOMER_SERVICE_CONTACT_ALLOW' => array( + 'title' => $this->l('Allow guest to select contact'), + 'hint' => $this->l('Allow guest to select the contact while submitting message from the contact page.'), + 'type' => 'bool' + ), + 'PS_CUSTOMER_SERVICE_EMAIL_MESSAGE' => array( + 'title' => $this->l('Send email to'), + 'desc' => $this->l('Where customers send messages from the Contact page.'), + 'validation' => 'isUnsignedId', + 'type' => 'select', + 'cast' => 'intval', + 'identifier' => 'email_message', + 'list' => $arr + ), + 'PS_CUSTOMER_SERVICE_NAME_REQUIRED' => array( + 'title' => $this->l('Set Name as required'), + 'hint' => $this->l('Set Name as required while submitting message from the contact page.'), + 'type' => 'bool' + ), + 'PS_CUSTOMER_SERVICE_PHONE_REQUIRED' => array( + 'title' => $this->l('Set Phone as required'), + 'hint' => $this->l('Set Phone as required while submitting message from the contact page.'), + 'type' => 'bool' + ), 'PS_CUSTOMER_SERVICE_SIGNATURE' => array( - 'title' => $this->l('Default message'), - 'hint' => $this->l('Please fill out the message fields that appear by default when you answer a thread on the customer service page.'), - 'type' => 'textareaLang', - 'lang' => true - ) + 'title' => $this->l('Default message'), + 'hint' => $this->l('Please fill out the message fields that appear by default when you answer a thread on the customer service page.'), + 'type' => 'textareaLang', + 'lang' => true + ) ), 'submit' => array( 'title' => $this->l('Save'), @@ -242,6 +313,25 @@ class AdminCustomerThreadsControllerCore extends AdminController ); parent::__construct(); + $this->_new_list_header_design = true; + $this->list_no_link = true; + } + + public function getCustomerLink($customer, $tr) + { + if ($tr['id_customer']) { + return ''.$customer.' (#'.$tr['id_customer'].')'; + } + + return $customer; + } + + public function setMedia() + { + parent::setMedia(); + if (!$this->display || $this->display == 'list') { + $this->addJS(_PS_JS_DIR_.'admin/customer_thread.js'); + } } public function renderList() @@ -253,7 +343,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->addRowAction('delete'); $this->_select = ' - CONCAT(c.`firstname`," ",c.`lastname`) as customer, cl.`name` as contact, l.`name` as language, group_concat(message) as messages, cm.private, + IF(a.`user_name`="", CONCAT(c.`firstname`," ",c.`lastname`), a.`user_name`) AS customer, cl.`name` as contact, l.`name` as language, group_concat(message) as messages, cm.private, ( SELECT IFNULL(CONCAT(LEFT(e.`firstname`, 1),". ",e.`lastname`), "--") FROM `'._DB_PREFIX_.'customer_message` cm2 @@ -274,10 +364,6 @@ class AdminCustomerThreadsControllerCore extends AdminController LEFT JOIN `'._DB_PREFIX_.'contact_lang` cl ON (cl.`id_contact` = a.`id_contact` AND cl.`id_lang` = '.(int)$this->context->language->id.')'; - if ($id_order = Tools::getValue('id_order')) { - $this->_where .= ' AND id_order = '.(int)$id_order; - } - $this->_group = 'GROUP BY cm.id_customer_thread'; $this->_orderBy = 'id_customer_thread'; $this->_orderWay = 'DESC'; @@ -286,19 +372,42 @@ class AdminCustomerThreadsControllerCore extends AdminController $categories = Contact::getCategoriesContacts(); - $params = array( - $this->l('Total threads') => $all = CustomerThread::getTotalCustomerThreads(), - $this->l('Threads pending') => $pending = CustomerThread::getTotalCustomerThreads('status LIKE "%pending%"'), - $this->l('Total number of customer messages') => CustomerMessage::getTotalCustomerMessages('id_employee = 0'), - $this->l('Total number of employee messages') => CustomerMessage::getTotalCustomerMessages('id_employee != 0'), - $this->l('Unread threads') => $unread = CustomerThread::getTotalCustomerThreads('status = "open"'), - $this->l('Closed threads') => $all - ($unread + $pending) + $stats = array( + array( + 'title' => $this->l('Total threads'), + 'val' => $all = CustomerThread::getTotalCustomerThreads(), + ), + array( + 'title' => $this->l('Threads pending'), + 'val' => $pending = CustomerThread::getTotalCustomerThreads( + 'status='.(int) CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1.' + OR status='.(int) CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2 + ), + ), + array( + 'title' => $this->l('Total number of customer messages'), + 'val' => CustomerMessage::getTotalCustomerMessages('id_employee = 0'), + ), + array( + 'title' => $this->l('Total number of employee messages'), + 'val' => CustomerMessage::getTotalCustomerMessages('id_employee != 0'), + ), + array( + 'title' => $this->l('Unread threads'), + 'val' => $unread = CustomerThread::getTotalCustomerThreads( + 'status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN + ), + ), + array( + 'title' => $this->l('Closed threads'), + 'val' => $all - ($unread + $pending), + ), ); $this->tpl_list_vars = array( 'contacts' => $contacts, 'categories' => $categories, - 'params' => $params + 'stats' => $stats ); return parent::renderList(); @@ -342,10 +451,9 @@ class AdminCustomerThreadsControllerCore extends AdminController ); } if ($id_status = (int)Tools::getValue('setstatus')) { - $status_array = array(1 => 'open', 2 => 'closed', 3 => 'pending1', 4 => 'pending2'); Db::getInstance()->execute(' UPDATE '._DB_PREFIX_.'customer_thread - SET status = "'.$status_array[$id_status].'" + SET status = "'.(int) $id_status.'" WHERE id_customer_thread = '.(int)$id_customer_thread.' LIMIT 1 '); } @@ -363,7 +471,7 @@ class AdminCustomerThreadsControllerCore extends AdminController LEFT OUTER JOIN '._DB_PREFIX_.'customer c ON (c.email = ct.email) WHERE ct.id_customer_thread = '.(int)Tools::getValue('id_customer_thread').' - ORDER BY cm.date_add DESC + ORDER BY cm.date_add, cm.id_employee, cm.private DESC '); $output = $this->displayMessage($messages, true, (int)Tools::getValue('id_employee_forward')); $cm = new CustomerMessage(); @@ -395,7 +503,8 @@ class AdminCustomerThreadsControllerCore extends AdminController $employee->firstname.' '.$employee->lastname, $current_employee->email, $current_employee->firstname.' '.$current_employee->lastname, - null, null, _PS_MAIL_DIR_, true)) { + null, null, _PS_MAIL_DIR_, true) + ) { $cm->id_employee = (int)$employee->id; $cm->private = 1; $cm->message = $this->l('Message forwarded to').' '.$employee->firstname.' '.$employee->lastname."\n".$this->l('Comment:').' '.$message; @@ -424,7 +533,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->errors[] = '
'.Tools::displayError('The email address is invalid.').'
'; } } - if (Tools::isSubmit('submitReply')) { + if (Tools::isSubmit('submitReply') || Tools::isSubmit('submitReplyAndClose')) { $ct = new CustomerThread($id_customer_thread); ShopUrl::cacheMainDomainForShop((int)$ct->id_shop); @@ -446,14 +555,26 @@ class AdminCustomerThreadsControllerCore extends AdminController $file_attachment['mime'] = $_FILES['joinFile']['type']; } $customer = new Customer($ct->id_customer); + if ($ct->id_order) { + $link = Tools::url( + $this->context->link->getPageLink('order-detail', true, (int)$ct->id_lang, null, false, $ct->id_shop), + 'id_order='.$ct->id_order + ); + } else { + $link = Tools::url( + $this->context->link->getPageLink('contact', true, (int)$ct->id_lang, null, false, $ct->id_shop), + 'token='.$ct->token + ); + } + + $headingText = $this->l('Hi'); + if ($customer->id) { + $headingText .= ' '.$customer->firstname.' '.$customer->lastname; + } $params = array( '{reply}' => Tools::nl2br(Tools::getValue('reply_message')), - '{link}' => Tools::url( - $this->context->link->getPageLink('contact', true, (int)$ct->id_lang, null, false, $ct->id_shop), - 'id_customer_thread='.(int)$ct->id.'&token='.$ct->token - ), - '{firstname}' => $customer->firstname, - '{lastname}' => $customer->lastname + '{link}' => $link, + '{headingtext}' => $headingText ); //#ct == id_customer_thread #tc == token of thread <== used in the synchronization imap $contact = new Contact((int)$ct->id_contact, (int)$ct->id_lang); @@ -471,8 +592,12 @@ class AdminCustomerThreadsControllerCore extends AdminController 'reply_msg', sprintf(Mail::l('An answer to your message is available #ct%1$s #tc%2$s', $ct->id_lang), $ct->id, $ct->token), $params, Tools::getValue('msg_email'), null, $from_email, $from_name, $file_attachment, null, - _PS_MAIL_DIR_, true, $ct->id_shop)) { - $ct->status = 'closed'; + _PS_MAIL_DIR_, true, $ct->id_shop) + ) { + if (Tools::isSubmit('submitReplyAndClose')) { + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED; + } + $ct->update(); } Tools::redirectAdmin( @@ -481,7 +606,24 @@ class AdminCustomerThreadsControllerCore extends AdminController } else { $this->errors[] = Tools::displayError('An error occurred. Your message was not sent. Please contact your system administrator.'); } + } else if (Tools::isSubmit('submitReplyAsPrivate')) { + $ct = new CustomerThread($id_customer_thread); + ShopUrl::cacheMainDomainForShop((int)$ct->id_shop); + $cm = new CustomerMessage(); + $cm->id_employee = (int)$this->context->employee->id; + $cm->id_customer_thread = $ct->id; + $cm->ip_address = (int)ip2long(Tools::getRemoteAddr()); + $cm->message = Tools::getValue('reply_message'); + $cm->private = 1; + $cm->read = 1; + if (($error = $cm->validateField('message', $cm->message, null, array(), true)) !== true) { + $this->errors[] = $error; + } elseif (!$cm->add()) { + $this->errors[] = Tools::displayError('Some error occured while saving the message'); + } } + + } return parent::postProcess(); @@ -603,64 +745,54 @@ class AdminCustomerThreadsControllerCore extends AdminController } } - $next_thread = CustomerThread::getNextThread((int)$thread->id); - $contacts = Contact::getContacts($this->context->language->id); - $actions = array(); - if ($next_thread) { - $next_thread = array( - 'href' => self::$currentIndex.'&id_customer_thread='.(int)$next_thread.'&viewcustomer_thread&token='.$this->token, - 'name' => $this->l('Reply to the next unanswered message in this thread') - ); - } - - if ($thread->status != 'closed') { - $actions['closed'] = array( - 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus=2&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, + if ($thread->status != CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED) { + $actions[CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED] = array( + 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED.'&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, 'label' => $this->l('Mark as "handled"'), 'name' => 'setstatus', - 'value' => 2 + 'value' => CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED ); } else { - $actions['open'] = array( - 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus=1&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, + $actions[CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN] = array( + 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.'&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, 'label' => $this->l('Re-open'), 'name' => 'setstatus', - 'value' => 1 + 'value' => CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN ); } - if ($thread->status != 'pending1') { - $actions['pending1'] = array( - 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus=3&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, + if ($thread->status != CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1) { + $actions[CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1] = array( + 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1.'&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, 'label' => $this->l('Mark as "pending 1" (will be answered later)'), 'name' => 'setstatus', - 'value' => 3 + 'value' => CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1 ); } else { - $actions['pending1'] = array( - 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus=1&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, + $actions[CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1] = array( + 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.'&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, 'label' => $this->l('Disable pending status'), 'name' => 'setstatus', - 'value' => 1 + 'value' => CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN ); } - if ($thread->status != 'pending2') { - $actions['pending2'] = array( - 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus=4&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, + if ($thread->status != CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2) { + $actions[CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2] = array( + 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2.'&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, 'label' => $this->l('Mark as "pending 2" (will be answered later)'), 'name' => 'setstatus', - 'value' => 4 + 'value' => CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2 ); } else { - $actions['pending2'] = array( - 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus=1&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, + $actions[CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2] = array( + 'href' => self::$currentIndex.'&viewcustomer_thread&setstatus='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.'&id_customer_thread='.(int)Tools::getValue('id_customer_thread').'&viewmsg&token='.$this->token, 'label' => $this->l('Disable pending status'), 'name' => 'setstatus', - 'value' => 1 + 'value' => CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN ); } @@ -710,7 +842,6 @@ class AdminCustomerThreadsControllerCore extends AdminController 'messages' => $messages, 'first_message' => $first_message, 'contact' => $contact, - 'next_thread' => $next_thread, 'orders' => isset($orders) ? $orders : false, 'customer' => isset($customer) ? $customer : false, 'products' => isset($products) ? $products : false, @@ -721,10 +852,6 @@ class AdminCustomerThreadsControllerCore extends AdminController 'timeline_items' => $timeline_items, ); - if ($next_thread) { - $this->tpl_view_vars['next_thread'] = $next_thread; - } - return parent::renderView(); } @@ -737,10 +864,15 @@ class AdminCustomerThreadsControllerCore extends AdminController $content = ''; if (!$message['private']) { - $content .= $this->l('Message to: ').' '.(!$message['id_employee'] ? $message['subject'] : $message['customer_name']).'
'; + if ($message['id_employee']) { + $content .= $this->l('Message to: ').' '.($message['customer_name']).'

'; + } + } else { + $content .= ''.$this->l('Private').'

'; } + if (Validate::isLoadedObject($product)) { - $content .= '
'.$this->l('Room type: ').''.$product->name.'

'; + $content .= $this->l('Room type: ').''.$product->name.'

'; } $content .= Tools::safeOutput($message['message']); @@ -1079,7 +1211,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $ct->id_contact = $id_contact; $ct->id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $ct->id_shop = $this->context->shop->id; //new customer threads for unrecognized mails are not shown without shop id - $ct->status = 'open'; + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $ct->token = Tools::passwdGen(12); $ct->add(); } else { diff --git a/controllers/admin/AdminEmailsController.php b/controllers/admin/AdminEmailsController.php index b933780ad..47159695d 100644 --- a/controllers/admin/AdminEmailsController.php +++ b/controllers/admin/AdminEmailsController.php @@ -80,25 +80,11 @@ class AdminEmailsControllerCore extends AdminController } parent::__construct(); - - foreach (Contact::getContacts($this->context->language->id) as $contact) { - $arr[] = array('email_message' => $contact['id_contact'], 'name' => $contact['name']); - } - $this->fields_options = array( 'email' => array( 'title' => $this->l('Email'), 'icon' => 'icon-envelope', - 'fields' => array( - 'PS_MAIL_EMAIL_MESSAGE' => array( - 'title' => $this->l('Send email to'), - 'desc' => $this->l('Where customers send messages from the order page.'), - 'validation' => 'isUnsignedId', - 'type' => 'select', - 'cast' => 'intval', - 'identifier' => 'email_message', - 'list' => $arr - ), + 'fields' => array( 'PS_MAIL_METHOD' => array( 'title' => '', 'validation' => 'isGenericName', diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index b852574d7..9c33b112a 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1424,7 +1424,7 @@ class AdminOrdersControllerCore extends AdminController $customer_thread->id_order = (int)$order->id; $customer_thread->id_lang = (int)$this->context->language->id; $customer_thread->email = $customer->email; - $customer_thread->status = 'open'; + $customer_thread->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $customer_thread->token = Tools::passwdGen(12); $customer_thread->add(); } else { @@ -3036,6 +3036,13 @@ class AdminOrdersControllerCore extends AdminController } } } + + $objCustomerThread = new CustomerThread(); + $messages = Message::getMessagesByOrderId($order->id, true); + if ($customerMessages = CustomerMessage::getMessagesByOrderId($order->id, true)) { + $messages = array_merge($messages, $customerMessages); + } + $this->tpl_view_vars = array( 'guestFormattedAddress' => $guestFormattedAddress, 'idOrderAddressInvoice' => $idOrderAddressInvoice, @@ -3080,8 +3087,9 @@ class AdminOrdersControllerCore extends AdminController 'discounts' => $order->getCartRules(), 'total_paid' => $order->getTotalPaid(), 'customer_thread_message' => CustomerThread::getCustomerMessages($order->id_customer, null, $order->id), + 'id_customer_thread' => $objCustomerThread->getIdCustomerThreadByIdOrder($order->id), 'orderMessages' => OrderMessage::getOrderMessages($order->id_lang), - 'messages' => Message::getMessagesByOrderId($order->id, true), + 'messages' => $messages, 'carrier' => new Carrier($order->id_carrier), 'history' => $history, 'order_payment_detail' => $order_payment_detail, diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 226909df4..b3b863326 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -39,16 +39,40 @@ class ContactControllerCore extends FrontController $saveContactKey = $this->context->cookie->contactFormKey; $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg'); $file_attachment = Tools::fileAttachment('fileUpload'); - $message = Tools::getValue('message'); // Html entities is not usefull, iscleanHtml check there is no bad html tags. + $message = trim(Tools::getValue('message')); // Html entities is not usefull, iscleanHtml check there is no bad html tags. $url = Tools::getValue('url'); + $phone = Tools::getValue('phone'); + $subject = trim(Tools::getValue('subject')); + $userName = Tools::getValue('user_name'); + $id_contact = (int)Tools::getValue('id_contact'); + $objCustomerThread = new CustomerThread(); + $id_customer_thread = (int)$objCustomerThread->getIdCustomerThreadByToken(Tools::getValue('token')); + $nameRequired = Configuration::get('PS_CUSTOMER_SERVICE_NAME_REQUIRED'); + $phoneRequired = Configuration::get('PS_CUSTOMER_SERVICE_PHONE_REQUIRED'); + if (!Configuration::get('PS_CUSTOMER_SERVICE_CONTACT_ALLOW')) { + $id_contact = (int) Configuration::get('PS_CUSTOMER_SERVICE_EMAIL_MESSAGE'); + } + if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) { $this->errors[] = Tools::displayError('Invalid email address.'); } elseif (!$message) { $this->errors[] = Tools::displayError('The message cannot be blank.'); } elseif (!Validate::isCleanHtml($message)) { $this->errors[] = Tools::displayError('Invalid message'); - } elseif (!($id_contact = (int)Tools::getValue('id_contact')) || !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id)))) { - $this->errors[] = Tools::displayError('Please select a subject from the list provided. '); + } elseif (!$id_customer_thread && !$subject) { + $this->errors[] = Tools::displayError('The subject cannot be blank.'); + } elseif (!$id_customer_thread && !Validate::isCleanHtml($subject)) { + $this->errors[] = Tools::displayError('Invalid subject$subject'); + } else if (!$id_customer_thread && $nameRequired && !trim($userName)) { + $this->errors[] = Tools::displayError('Name is required.'); + } else if (!$id_customer_thread && trim($nameRequired) && !Validate::isGenericName($userName)) { + $this->errors[] = Tools::displayError('Invalid name.'); + } else if (!$id_customer_thread && $phoneRequired && !trim($phone)) { + $this->errors[] = Tools::displayError('Phone is required.'); + } else if (!$id_customer_thread && trim($phone) && !Validate::isPhoneNumber($phone)) { + $this->errors[] = Tools::displayError('Invalid Phone number.'); + } elseif (!Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id))) { + $this->errors[] = Tools::displayError('Please select a subject from the list provided.'); } elseif (!empty($file_attachment['name']) && $file_attachment['error'] != 0) { $this->errors[] = Tools::displayError('An error occurred during the file-upload process.'); } elseif (!empty($file_attachment['name']) && !in_array(Tools::strtolower(substr($file_attachment['name'], -4)), $extension) && !in_array(Tools::strtolower(substr($file_attachment['name'], -5)), $extension)) { @@ -71,44 +95,15 @@ class ContactControllerCore extends FrontController $id_order = (int) $order->id_customer === (int) $customer->id ? $id_order : 0; } - if (!(( - ($id_customer_thread = (int)Tools::getValue('id_customer_thread')) - && (int)Db::getInstance()->getValue(' - SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm - WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND cm.id_shop = '.(int)$this->context->shop->id.' AND token = \''.pSQL(Tools::getValue('token')).'\'') - ) || ( - $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, $id_order, $id_contact) - ))) { - $fields = Db::getInstance()->executeS(' - SELECT cm.id_customer_thread, cm.id_contact, cm.id_customer, cm.id_order, cm.id_product, cm.email - FROM '._DB_PREFIX_.'customer_thread cm - WHERE email = \''.pSQL($from).'\' AND cm.id_shop = '.(int)$this->context->shop->id.' AND ('. - ($customer->id ? 'id_customer = '.(int)$customer->id.' OR ' : '').' - id_order = '.(int)$id_order.')'); - $score = 0; - foreach ($fields as $key => $row) { - $tmp = 0; - if ((int)$row['id_customer'] && $row['id_customer'] != $customer->id && $row['email'] != $from) { - continue; - } - if ($row['id_order'] != 0 && $id_order != $row['id_order']) { - continue; - } - if ($row['email'] == $from) { - $tmp += 4; - } - if ($row['id_contact'] == $id_contact) { - $tmp++; - } - if (Tools::getValue('id_product') != 0 && $row['id_product'] == Tools::getValue('id_product')) { - $tmp += 2; - } - if ($tmp >= 5 && $tmp >= $score) { - $score = $tmp; - $id_customer_thread = $row['id_customer_thread']; - } - } + if (!$id_customer_thread) { + $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder( + $from, + $id_order, + $id_contact, + ' AND a.`status` !='. CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED + ); } + $old_message = Db::getInstance()->getValue(' SELECT cm.message FROM '._DB_PREFIX_.'customer_message cm LEFT JOIN '._DB_PREFIX_.'customer_thread cc on (cm.id_customer_thread = cc.id_customer_thread) @@ -123,13 +118,10 @@ class ContactControllerCore extends FrontController if ($contact->customer_service) { if ((int)$id_customer_thread) { $ct = new CustomerThread($id_customer_thread); - $ct->status = 'open'; + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $ct->id_lang = (int)$this->context->language->id; $ct->id_contact = (int)$id_contact; $ct->id_order = (int)$id_order; - if ($id_product = (int)Tools::getValue('id_product')) { - $ct->id_product = $id_product; - } $ct->update(); } else { $ct = new CustomerThread(); @@ -137,14 +129,13 @@ class ContactControllerCore extends FrontController $ct->id_customer = (int)$customer->id; } $ct->id_shop = (int)$this->context->shop->id; - $ct->id_order = (int)$id_order; - if ($id_product = (int)Tools::getValue('id_product')) { - $ct->id_product = $id_product; - } + $ct->phone = $phone; + $ct->user_name = $userName; + $ct->subject = $subject; $ct->id_contact = (int)$id_contact; $ct->id_lang = (int)$this->context->language->id; $ct->email = $from; - $ct->status = 'open'; + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $ct->token = Tools::passwdGen(12); $ct->add(); } @@ -153,6 +144,9 @@ class ContactControllerCore extends FrontController $cm = new CustomerMessage(); $cm->id_customer_thread = $ct->id; $cm->message = $message; + if ($id_product = (int)Tools::getValue('id_product')) { + $cm->id_product = $id_product; + } if (isset($file_attachment['rename']) && !empty($file_attachment['rename']) && rename($file_attachment['tmp_name'], _PS_UPLOAD_DIR_.basename($file_attachment['rename']))) { $cm->file_name = $file_attachment['rename']; @chmod(_PS_UPLOAD_DIR_.basename($file_attachment['rename']), 0664); @@ -266,21 +260,21 @@ class ContactControllerCore extends FrontController 'max_upload_size' => (int)Tools::getMaxUploadSize() )); - if (($id_customer_thread = (int)Tools::getValue('id_customer_thread')) && $token = Tools::getValue('token')) { - $customer_thread = Db::getInstance()->getRow(' + if ($token = Tools::getValue('token')) { + if ($customer_thread = Db::getInstance()->getRow(' SELECT cm.* FROM '._DB_PREFIX_.'customer_thread cm - WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' - AND cm.id_shop = '.(int)$this->context->shop->id.' + WHERE cm.id_shop = '.(int)$this->context->shop->id.' AND token = \''.pSQL($token).'\' - '); - - $order = new Order((int)$customer_thread['id_order']); - if (Validate::isLoadedObject($order)) { - $customer_thread['reference'] = $order->getUniqReference(); + ')) { + $order = new Order((int)$customer_thread['id_order']); + if (Validate::isLoadedObject($order)) { + $customer_thread['reference'] = $order->getUniqReference(); + } + $this->context->smarty->assign('customerThread', $customer_thread); } - $this->context->smarty->assign('customerThread', $customer_thread); } + // Send Hotel location information $gblHtlAddress = Configuration::get('WK_HOTEL_GLOBAL_ADDRESS'); $gblHtlPhone = Configuration::get('WK_HOTEL_GLOBAL_CONTACT_NUMBER'); @@ -320,6 +314,9 @@ class ContactControllerCore extends FrontController 'contacts' => Contact::getContacts($this->context->language->id), 'message' => html_entity_decode(Tools::getValue('message')), 'contactKey' => $contactKey, + 'contactNameRequired' => Configuration::get('PS_CUSTOMER_SERVICE_NAME_REQUIRED'), + 'contactPhoneRequired' => Configuration::get('PS_CUSTOMER_SERVICE_PHONE_REQUIRED'), + 'allowContactSelection' => Configuration::get('PS_CUSTOMER_SERVICE_CONTACT_ALLOW') ) ); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 3b15a99b6..892273c29 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -695,21 +695,23 @@ class OrderDetailControllerCore extends FrontController $ct->id_contact = 0; $ct->id_customer = (int)$order->id_customer; $ct->id_shop = (int)$this->context->shop->id; - if ($id_product && $order->orderContainProduct($id_product)) { - $ct->id_product = $id_product; - } $ct->id_order = (int)$order->id; $ct->id_lang = (int)$this->context->language->id; $ct->email = $this->context->customer->email; - $ct->status = 'open'; + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $ct->token = Tools::passwdGen(12); $ct->add(); } else { $ct = new CustomerThread((int)$id_customer_thread); - $ct->status = 'open'; + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $ct->update(); } + if ($id_product && $order->orderContainProduct($id_product)) { + $cm->id_product = $id_product; + } + + $cm->user_agent = $_SERVER['HTTP_USER_AGENT']; $cm->id_customer_thread = $ct->id; $cm->message = $msgText; $cm->ip_address = (int)ip2long($_SERVER['REMOTE_ADDR']); @@ -819,4 +821,4 @@ class OrderDetailControllerCore extends FrontController } } } -} \ No newline at end of file +} diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index de57c4024..ed8b8c64e 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -633,6 +633,7 @@ CREATE TABLE `PREFIX_customer_message` ( `id_customer_thread` int(11) DEFAULT NULL, `id_employee` int(10) unsigned DEFAULT NULL, `message` MEDIUMTEXT NOT NULL, + `id_product` int(10) unsigned DEFAULT NULL, `file_name` varchar(18) DEFAULT NULL, `ip_address` varchar(16) DEFAULT NULL, `user_agent` varchar(128) DEFAULT NULL, @@ -658,8 +659,10 @@ CREATE TABLE `PREFIX_customer_thread` ( `id_contact` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned DEFAULT NULL, `id_order` int(10) unsigned DEFAULT NULL, - `id_product` int(10) unsigned DEFAULT NULL, - `status` enum('open','closed','pending1','pending2') NOT NULL DEFAULT 'open', + `user_name` VARCHAR(128) DEFAULT NULL, + `phone` VARCHAR(32) DEFAULT NULL, + `subject` TEXT DEFAULT NULL, + `status` INT(10) NOT NULL DEFAULT 1, `email` varchar(128) NOT NULL, `token` varchar(12) DEFAULT NULL, `date_add` datetime NOT NULL, diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 490e2b691..1b6169fc9 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -946,6 +946,15 @@ 0 + + + 1 + + + 1 + + + 1 diff --git a/js/admin/customer_thread.js b/js/admin/customer_thread.js new file mode 100644 index 000000000..bee35d067 --- /dev/null +++ b/js/admin/customer_thread.js @@ -0,0 +1,32 @@ +/* +* Copyright since 2010 Webkul. +* +* NOTICE OF LICENSE +* +* All right is reserved, +* Please go through this link for complete license : https://store.webkul.com/license.html +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade this module to newer +* versions in the future. If you wish to customize this module for your +* needs please refer to https://store.webkul.com/customisation-guidelines/ for more information. +* +* @author Webkul IN +* @copyright Since 2010 Webkul IN +* @license https://store.webkul.com/license.html +*/ + +$(document).ready(function() { + if ($('#PS_CUSTOMER_SERVICE_CONTACT_ALLOW_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').hide(); + } + + $(document).on('change', '[name="PS_CUSTOMER_SERVICE_CONTACT_ALLOW"]', function() { + if ($('#PS_CUSTOMER_SERVICE_CONTACT_ALLOW_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').hide(); + } else { + $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').show(); + } + }); +}); diff --git a/mails/en/reply_msg.html b/mails/en/reply_msg.html index b26a5a41d..c71767da6 100644 --- a/mails/en/reply_msg.html +++ b/mails/en/reply_msg.html @@ -4,51 +4,51 @@ Message from {shop_name} - - - @@ -66,31 +66,29 @@ - - - - Hi {firstname} {lastname}, - - - -   - - - - {reply} - - - -   - - - - - Please do not reply directly to this email, we will not receive it.
- In order to reply, please use the following link: {link}
- - - + + + {headingtext} + + + +   + + + + {reply} + + + +   + + + + + Please do not reply directly to this email, we will not receive it.
+ In order to reply, you can click here
+ +   diff --git a/mails/en/reply_msg.txt b/mails/en/reply_msg.txt index 6c91280e4..c654fa2df 100644 --- a/mails/en/reply_msg.txt +++ b/mails/en/reply_msg.txt @@ -1,14 +1,14 @@ -[/{shop_url}] +[/{shop_url}] -Hi {firstname} {lastname}, +{headingtext}, -{reply} +{reply} -Please do not reply directly to this email, we will not receive it. +Please do not reply directly to this email, we will not receive it. -In order to reply, please use the following link: {link} [/{link}] +In order to reply, you can click here [/{link}]. {shop_name} [/{shop_url}] powered by Webkul(tm) -[https://webkul.com] +[https://webkul.com] diff --git a/themes/hotel-reservation-theme/contact-form.tpl b/themes/hotel-reservation-theme/contact-form.tpl index 6a5aedbe0..144a56043 100644 --- a/themes/hotel-reservation-theme/contact-form.tpl +++ b/themes/hotel-reservation-theme/contact-form.tpl @@ -70,25 +70,56 @@ {/if}
{block name='contact_form_content'} + {if isset($customerThread.token)} + + {else} - {if isset($customerThread.id_contact) && $customerThread.id_contact && $contacts|count} - {assign var=flag value=true} - {foreach from=$contacts item=contact} - {if $contact.id_contact == $customerThread.id_contact} - - - {$flag=false} + {/if} + {if !isset($customerThread.id_contact)} +
+
+ + +
+
+ {/if} +
+
+ + {if isset($customerThread.email)} + + {else} + {/if} - {/foreach} - {if $flag && isset($contacts.0.id_contact)} - - - {/if} - {else} +
+
+ {if !isset($customerThread.id_contact)} +
+
+ + +
+
+
+
+ + +
+
+ {/if} + {if !isset($customerThread.id_contact) && isset($allowContactSelection) && $allowContactSelection}
+ {elseif isset($customerThread.id_contact) && isset($allowContactSelection) && $allowContactSelection} + {/if} -
-
- - {if isset($customerThread.email)} - - {else} - - {/if} -
-
+
+ {l s='* Required fields'} +
{if $fileupload == 1}
diff --git a/themes/hotel-reservation-theme/css/contact-form.css b/themes/hotel-reservation-theme/css/contact-form.css index 5ffae05e0..a53fe0290 100644 --- a/themes/hotel-reservation-theme/css/contact-form.css +++ b/themes/hotel-reservation-theme/css/contact-form.css @@ -200,13 +200,13 @@ font-size: 16px; font-weight: 600; height: 47px; - margin-bottom: 20px; + margin-bottom: 5px; padding: 10px; } .contact_textarea { color: #9a9a9a; height: 150px !important; - margin-bottom: 20px; + margin-bottom: 5px; padding: 10px; font-size: 16px; font-weight: 600; diff --git a/themes/hotel-reservation-theme/css/order-detail.css b/themes/hotel-reservation-theme/css/order-detail.css index 1f188cedc..c3382f5d1 100644 --- a/themes/hotel-reservation-theme/css/order-detail.css +++ b/themes/hotel-reservation-theme/css/order-detail.css @@ -606,7 +606,7 @@ color: #55c65e; } -#sendOrderMessage { +#sendOrderMessage, .select-room-type .card-subheader { margin-bottom: 10px; } @@ -1121,4 +1121,4 @@ text-decoration: underline; text-underline-offset: 3px; } -/* Guest Tracking page styles - end */ \ No newline at end of file +/* Guest Tracking page styles - end */ diff --git a/themes/hotel-reservation-theme/order-detail.tpl b/themes/hotel-reservation-theme/order-detail.tpl index 9ac445d81..f085dceaf 100644 --- a/themes/hotel-reservation-theme/order-detail.tpl +++ b/themes/hotel-reservation-theme/order-detail.tpl @@ -528,6 +528,9 @@
+

+ {l s='To add a comment about a room type, please select one first.'} +

-
+
+
+ +
- {/if} +
- {if !isset($customerThread.id_contact)} -
-
- - -
+
+
+ +
-
-
- - -
+
+
+
+ +
- {/if} +
{if !isset($customerThread.id_contact) && isset($allowContactSelection) && $allowContactSelection}
From 8901e71d30859b513c79afbb978fbe40bf2970c2 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 27 Feb 2025 15:58:51 +0530 Subject: [PATCH 03/13] Fixed indentation --- admin/themes/default/template/controllers/orders/form.tpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/themes/default/template/controllers/orders/form.tpl b/admin/themes/default/template/controllers/orders/form.tpl index a1a525b16..e7f91d247 100644 --- a/admin/themes/default/template/controllers/orders/form.tpl +++ b/admin/themes/default/template/controllers/orders/form.tpl @@ -294,7 +294,8 @@ action: "updateOrderMessage", id_cart: id_cart, id_customer: id_customer, - message: $(this).val() }, + message: $(this).val() + }, success : function(res) { displaySummary(res); From 62474a34973a7190d5a775713f55bed079840db8 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Mon, 21 Apr 2025 16:11:37 +0530 Subject: [PATCH 04/13] Removed: Message to is removed in case no customer name is added in the customer message --- controllers/admin/AdminCustomerThreadsController.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 0916fb3eb..dddc015d9 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -864,8 +864,15 @@ class AdminCustomerThreadsControllerCore extends AdminController $content = ''; if (!$message['private']) { - if ($message['id_employee']) { - $content .= $this->l('Message to: ').' '.($message['customer_name']).'

'; + $customerName = false; + if (!$message['id_customer']) { + $customerName = $message['user_name']; + } else if ($message['customer_name']) { + $customerName = $message['customer_name']; + } + + if ($message['id_employee'] && $customerName) { + $content .= $this->l('Message to: ').' '.($customerName).'

'; } } else { $content .= ''.$this->l('Private').'

'; From def33d9474cb508c20f1f5cb74da34744c28a851 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Thu, 8 May 2025 17:41:35 +0530 Subject: [PATCH 05/13] Updated the flow for customer message and order message, and fixed some minor issues --- .../customer_threads/helpers/view/view.tpl | 4 +- .../controllers/orders/helpers/view/view.tpl | 7 +- classes/CustomerMessage.php | 4 +- classes/CustomerThread.php | 2 + classes/Message.php | 4 +- .../WebserviceSpecificManagementBookings.php | 4 +- .../admin/AdminCustomerThreadsController.php | 166 +++++++++++++----- controllers/admin/AdminOrdersController.php | 6 +- controllers/front/ContactController.php | 35 ++-- controllers/front/OrderDetailController.php | 8 +- install/data/db_structure.sql | 1 + install/data/xml/configuration.xml | 6 + js/admin/customer_thread.js | 27 +++ mails/en/contact.html | 1 + mails/en/contact.txt | 12 +- mails/en/order_customer_comment.html | 50 +++--- mails/en/order_customer_comment.txt | 10 +- mails/en/reply_msg.html | 5 + mails/en/reply_msg.txt | 2 + .../hotel-reservation-theme/contact-form.tpl | 16 +- 20 files changed, 250 insertions(+), 120 deletions(-) diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl index fb68b64e7..6cb1f5885 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl @@ -111,8 +111,8 @@ {l s="Choose a template"} --> - - + + diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index b823f98a1..95bbe3d36 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -703,13 +703,13 @@
{* Order Internal notes *} - {if (sizeof($messages))} + {if isset($messages) && $messages}
-  {l s='Order Notes'} +  {l s='Order Private Notes'}
- {foreach from=$messages item=message} + {foreach from=$messages item=message name=customerMessage}

{$message['message']|escape:'html':'UTF-8'|nl2br} @@ -726,6 +726,7 @@ {/if}

+ {if !$smarty.foreach.customerMessage.last}
{/if} {* {if ($message['is_new_for_me'])} diff --git a/classes/CustomerMessage.php b/classes/CustomerMessage.php index 6ac21bbef..abc6df3ef 100644 --- a/classes/CustomerMessage.php +++ b/classes/CustomerMessage.php @@ -74,7 +74,7 @@ class CustomerMessageCore extends ObjectModel ), ); - public static function getMessagesByOrderId($id_order, $private = true, $limit = false) + public static function getMessagesByOrderId($id_order, $private = null, $limit = false) { return Db::getInstance()->executeS(' SELECT cm.*, @@ -91,7 +91,7 @@ class CustomerMessageCore extends ObjectModel LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = cm.`id_employee` WHERE ct.id_order = '.(int)$id_order.' - '.(!$private ? 'AND cm.`private` = 0' : '').' + '.(!is_null($private) ? 'AND cm.`private` = '.(int) $private : '').' GROUP BY cm.id_customer_message ORDER BY cm.date_add DESC'. (($limit) ? ' LIMIT '.(int) $limit: ' ') diff --git a/classes/CustomerThread.php b/classes/CustomerThread.php index 367499a0a..04fb60851 100644 --- a/classes/CustomerThread.php +++ b/classes/CustomerThread.php @@ -30,6 +30,7 @@ class CustomerThreadCore extends ObjectModel public $id_shop; public $id_lang; public $id_contact; + public $id_employee; public $id_customer; public $id_order; public $user_name; @@ -60,6 +61,7 @@ class CustomerThreadCore extends ObjectModel 'subject' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml'), 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_customer' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), + 'id_employee' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 254), 'token' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true), diff --git a/classes/Message.php b/classes/Message.php index 0d1deaf2d..42a16bc54 100644 --- a/classes/Message.php +++ b/classes/Message.php @@ -88,7 +88,7 @@ class MessageCore extends ObjectModel * @param bool $private return WITH private messages * @return array Messages */ - public static function getMessagesByOrderId($id_order, $private = false, Context $context = null) + public static function getMessagesByOrderId($id_order, $private = null, Context $context = null) { if (!Validate::isBool($private)) { die(Tools::displayError()); @@ -108,7 +108,7 @@ class MessageCore extends ObjectModel AND mr.`id_employee` = '.(isset($context->employee) ? (int)$context->employee->id : '\'\'').' LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee` WHERE id_order = '.(int)$id_order.' - '.(!$private ? ' AND m.`private` = 0' : '').' + '.(!is_null($private) ? ' AND m.`private` = '.(int) $private : '').' GROUP BY m.id_message ORDER BY m.date_add DESC '); diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php index 8d3580781..72c8b3447 100644 --- a/classes/webservice/WebserviceSpecificManagementBookings.php +++ b/classes/webservice/WebserviceSpecificManagementBookings.php @@ -2610,7 +2610,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We $message = strip_tags($remark, '
'); $saveMessage = true; $idCart = Cart::getCartIdByOrderId($objOrder->id); - if ($customerMessages = Message::getMessagesByOrderId($objOrder->id, true)) { + if ($customerMessages = Message::getMessagesByOrderId($objOrder->id, false)) { foreach ($customerMessages as $customerMessage) { if ($customerMessage['message'] == $message) { $saveMessage = false; @@ -3424,7 +3424,7 @@ class WebserviceSpecificManagementBookingsCore Extends ObjectModel implements We } $params['associations']['remarks'] = array(); - if ($customerMessages = Message::getMessagesByOrderId($objOrder->id, true)) { + if ($customerMessages = Message::getMessagesByOrderId($objOrder->id)) { foreach ($customerMessages as $customerMessage) { $message = $customerMessage['message']; $params['associations']['remarks'][] = $message; diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index dddc015d9..7f2940ec1 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -114,10 +114,10 @@ class AdminCustomerThreadsControllerCore extends AdminController 'filter_type' => 'int', ), 'subject' => array( - 'title' => $this->l('Subject'), + 'title' => $this->l('Title'), 'filter_key' => 'a!subject', 'tmpTableFilter' => true, - 'maxlength' => 40, + 'maxlength' => 30, 'optional' => true, 'visible_default' => true, ), @@ -142,25 +142,28 @@ class AdminCustomerThreadsControllerCore extends AdminController 'title' => $this->l('Employee'), 'filter_key' => 'employee', 'tmpTableFilter' => true, + 'optional' => true, + ), + 'last_employee' => array( + 'title' => $this->l('Last Reply by'), + 'filter_key' => 'employee', + 'tmpTableFilter' => true, + 'optional' => true, ), 'messages' => array( 'title' => $this->l('Messages'), 'filter_key' => 'messages', 'tmpTableFilter' => true, - 'maxlength' => 40, + 'maxlength' => 30, 'optional' => true, ), - 'private' => array( + 'has_private' => array( 'title' => $this->l('Has Private'), - 'type' => 'select', - 'filter_key' => 'private', + 'type' => 'bool', + 'havingFilter' => true, + 'filter_key' => 'has_private', 'align' => 'center', - 'cast' => 'intval', 'callback' => 'printOptinIcon', - 'list' => array( - '0' => $this->l('No'), - '1' => $this->l('Yes') - ) ), 'date_upd' => array( 'title' => $this->l('Last message'), @@ -223,11 +226,21 @@ class AdminCustomerThreadsControllerCore extends AdminController 'hint' => $this->l('Set Name as required while submitting message from the contact page.'), 'type' => 'bool' ), + 'PS_CUSTOMER_SERVICE_NAME_DISPLAY' => array( + 'title' => $this->l('Display Name field'), + 'hint' => $this->l('Display name field on contact page.'), + 'type' => 'bool', + ), 'PS_CUSTOMER_SERVICE_PHONE_REQUIRED' => array( 'title' => $this->l('Set Phone as required'), 'hint' => $this->l('Set Phone as required while submitting message from the contact page.'), 'type' => 'bool' ), + 'PS_CUSTOMER_SERVICE_PHONE_DISPLAY' => array( + 'title' => $this->l('Display Phone field'), + 'hint' => $this->l('Display phone field on contact page.'), + 'type' => 'bool', + ), 'PS_CUSTOMER_SERVICE_SIGNATURE' => array( 'title' => $this->l('Default message'), 'hint' => $this->l('Please fill out the message fields that appear by default when you answer a thread on the customer service page.'), @@ -343,7 +356,8 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->addRowAction('delete'); $this->_select = ' - IF(a.`user_name`="", CONCAT(c.`firstname`," ",c.`lastname`), a.`user_name`) AS customer, cl.`name` as contact, l.`name` as language, group_concat(message) as messages, cm.private, + IF(a.`user_name`="", CONCAT(c.`firstname`," ",c.`lastname`), a.`user_name`) AS customer, cl.`name` as contact, l.`name` as language, group_concat(message) as messages, + cm.private, IF(COUNT(CASE WHEN cm.`private` = 1 THEN 1 END), 1, 0) AS `has_private`, ( SELECT IFNULL(CONCAT(LEFT(e.`firstname`, 1),". ",e.`lastname`), "--") FROM `'._DB_PREFIX_.'customer_message` cm2 @@ -352,9 +366,12 @@ class AdminCustomerThreadsControllerCore extends AdminController WHERE cm2.id_employee > 0 AND cm2.`id_customer_thread` = a.`id_customer_thread` ORDER BY cm2.`date_add` DESC LIMIT 1 - ) as employee'; + ) AS last_employee, + IFNULL(CONCAT(LEFT(emp.`firstname`, 1),". ",emp.`lastname`), "--") AS employee'; $this->_join = ' + LEFT JOIN `'._DB_PREFIX_.'employee` emp + ON emp.`id_employee` = a.`id_employee` LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = a.`id_customer` LEFT JOIN `'._DB_PREFIX_.'customer_message` cm @@ -386,11 +403,11 @@ class AdminCustomerThreadsControllerCore extends AdminController ), array( 'title' => $this->l('Total number of customer messages'), - 'val' => CustomerMessage::getTotalCustomerMessages('id_employee = 0'), + 'val' => CustomerMessage::getTotalCustomerMessages('ct.`id_employee` = 0'), ), array( 'title' => $this->l('Total number of employee messages'), - 'val' => CustomerMessage::getTotalCustomerMessages('id_employee != 0'), + 'val' => CustomerMessage::getTotalCustomerMessages('ct.`id_employee` != 0'), ), array( 'title' => $this->l('Unread threads'), @@ -432,6 +449,13 @@ class AdminCustomerThreadsControllerCore extends AdminController if (Tools::isSubmit('submitOptionsCustomerService')) { unset($this->fields_options['general']); $this->processUpdateOptions(); + if (Tools::getValue('PS_CUSTOMER_SERVICE_NAME_REQUIRED')) { + Configuration::updateValue('PS_CUSTOMER_SERVICE_NAME_DISPLAY', 1); + } + + if (Tools::getValue('PS_CUSTOMER_SERVICE_PHONE_REQUIRED')) { + Configuration::updateValue('PS_CUSTOMER_SERVICE_PHONE_DISPLAY', 1); + } } else if (Tools::isSubmit('submitOptionsIMAPConfig')) { unset($this->fields_options['contact']); $this->processUpdateOptions(); @@ -443,6 +467,7 @@ class AdminCustomerThreadsControllerCore extends AdminController } if ($id_customer_thread = (int)Tools::getValue('id_customer_thread')) { + $ct = new CustomerThread($id_customer_thread); if (($id_contact = (int)Tools::getValue('id_contact'))) { Db::getInstance()->execute(' UPDATE '._DB_PREFIX_.'customer_thread @@ -457,7 +482,7 @@ class AdminCustomerThreadsControllerCore extends AdminController WHERE id_customer_thread = '.(int)$id_customer_thread.' LIMIT 1 '); } - if (isset($_POST['id_employee_forward'])) { + if ($id_employee = (int) Tools::getValue('id_employee_forward')) { $messages = Db::getInstance()->getRow(' SELECT ct.*, cm.*, cl.name subject, CONCAT(e.firstname, \' \', e.lastname) employee_name, CONCAT(c.firstname, \' \', c.lastname) customer_name, c.firstname @@ -471,7 +496,7 @@ class AdminCustomerThreadsControllerCore extends AdminController LEFT OUTER JOIN '._DB_PREFIX_.'customer c ON (c.email = ct.email) WHERE ct.id_customer_thread = '.(int)Tools::getValue('id_customer_thread').' - ORDER BY cm.date_add, cm.id_employee, cm.private DESC + ORDER BY cm.id_employee, cm.private, cm.date_add DESC '); $output = $this->displayMessage($messages, true, (int)Tools::getValue('id_employee_forward')); $cm = new CustomerMessage(); @@ -505,6 +530,8 @@ class AdminCustomerThreadsControllerCore extends AdminController $current_employee->firstname.' '.$current_employee->lastname, null, null, _PS_MAIL_DIR_, true) ) { + $ct->id_employee = $employee->id; + $ct->save(); $cm->id_employee = (int)$employee->id; $cm->private = 1; $cm->message = $this->l('Message forwarded to').' '.$employee->firstname.' '.$employee->lastname."\n".$this->l('Comment:').' '.$message; @@ -534,12 +561,13 @@ class AdminCustomerThreadsControllerCore extends AdminController } } if (Tools::isSubmit('submitReply') || Tools::isSubmit('submitReplyAndClose')) { - $ct = new CustomerThread($id_customer_thread); - ShopUrl::cacheMainDomainForShop((int)$ct->id_shop); $cm = new CustomerMessage(); $cm->id_employee = (int)$this->context->employee->id; + if (!$ct->id_employee) { + $ct->id_employee = $this->context->employee->id; + } $cm->id_customer_thread = $ct->id; $cm->ip_address = (int)ip2long(Tools::getRemoteAddr()); $cm->message = Tools::getValue('reply_message'); @@ -555,27 +583,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $file_attachment['mime'] = $_FILES['joinFile']['type']; } $customer = new Customer($ct->id_customer); - if ($ct->id_order) { - $link = Tools::url( - $this->context->link->getPageLink('order-detail', true, (int)$ct->id_lang, null, false, $ct->id_shop), - 'id_order='.$ct->id_order - ); - } else { - $link = Tools::url( - $this->context->link->getPageLink('contact', true, (int)$ct->id_lang, null, false, $ct->id_shop), - 'token='.$ct->token - ); - } - $headingText = $this->l('Hi'); - if ($customer->id) { - $headingText .= ' '.$customer->firstname.' '.$customer->lastname; - } - $params = array( - '{reply}' => Tools::nl2br(Tools::getValue('reply_message')), - '{link}' => $link, - '{headingtext}' => $headingText - ); //#ct == id_customer_thread #tc == token of thread <== used in the synchronization imap $contact = new Contact((int)$ct->id_contact, (int)$ct->id_lang); @@ -587,15 +595,76 @@ class AdminCustomerThreadsControllerCore extends AdminController $from_email = null; } + if ($ct->id_order) { + $link = Tools::url( + $this->context->link->getPageLink('order-detail', true, (int)$ct->id_lang, null, false, $ct->id_shop), + 'id_order='.$ct->id_order + ); + $objOrder = new Order($ct->id_order); + $message = $cm->message; + if (Configuration::get('PS_MAIL_TYPE', null, null, $objOrder->id_shop) != Mail::TYPE_TEXT) { + $message = Tools::nl2br($cm->message); + } + + $objCustomer = new Customer($objOrder->id_customer); + $idShop = $objOrder->id_shop; + $params = array( + '{lastname}' => $objCustomer->lastname, + '{firstname}' => $objCustomer->firstname, + '{id_order}' => $objOrder->id, + '{order_name}' => $objOrder->getUniqReference(), + '{message}' => $message + ); + $toEmail = $objCustomer->email; + $toName = $objCustomer->firstname.' '.$objCustomer->lastname; + $title = Mail::l('New message regarding your booking', (int)$objOrder->id_lang); + $template = 'order_merchant_comment'; + $idLang = $objOrder->id_lang; + } else { + $link = Tools::url( + $this->context->link->getPageLink('contact', true, (int)$ct->id_lang, null, false, $ct->id_shop), + 'token='.$ct->token + ); + $headingText = $this->l('Hi'); + $idShop = $ct->id_shop; + $params = array( + '{reply}' => Tools::nl2br(Tools::getValue('reply_message')), + '{link}' => $link, + '{headingtext}' => $headingText, + ); + if (!empty(trim($ct->subject))) { + $params['{subject}'] = $this->l('Title : ').$ct->subject; + } + + $idLang = $ct->id_lang; + $toEmail = Tools::getValue('msg_email'); + $toName = null; + $template = 'reply_msg'; + $title = Mail::l('An answer to your message is available', $ct->id_lang); + if ($customer->id) { + $headingText .= ' '.$customer->firstname.' '.$customer->lastname; + } + } + if (Mail::Send( - (int)$ct->id_lang, - 'reply_msg', - sprintf(Mail::l('An answer to your message is available #ct%1$s #tc%2$s', $ct->id_lang), $ct->id, $ct->token), - $params, Tools::getValue('msg_email'), null, $from_email, $from_name, $file_attachment, null, - _PS_MAIL_DIR_, true, $ct->id_shop) - ) { + (int) $idLang, + $template, + $title, + $params, + $toEmail, + $toName, + $from_email, + $from_name, + $file_attachment, + null, + _PS_MAIL_DIR_, + true, + $idShop + )) { if (Tools::isSubmit('submitReplyAndClose')) { $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED; + } else { + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; } $ct->update(); @@ -607,7 +676,10 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->errors[] = Tools::displayError('An error occurred. Your message was not sent. Please contact your system administrator.'); } } else if (Tools::isSubmit('submitReplyAsPrivate')) { - $ct = new CustomerThread($id_customer_thread); + if (!$ct->id_employee) { + $ct->id_employee = $this->context->employee->id; + $ct->update(); + } ShopUrl::cacheMainDomainForShop((int)$ct->id_shop); $cm = new CustomerMessage(); $cm->id_employee = (int)$this->context->employee->id; @@ -622,8 +694,6 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->errors[] = Tools::displayError('Some error occured while saving the message'); } } - - } return parent::postProcess(); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index e3d7a9050..c930d4ba9 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1424,6 +1424,10 @@ class AdminOrdersControllerCore extends AdminController $customer_thread = new CustomerThread(); $customer_thread->id_contact = 0; $customer_thread->id_customer = (int)$order->id_customer; + $customer_thread->user_name = $customer->firstname.' '.$customer->lastname; + $customer_thread->phone = $customer->phone; + $customer_thread->subject = $order->reference; + $customer_thread->id_employee = (int)$this->context->employee->id; $customer_thread->id_shop = (int)$this->context->shop->id; $customer_thread->id_order = (int)$order->id; $customer_thread->id_lang = (int)$this->context->language->id; @@ -1461,7 +1465,7 @@ class AdminOrdersControllerCore extends AdminController if (@Mail::Send( (int)$order->id_lang, 'order_merchant_comment', - Mail::l('New message regarding your order', (int)$order->id_lang), + Mail::l('New message regarding your booking', (int)$order->id_lang), $varsTpl, $customer->email, $customer->firstname.' '.$customer->lastname, diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index b3b863326..329e71233 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -118,11 +118,7 @@ class ContactControllerCore extends FrontController if ($contact->customer_service) { if ((int)$id_customer_thread) { $ct = new CustomerThread($id_customer_thread); - $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; - $ct->id_lang = (int)$this->context->language->id; - $ct->id_contact = (int)$id_contact; $ct->id_order = (int)$id_order; - $ct->update(); } else { $ct = new CustomerThread(); if (isset($customer->id)) { @@ -132,15 +128,15 @@ class ContactControllerCore extends FrontController $ct->phone = $phone; $ct->user_name = $userName; $ct->subject = $subject; - $ct->id_contact = (int)$id_contact; - $ct->id_lang = (int)$this->context->language->id; $ct->email = $from; - $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; $ct->token = Tools::passwdGen(12); - $ct->add(); } - if ($ct->id) { + $ct->status = CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN; + $ct->id_lang = (int)$this->context->language->id; + $ct->id_contact = (int)$id_contact; + + if ($ct->save()) { $cm = new CustomerMessage(); $cm->id_customer_thread = $ct->id; $cm->message = $message; @@ -163,15 +159,16 @@ class ContactControllerCore extends FrontController if (!count($this->errors)) { $var_list = array( - '{order_name}' => '-', - '{attached_file}' => '-', - '{message}' => Tools::nl2br(stripslashes($message)), - '{email}' => $from, - '{product_name}' => '', - ); + '{order_name}' => '-', + '{attached_file}' => ' ', + '{message}' => Tools::nl2br(stripslashes($message)), + '{email}' => $from, + '{product_name}' => '', + '{subject}' => $ct->subject, + ); if (isset($file_attachment['name'])) { - $var_list['{attached_file}'] = $file_attachment['name']; + $var_list['{attached_file}'] = ''.$this->l('Attached file').':'.$file_attachment['name']; } $id_product = (int)Tools::getValue('id_product'); @@ -253,9 +250,13 @@ class ContactControllerCore extends FrontController $email = Tools::safeOutput(Tools::getValue('from', ((isset($this->context->cookie) && isset($this->context->cookie->email) && Validate::isEmail($this->context->cookie->email)) ? $this->context->cookie->email : ''))); + $customerName = isset($this->context->customer) ? $this->context->customer->firstname.' '.$this->context->customer->lastname : ''; + $customerPhone = isset($this->context->customer) ? $this->context->customer->phone: ''; $this->context->smarty->assign(array( 'errors' => $this->errors, 'email' => $email, + 'customerName' => $customerName, + 'customerPhone' => $customerPhone, 'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD'), 'max_upload_size' => (int)Tools::getMaxUploadSize() )); @@ -315,7 +316,9 @@ class ContactControllerCore extends FrontController 'message' => html_entity_decode(Tools::getValue('message')), 'contactKey' => $contactKey, 'contactNameRequired' => Configuration::get('PS_CUSTOMER_SERVICE_NAME_REQUIRED'), + 'displayContactName' => Configuration::get('PS_CUSTOMER_SERVICE_NAME_DISPLAY'), 'contactPhoneRequired' => Configuration::get('PS_CUSTOMER_SERVICE_PHONE_REQUIRED'), + 'displayContactPhone' => Configuration::get('PS_CUSTOMER_SERVICE_PHONE_DISPLAY'), 'allowContactSelection' => Configuration::get('PS_CUSTOMER_SERVICE_CONTACT_ALLOW') ) ); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 892273c29..80e9a335d 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -460,7 +460,7 @@ class OrderDetailControllerCore extends FrontController 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state) ? new State($addressDelivery->id_state) : false, 'is_guest' => false, - 'messages' => CustomerMessage::getMessagesByOrderId((int) $order->id, false), + 'messages' => CustomerMessage::getMessagesByOrderId((int) $order->id), 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), @@ -690,10 +690,14 @@ class OrderDetailControllerCore extends FrontController $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($this->context->customer->email, $order->id); $id_product = (int)Tools::getValue('id_product'); $cm = new CustomerMessage(); + $objCustomer = new Customer($order->id_customer); if (!$id_customer_thread) { $ct = new CustomerThread(); $ct->id_contact = 0; $ct->id_customer = (int)$order->id_customer; + $ct->user_name = $objCustomer->firstname.' '.$objCustomer->lastname; + $ct->subject = $order->reference; + $ct->phone = $objCustomer->phone; $ct->id_shop = (int)$this->context->shop->id; $ct->id_order = (int)$order->id; $ct->id_lang = (int)$this->context->language->id; @@ -763,7 +767,7 @@ class OrderDetailControllerCore extends FrontController // send message html in json $response['status'] = true; - $message = CustomerMessage::getMessagesByOrderId($order->id, false)[0]; + $message = CustomerMessage::getMessagesByOrderId($order->id)[0]; $this->context->smarty->assign(array('message' => $message)); $response['message_html'] = $this->context->smarty->fetch(_PS_THEME_DIR_.'_partials/order-message.tpl'); } else { diff --git a/install/data/db_structure.sql b/install/data/db_structure.sql index 5f1457ee9..6f6769302 100644 --- a/install/data/db_structure.sql +++ b/install/data/db_structure.sql @@ -658,6 +658,7 @@ CREATE TABLE `PREFIX_customer_thread` ( `id_lang` int(10) unsigned NOT NULL, `id_contact` int(10) unsigned NOT NULL, `id_customer` int(10) unsigned DEFAULT NULL, + `id_employee` int(10) unsigned DEFAULT NULL, `id_order` int(10) unsigned DEFAULT NULL, `user_name` VARCHAR(128) DEFAULT NULL, `phone` VARCHAR(32) DEFAULT NULL, diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index e111894ed..2696980f6 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -952,9 +952,15 @@ 1 + + + 1 1 + + + 1 1 diff --git a/js/admin/customer_thread.js b/js/admin/customer_thread.js index bee35d067..94aeea291 100644 --- a/js/admin/customer_thread.js +++ b/js/admin/customer_thread.js @@ -22,6 +22,14 @@ $(document).ready(function() { $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').hide(); } + if ($('#PS_CUSTOMER_SERVICE_NAME_REQUIRED_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_NAME_DISPLAY"]').closest('.form-group').hide(); + } + + if ($('#PS_CUSTOMER_SERVICE_PHONE_REQUIRED_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_PHONE_DISPLAY"]').closest('.form-group').hide(); + } + $(document).on('change', '[name="PS_CUSTOMER_SERVICE_CONTACT_ALLOW"]', function() { if ($('#PS_CUSTOMER_SERVICE_CONTACT_ALLOW_on').prop('checked')) { $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').hide(); @@ -29,4 +37,23 @@ $(document).ready(function() { $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').show(); } }); + + $(document).on('change', '[name="PS_CUSTOMER_SERVICE_NAME_REQUIRED"]', function() { + if ($('#PS_CUSTOMER_SERVICE_NAME_REQUIRED_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_NAME_DISPLAY"]').closest('.form-group').hide(); + $('#PS_CUSTOMER_SERVICE_NAME_DISPLAY_on').prop('checked', true); + } else { + $('[name="PS_CUSTOMER_SERVICE_NAME_DISPLAY"]').closest('.form-group').show(); + } + }); + + $(document).on('change', '[name="PS_CUSTOMER_SERVICE_PHONE_REQUIRED"]', function() { + if ($('#PS_CUSTOMER_SERVICE_PHONE_REQUIRED_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_PHONE_DISPLAY"]').closest('.form-group').hide(); + $('#PS_CUSTOMER_SERVICE_PHONE_DISPLAY_on').prop('checked', true); + } else { + $('[name="PS_CUSTOMER_SERVICE_PHONE_DISPLAY"]').closest('.form-group').show(); + } + }); + }); diff --git a/mails/en/contact.html b/mails/en/contact.html index 3ebbf35d5..c9c93ad62 100644 --- a/mails/en/contact.html +++ b/mails/en/contact.html @@ -86,6 +86,7 @@ Customer e-mail address:
{email}

+ Title: {subject}

Customer message: {message}

Attached file: {attached_file} diff --git a/mails/en/contact.txt b/mails/en/contact.txt index 152a1581c..ccd9a4132 100644 --- a/mails/en/contact.txt +++ b/mails/en/contact.txt @@ -1,16 +1,16 @@ -[/{shop_url}] +[/{shop_url}] -Message from a {shop_name} customer +Message from a {shop_name} customer CUSTOMER E-MAIL ADDRESS: {email} +TITLE : {subject} + CUSTOMER MESSAGE: {message} -ORDER ID: {order_name} - -ATTACHED FILE: {attached_file} +ATTACHED FILE: {attached_file} {shop_name} [/{shop_url}] powered by Webkul(tm) -[https://webkul.com] +[https://webkul.com] diff --git a/mails/en/order_customer_comment.html b/mails/en/order_customer_comment.html index 83cb0223e..42df13834 100644 --- a/mails/en/order_customer_comment.html +++ b/mails/en/order_customer_comment.html @@ -4,51 +4,51 @@ Message from {shop_name} - - - @@ -87,7 +87,7 @@

Message from a customer

- You have received a new message regarding order with the reference {order_name}.

+ You have received a new message regarding booking with the reference {order_name}.

Customer: {firstname} {lastname} ({email})

{message}
diff --git a/mails/en/order_customer_comment.txt b/mails/en/order_customer_comment.txt index d5055db73..2c2e715b1 100644 --- a/mails/en/order_customer_comment.txt +++ b/mails/en/order_customer_comment.txt @@ -1,15 +1,15 @@ -[/{shop_url}] +[/{shop_url}] -Hi {firstname} {lastname}, +Hi {firstname} {lastname}, -You have received a new message regarding order with the reference +You have received a new message regarding booking with the reference {order_name}. CUSTOMER: {firstname} {lastname} ({email}) -{message} +{message} {shop_name} [/{shop_url}] powered by Webkul(tm) -[https://webkul.com] +[https://webkul.com] diff --git a/mails/en/reply_msg.html b/mails/en/reply_msg.html index c71767da6..98616b76a 100644 --- a/mails/en/reply_msg.html +++ b/mails/en/reply_msg.html @@ -71,6 +71,11 @@ {headingtext} + + + Title: {subject} + +   diff --git a/mails/en/reply_msg.txt b/mails/en/reply_msg.txt index c654fa2df..0953fc4e9 100644 --- a/mails/en/reply_msg.txt +++ b/mails/en/reply_msg.txt @@ -3,6 +3,8 @@ {headingtext}, +{subject} + {reply} Please do not reply directly to this email, we will not receive it. diff --git a/themes/hotel-reservation-theme/contact-form.tpl b/themes/hotel-reservation-theme/contact-form.tpl index 63fd52fa9..62ee452f5 100644 --- a/themes/hotel-reservation-theme/contact-form.tpl +++ b/themes/hotel-reservation-theme/contact-form.tpl @@ -75,14 +75,16 @@ {else} {/if} + {if isset($displayContactName) && $displayContactName}
- +
+ {/if}
+ {if isset($displayContactPhone) && $displayContactPhone}
- +
+ {/if}
@@ -150,9 +154,6 @@
-
- {l s='* Required fields'} -
{if $fileupload == 1}
@@ -164,6 +165,9 @@
{/if} +
+ {l s='* Required fields'} +
{hook h='displayGDPRConsent' moduleName='contactform'} {hook h='displayContactFormFieldsAfter'}
From 66f3f850680987e9b310032798a1cad5fd106981 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 16 May 2025 12:22:41 +0530 Subject: [PATCH 06/13] Fixed some text related issues, and added order wise restriction on the stats --- .../customers/helpers/view/view.tpl | 15 ++++++++--- classes/CustomerMessage.php | 27 ++++++++++--------- classes/CustomerThread.php | 25 ++++++++--------- .../admin/AdminCustomerThreadsController.php | 15 ++++++----- controllers/admin/AdminOrdersController.php | 4 ++- controllers/admin/AdminStatsController.php | 25 ++++++++++++++--- controllers/front/ContactController.php | 8 +++--- 7 files changed, 77 insertions(+), 42 deletions(-) diff --git a/admin/themes/default/template/controllers/customers/helpers/view/view.tpl b/admin/themes/default/template/controllers/customers/helpers/view/view.tpl index 8213ed88d..26684cbd3 100644 --- a/admin/themes/default/template/controllers/customers/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/customers/helpers/view/view.tpl @@ -501,13 +501,22 @@ {if count($messages)} - + - + {foreach $messages AS $message} - + - - - - - - - - - - - + + + + + + + + + diff --git a/mails/en/contact.txt b/mails/en/contact.txt index ccd9a4132..6744c4958 100644 --- a/mails/en/contact.txt +++ b/mails/en/contact.txt @@ -3,13 +3,7 @@ Message from a {shop_name} customer -CUSTOMER E-MAIL ADDRESS: {email} - -TITLE : {subject} - -CUSTOMER MESSAGE: {message} - -ATTACHED FILE: {attached_file} +{contact_content_txt} {shop_name} [/{shop_url}] powered by Webkul(tm) [https://webkul.com] diff --git a/mails/en/contact_content_html.tpl b/mails/en/contact_content_html.tpl new file mode 100644 index 000000000..ad318937f --- /dev/null +++ b/mails/en/contact_content_html.tpl @@ -0,0 +1,15 @@ +{if isset($user_name) && $user_name} +Name: {$user_name}

+{/if} +{if isset($email) && $email} +E-mail: {$email}

+{/if} +{if isset($subject) && $subject} +Title: {$subject}

+{/if} +{if isset($message) && $message} +Customer message:
{$message}

+{/if} +{if isset($attached_file) && $attached_file} +Attached file: {$attached_file} +{/if} diff --git a/mails/en/contact_content_txt.tpl b/mails/en/contact_content_txt.tpl new file mode 100644 index 000000000..ea7b435cf --- /dev/null +++ b/mails/en/contact_content_txt.tpl @@ -0,0 +1,18 @@ + +{if isset($user_name) && $user_name} + Name: {$user_name} +{/if} +{if isset($email) && $email} + E-mail: {$email} +{/if} +{if isset($subject) && $subject} + Title: {$subject} +{/if} + +{if isset($message) && $message} + Customer message:
{$message}

+{/if} +{if isset($attached_file) && $attached_file} + Attached file: {$attached_file} +{/if} + diff --git a/mails/en/order_customer_comment.html b/mails/en/order_customer_comment.html index 42df13834..6dd6fedcf 100644 --- a/mails/en/order_customer_comment.html +++ b/mails/en/order_customer_comment.html @@ -66,39 +66,36 @@ - - - - - - - - - - - + + + + + + + + + diff --git a/mails/en/order_customer_comment.txt b/mails/en/order_customer_comment.txt index 2c2e715b1..e119eb1c9 100644 --- a/mails/en/order_customer_comment.txt +++ b/mails/en/order_customer_comment.txt @@ -6,8 +6,11 @@ Hi {firstname} {lastname}, You have received a new message regarding booking with the reference {order_name}. -CUSTOMER: {firstname} {lastname} ({email}) +NAME: {firstname} {lastname} +E-mail: {email} + +Customer message: {message} {shop_name} [/{shop_url}] powered by Webkul(tm) diff --git a/mails/en/order_merchant_comment.html b/mails/en/order_merchant_comment.html index 941533196..4cbc9d7b8 100644 --- a/mails/en/order_merchant_comment.html +++ b/mails/en/order_merchant_comment.html @@ -4,51 +4,51 @@ Message from {shop_name} - - - @@ -66,38 +66,37 @@ - - - - - - - - - - - + + + + + + + + + diff --git a/mails/en/order_merchant_comment.txt b/mails/en/order_merchant_comment.txt index e1c404f3e..ee62c23f0 100644 --- a/mails/en/order_merchant_comment.txt +++ b/mails/en/order_merchant_comment.txt @@ -1,13 +1,14 @@ -[/{shop_url}] +[/{shop_url}] -Hi {firstname} {lastname}, +Hi {firstname} {lastname}, -You have received a new message from {shop_name} regarding order with +You have received a new message from {shop_name} regarding booking with the reference {order_name}. -MESSAGE: {message} +MESSAGE: +{message} {shop_name} [/{shop_url}] powered by Webkul(tm) -[https://webkul.com] +[https://webkul.com] diff --git a/mails/en/reply_msg.html b/mails/en/reply_msg.html index 98616b76a..7eafe00e4 100644 --- a/mails/en/reply_msg.html +++ b/mails/en/reply_msg.html @@ -71,29 +71,29 @@ {headingtext} - - - - - - - - - - - diff --git a/mails/en/reply_msg.txt b/mails/en/reply_msg.txt index 0953fc4e9..475f41d4d 100644 --- a/mails/en/reply_msg.txt +++ b/mails/en/reply_msg.txt @@ -3,8 +3,9 @@ {headingtext}, -{subject} +Title: {subject} +Message: {reply} Please do not reply directly to this email, we will not receive it. From a612740c16963df9cb87077314a5df107b1c3b8e Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 21 May 2025 15:31:23 +0530 Subject: [PATCH 10/13] removed non required permission related code --- controllers/admin/AdminCartsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 3b6bfc157..557fca655 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -590,7 +590,7 @@ class AdminCartsControllerCore extends AdminController public function ajaxProcessUpdateOrderMessage() { - if ($this->tabAccess['edit'] === '1' || $this->tabAccess['add'] === '1') { + if ($this->tabAccess['edit'] === '1') { $id_message = false; if ($old_message = Message::getMessageByCartId((int)$this->context->cart->id)) { $id_message = $old_message['id_message']; From 141f1c49cf451fedaf8606fe38ee8fa2b98d323b Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 21 May 2025 16:16:53 +0530 Subject: [PATCH 11/13] Added tootip for the KPIs and updated titles --- controllers/admin/AdminCustomerThreadsController.php | 11 ++++++++++- controllers/admin/AdminStatsController.php | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 9a0b9f397..fed00a41c 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -729,11 +729,13 @@ class AdminCustomerThreadsControllerCore extends AdminController $all = CustomerThread::getTotalCustomerThreads(); $pending = (int)AdminStatsController::getPendingMessages(); $open = CustomerThread::getTotalCustomerThreads('status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN); + $helper = new HelperKpi(); $helper->id = 'box-messages'; $helper->icon = 'icon-envelope'; $helper->color = 'color1'; $helper->title = $this->l('Total threads'); + $helper->tooltip = $this->l('Total number of threads.'); $helper->value = $all; $this->kpis[] = $helper; @@ -743,6 +745,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper->color = 'color2'; $helper->title = $this->l('Threads pending', null, null, false); $helper->value = $pending + $open; + $helper->tooltip = $this->l('Total number of threads having "open", "pending 1" and "pending 2" statuses.'); $this->kpis[] = $helper; $helper = new HelperKpi(); @@ -750,6 +753,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper->icon = 'icon-time'; $helper->color = 'color3'; $helper->title = $this->l('Average Response Time', null, null, false); + $helper->tooltip = $this->l('The average response time.'); $helper->subtitle = $this->l('30 days', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=avg_msg_response_time'; $this->kpis[] = $helper; @@ -758,8 +762,9 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper->id = 'box-messages-per-thread'; $helper->icon = 'icon-copy'; $helper->color = 'color4'; - $helper->title = $this->l('Messages per Thread', null, null, false); + $helper->title = $this->l('Average Messages per Thread', null, null, false); $helper->subtitle = $this->l('30 day', null, null, false); + $helper->tooltip = $this->l('The average number of messages in each thread.'); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=messages_per_thread'; $this->kpis[] = $helper; @@ -768,6 +773,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper->icon = 'icon-envelope'; $helper->color = 'color1'; $helper->title = $this->l('Customer messages', null, null, false); + $helper->tooltip = $this->l('Total number of messages sent by customers.'); $helper->value = (int) CustomerMessage::getTotalCustomerMessages('cm.`id_employee` = 0'); $this->kpis[] = $helper; @@ -776,6 +782,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper->icon = 'icon-envelope'; $helper->color = 'color4'; $helper->title = $this->l('Employee messages', null, null, false); + $helper->tooltip = $this->l('Total number of messages sent by employees.'); $helper->value = (int) CustomerMessage::getTotalCustomerMessages('cm.`id_employee` != 0'); $this->kpis[] = $helper; @@ -785,6 +792,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper->icon = 'icon-envelope'; $helper->color = 'color2'; $helper->title = $this->l('Unread threads', null, null, false); + $helper->tooltip = $this->l('Total number of messages having open status.'); $helper->value = (int) $open; $this->kpis[] = $helper; @@ -794,6 +802,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper->color = 'color1'; $helper->title = $this->l('Closed threads', null, null, false); $helper->value = (int) ($all - ($open + $pending)); + $helper->tooltip = $this->l('Total number of messages having closed status.'); $this->kpis[] = $helper; return parent::renderKpis(); diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 5864228a7..0c0b5d5b0 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -479,7 +479,6 @@ class AdminStatsControllerCore extends AdminStatsTabController LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON (ct.id_customer_thread = cm.id_customer_thread) WHERE ct.`date_add` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" '.Shop::addSqlRestriction().$accessWhere.' - AND status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED.' GROUP BY ct.id_customer_thread'); $threads = $messages = 0; foreach ($result as $row) { From 1341db1ae4b7cbed8f16557496e2526cb91ad804 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 21 May 2025 19:54:14 +0530 Subject: [PATCH 12/13] Updated the list header, and updated the KPIs --- .../helpers/list/list_header.tpl | 54 +-- .../template/helpers/list/list_header.tpl | 414 +++++++++--------- .../admin/AdminCustomerThreadsController.php | 38 +- 3 files changed, 253 insertions(+), 253 deletions(-) diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl index de58eaab0..e53c819f7 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl @@ -25,49 +25,19 @@ {extends file="helpers/list/list_header.tpl"} -{block name="leadin"} -
- {assign var=nb_categories value=count($categories)} - {foreach $categories as $key => $val} - - {assign var=total_thread value=0} - {assign var=id_customer_thread value=0} - - {foreach $contacts as $tmp => $tmp2} - {if $val.id_contact == $tmp2.id_contact} - {assign var=total_thread value=$tmp2.total} - {assign var=id_customer_thread value=$tmp2.id_customer_thread} - {/if} - {/foreach} -
-
-
- {$val.name} -
- {if $nb_categories < 6} -

{$val.description}

- {/if} - {if $total_thread == 0} - {l s='No new messages'} - {else} - - {$total_thread} - {if $total_thread > 1}{l s='New messages'}{else}{l s='New message'}{/if} - - {/if} -
-
- {/foreach} -
-
-
- {l s='Meaning of status'} -
+{block name="list_action_filter_fields" append} +
+
+ +
diff --git a/admin/themes/default/template/helpers/list/list_header.tpl b/admin/themes/default/template/helpers/list/list_header.tpl index 7f9266286..6b20667e5 100644 --- a/admin/themes/default/template/helpers/list/list_header.tpl +++ b/admin/themes/default/template/helpers/list/list_header.tpl @@ -194,237 +194,245 @@ {block name="updatelist"} {if $new_list_header_design} -
-
- {if $fields_optional|count} -
-
- - -
-
- {/if} - {if !$simple_header && $show_filters} -
-
- -
-
- {/if} -
-
-
- {if $filters_has_value} -
- {l s='Filters: '} - - {foreach $fields_display AS $key => $params} - {if (!isset($params.search) || $params.search) && $params.value != ''} - {if ($params.type == 'date' || $params.type == 'datetime' || $params.type == 'range') && $params.value|is_array} - {assign var="filter_value" value=''} - {foreach $params.value as $value} - {if (isset($value) && ($value !== '' || $value === 0))} - {if !(isset($filter_value) && ($filter_value !== '' || $filter_value === 0))} - {assign var="filter_value" value=$value} - {else} - {assign var="filter_value" value="`$filter_value` - `$value`"} - {/if} - {/if} + {block name="list_action_wrapper"} +
+ {block name="list_action_buttons"} +
+ {block name="list_action_optional_fields"} + {if $fields_optional|count} +
+
+ + +
+
+ {/if} + {/block} + {block name="list_action_filter_fields"} + {if !$simple_header && $show_filters} +
+
+ +
+
+ {/if} + {/block} +
+ {/block} +
+
+ {if $filters_has_value} +
+ {l s='Filters: '} + + {foreach $fields_display AS $key => $params} + {if (!isset($params.search) || $params.search) && $params.value != ''} + {if ($params.type == 'date' || $params.type == 'datetime' || $params.type == 'range') && $params.value|is_array} + {assign var="filter_value" value=''} + {foreach $params.value as $value} + {if (isset($value) && ($value !== '' || $value === 0))} + {if !(isset($filter_value) && ($filter_value !== '' || $filter_value === 0))} + {assign var="filter_value" value=$value} + {else} + {assign var="filter_value" value="`$filter_value` - `$value`"} + {/if} + {/if} + {/foreach} + {if (isset($filter_value) && ($filter_value !== '' || $filter_value === 0))} + + {$params['title']|escape:'html':'UTF-8'}: {$filter_value|escape:'html':'UTF-8'} + + {/if} + {elseif $params.type == 'select'} + {if isset($params.multiple) && $params.multiple} + + {$params['title']|escape:'html':'UTF-8'}: + + {foreach from=$params.value item=option name=foreachInfo} + {$params.list[$option]}{if !$smarty.foreach.foreachInfo.last}{if $params.operator == 'or'} | {else}, {/if}{/if} + {/foreach} + + + + {else} + + {$params['title']|escape:'html':'UTF-8'}: {$params['list'][$params['value']]|replace: ' ' : ''} + + + {/if} + {elseif $params.type == 'bool'} + + {$params['title']|escape:'html':'UTF-8'}: {if $params['value'] == 1}{l s='Yes'}{else}{l s='No'}{/if} {else} - {$params['title']|escape:'html':'UTF-8'}: {$params['list'][$params['value']]|replace: ' ' : ''} + {$params['title']|escape:'html':'UTF-8'}: {$params['value']|escape:'html':'UTF-8'} {/if} - {elseif $params.type == 'bool'} - - {$params['title']|escape:'html':'UTF-8'}: {if $params['value'] == 1}{l s='Yes'}{else}{l s='No'}{/if} - - - {else} - - {$params['title']|escape:'html':'UTF-8'}: {$params['value']|escape:'html':'UTF-8'} - - {/if} - {/if} - {/foreach} - -
- {/if} -
-
-
-
- {foreach $fields_display AS $key => $params} - {if !isset($params.search) || $params.search} -
- -
- {if $params.type == 'range'} - {$field_name="`$list_id`Filter_{if isset($params.filter_key)}`$params.filter_key`{else}`$key`{/if}"} -
- - -
- {elseif $params.type == 'bool'} - {$field_name="`$list_id`Filter_{if isset($params.filter_key)}`$params.filter_key`{else}`$key`{/if}"} - - {elseif $params.type == 'date' || $params.type == 'datetime'} -
-
- - - - - + {/foreach} + +
+ {/if} +
+
+
+
+ {foreach $fields_display AS $key => $params} + {if !isset($params.search) || $params.search} +
+ +
+ {if $params.type == 'range'} + {$field_name="`$list_id`Filter_{if isset($params.filter_key)}`$params.filter_key`{else}`$key`{/if}"} +
+ +
-
- - - - - -
- -
- {elseif $params.type == 'select'} - {$field_name="`$list_id`Filter_`$params.filter_key`"} - {if isset($params.multiple) && $params.multiple} - + + + - {else} - {if isset($params.filter_key)} - + + + + +
+
+ + + + + +
+ +
+ {elseif $params.type == 'select'} + {$field_name="`$list_id`Filter_`$params.filter_key`"} + {if isset($params.multiple) && $params.multiple} + + {else} + {if isset($params.filter_key)} + + {/if} {/if} + {else} + {$field_name="`$list_id`Filter_{if isset($params.filter_key)}`$params.filter_key`{else}`$key`{/if}"} + {/if} - {else} - {$field_name="`$list_id`Filter_{if isset($params.filter_key)}`$params.filter_key`{else}`$key`{/if}"} - - {/if} +
+ {/if} + {/foreach} + {if $has_actions || $show_filters} +
+
+ {if $show_filters} + + + {if $filters_has_value} + + {/if} + + {/if}
{/if} - {/foreach} - {if $has_actions || $show_filters} -
-
- {if $show_filters} - - - {if $filters_has_value} - - {/if} - - {/if} -
- {/if} +
-
+ {/block} {/if} {/block}
diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index fed00a41c..4d120c055 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -393,13 +393,6 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->_orderBy = 'id_customer_thread'; $this->_orderWay = 'DESC'; - $contacts = CustomerThread::getContacts(); - $categories = Contact::getCategoriesContacts(); - $this->tpl_list_vars = array( - 'contacts' => $contacts, - 'categories' => $categories, - ); - return parent::renderList(); } @@ -799,12 +792,41 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper = new HelperKpi(); $helper->id = 'box-pending-messages'; $helper->icon = 'icon-envelope'; - $helper->color = 'color1'; + $helper->color = 'color3'; $helper->title = $this->l('Closed threads', null, null, false); $helper->value = (int) ($all - ($open + $pending)); $helper->tooltip = $this->l('Total number of messages having closed status.'); $this->kpis[] = $helper; + $contacts = CustomerThread::getContacts(); + $categories = Contact::getCategoriesContacts(); + if ($contacts) { + $contacts = array_column($contacts, null, 'id_contact'); + } + + if ($categories) { + foreach ($categories as $idContact => $category) { + $helper = new HelperKpi(); + $helper->id = 'box-pending-messages'; + $helper->icon = 'icon-envelope'; + $helper->color = 'color'.(($idContact+1)%3 ? ($idContact+1)%3 : '4'); + $helper->title = $category['name']; + if (isset($contacts[$category['id_contact']])) { + $helper->href = self::$currentIndex.'&token='.$this->token.'&id_customer_thread='.$contacts[$category['id_contact']]['id_customer_thread'].'&viewcustomer_thread'; + if ($contacts[$category['id_contact']]['total'] > 1) { + $helper->value = $contacts[$category['id_contact']]['total'].' '.$this->l('New messages'); + } else { + $helper->value = $contacts[$category['id_contact']]['total'].' '.$this->l('New message'); + } + } else { + $helper->value = $this->l('No new messages'); + } + + $helper->tooltip = $this->l('Total number of messages sent to').' '.$category['name']; + $this->kpis[] = $helper; + } + } + return parent::renderKpis(); } From e919eb9a66f17efb4cdd08e82e67f899ad1d6b41 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 21 May 2025 20:09:53 +0530 Subject: [PATCH 13/13] updated the list header block name --- .../helpers/list/list_header.tpl | 2 +- .../template/helpers/list/list_header.tpl | 68 +++++++++---------- 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl index e53c819f7..9dfd074b7 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl @@ -25,7 +25,7 @@ {extends file="helpers/list/list_header.tpl"} -{block name="list_action_filter_fields" append} +{block name="list_filter_items" append}
- -
+
+ {block name="list_filter_items"} + {if $fields_optional|count} +
+
+ +
- {/if} - {/block} - {block name="list_action_filter_fields"} - {if !$simple_header && $show_filters} -
-
- -
+
+ {/if} + {if !$simple_header && $show_filters} +
+
+
- {/if} - {/block} -
- {/block} +
+ {/if} + {/block} +
{if $filters_has_value}
{l s='Status'}{l s='Status'} {l s='Message'}{l s='Sent on'}{l s='Sent on'}
{$message['status']}{if $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN} + {l s='Open'} + {elseif $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED} + {l s='Closed'} + {elseif $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1} + {l s='Pending 1'} + {elseif $message['status'] == CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2} + {l s='Pending 2'} + {/if} + {$message['message']}... diff --git a/classes/CustomerMessage.php b/classes/CustomerMessage.php index abc6df3ef..21798c993 100644 --- a/classes/CustomerMessage.php +++ b/classes/CustomerMessage.php @@ -100,21 +100,24 @@ class CustomerMessageCore extends ObjectModel public static function getTotalCustomerMessages($where = null) { + $sql = 'SELECT COUNT(*) + FROM '._DB_PREFIX_.'customer_message cm + LEFT JOIN `'._DB_PREFIX_.'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`) '; if (is_null($where)) { - return (int)Db::getInstance()->getValue(' - SELECT COUNT(*) - FROM '._DB_PREFIX_.'customer_message - LEFT JOIN `'._DB_PREFIX_.'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`) - WHERE 1'.Shop::addSqlRestriction() - ); - } else { - return (int)Db::getInstance()->getValue(' - SELECT COUNT(*) - FROM '._DB_PREFIX_.'customer_message cm - LEFT JOIN `'._DB_PREFIX_.'customer_thread` ct ON (cm.`id_customer_thread` = ct.`id_customer_thread`) - WHERE '.$where.Shop::addSqlRestriction() + $where = ' 1 '; + } + + $employee = Context::getContext()->employee; + if (!$employee->isSuperAdmin()) { + $where .= (($acsHtls = HotelBranchInformation::getProfileAccessedHotels($employee->id_profile, 1, 1)) ? + ' AND ct.`id_order` IN (SELECT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE `id_hotel` IN ('.implode(',', $acsHtls).')) ' : + ' AND ct.`id_order` = 0 ' ); } + + return (int)Db::getInstance()->getValue( + $sql.' WHERE '.$where.Shop::addSqlRestriction() + ); } public function delete() diff --git a/classes/CustomerThread.php b/classes/CustomerThread.php index 04fb60851..e692dd724 100644 --- a/classes/CustomerThread.php +++ b/classes/CustomerThread.php @@ -210,7 +210,8 @@ class CustomerThreadCore extends ObjectModel SELECT cl.*, COUNT(*) as total, ( SELECT id_customer_thread FROM '._DB_PREFIX_.'customer_thread ct2 - WHERE status = "open" AND ct.id_contact = ct2.id_contact + WHERE status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.' + AND ct.id_contact = ct2.id_contact '.Shop::addSqlRestriction().' ORDER BY date_upd ASC LIMIT 1 @@ -218,7 +219,7 @@ class CustomerThreadCore extends ObjectModel FROM '._DB_PREFIX_.'customer_thread ct LEFT JOIN '._DB_PREFIX_.'contact_lang cl ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)Context::getContext()->language->id.') - WHERE ct.status = "open" + WHERE ct.status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN.' AND ct.id_contact IS NOT NULL AND cl.id_contact IS NOT NULL '.Shop::addSqlRestriction().' @@ -228,19 +229,19 @@ class CustomerThreadCore extends ObjectModel public static function getTotalCustomerThreads($where = null) { + $sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'customer_thread '; if (is_null($where)) { - return (int)Db::getInstance()->getValue(' - SELECT COUNT(*) - FROM '._DB_PREFIX_.'customer_thread - WHERE 1 '.Shop::addSqlRestriction() - ); - } else { - return (int)Db::getInstance()->getValue(' - SELECT COUNT(*) - FROM '._DB_PREFIX_.'customer_thread - WHERE '.$where.Shop::addSqlRestriction() + $where = ' 1 '; + } + + $employee = Context::getContext()->employee; + if (!$employee->isSuperAdmin()) { + $where .= (($acsHtls = HotelBranchInformation::getProfileAccessedHotels($employee->id_profile, 1, 1)) ? + ' AND `id_order` IN (SELECT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE `id_hotel` IN ('.implode(',', $acsHtls).')) ' : + ' AND `id_order` = 0 ' ); } + return (int)Db::getInstance()->getValue($sql.' WHERE '.$where.Shop::addSqlRestriction()); } public static function getMessageCustomerThreads($id_customer_thread) diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 7f2940ec1..21c6db2a1 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -107,7 +107,7 @@ class AdminCustomerThreadsControllerCore extends AdminController 'visible_default' => true, ), 'contact' => array( - 'title' => $this->l('Type'), + 'title' => $this->l('Contact'), 'type' => 'select', 'list' => $contact_array, 'filter_key' => 'cl!id_contact', @@ -143,6 +143,7 @@ class AdminCustomerThreadsControllerCore extends AdminController 'filter_key' => 'employee', 'tmpTableFilter' => true, 'optional' => true, + 'hint' => $this->l('The first employee to reply becomes responsible. They can then forward the message to another employee if needed.') ), 'last_employee' => array( 'title' => $this->l('Last Reply by'), @@ -397,17 +398,17 @@ class AdminCustomerThreadsControllerCore extends AdminController array( 'title' => $this->l('Threads pending'), 'val' => $pending = CustomerThread::getTotalCustomerThreads( - 'status='.(int) CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1.' - OR status='.(int) CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2 + 'status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1.' + OR status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2 ), ), array( 'title' => $this->l('Total number of customer messages'), - 'val' => CustomerMessage::getTotalCustomerMessages('ct.`id_employee` = 0'), + 'val' => CustomerMessage::getTotalCustomerMessages('cm.`id_employee` = 0'), ), array( 'title' => $this->l('Total number of employee messages'), - 'val' => CustomerMessage::getTotalCustomerMessages('ct.`id_employee` != 0'), + 'val' => CustomerMessage::getTotalCustomerMessages('cm.`id_employee` != 0'), ), array( 'title' => $this->l('Unread threads'), @@ -625,7 +626,7 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->context->link->getPageLink('contact', true, (int)$ct->id_lang, null, false, $ct->id_shop), 'token='.$ct->token ); - $headingText = $this->l('Hi'); + $headingText = $this->l('Hi') .' '.$ct->user_name; $idShop = $ct->id_shop; $params = array( '{reply}' => Tools::nl2br(Tools::getValue('reply_message')), @@ -633,7 +634,7 @@ class AdminCustomerThreadsControllerCore extends AdminController '{headingtext}' => $headingText, ); if (!empty(trim($ct->subject))) { - $params['{subject}'] = $this->l('Title : ').$ct->subject; + $params['{subject}'] = $ct->subject; } $idLang = $ct->id_lang; diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 28c8001d9..e3f5be859 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -2490,13 +2490,15 @@ class AdminOrdersControllerCore extends AdminController $helper->value = $objOrder->source; $this->kpis[] = $helper; + $objCustomerThread = new CustomerThread(); + $idCustomerThread = $objCustomerThread->getIdCustomerThreadByIdOrder($objOrder->id); $helper = new HelperKpi(); $helper->id = 'box-messages'; $helper->icon = 'icon-comments'; $helper->color = 'color2'; $helper->title = $this->l('Messages'); $helper->tooltip = $this->l('Messages is the number of customer messages for this order.'); - $helper->href = $this->context->link->getAdminLink('AdminCustomerThreads').'&id_order='.$objOrder->id; + $helper->href = $this->context->link->getAdminLink('AdminCustomerThreads').((int) $idCustomerThread ? '&viewcustomer_thread&id_customer_thread='.(int) $idCustomerThread : ''); $helper->value = count(CustomerThread::getCustomerMessages($objOrder->id_customer, null, $objOrder->id, CustomerMessage::QLO_CUSTOMER_MESSAGE_BY_CUSTOMER)); $this->kpis[] = $helper; diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index ea6bbb299..47f48394b 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -424,7 +424,15 @@ class AdminStatsControllerCore extends AdminStatsTabController public static function getPendingMessages() { - return CustomerThread::getTotalCustomerThreads('status LIKE "%pending%" OR status = "open"'.Shop::addSqlRestriction()); + $pendingStatuses = array( + CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN, + CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2, + CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1 + ); + + return CustomerThread::getTotalCustomerThreads( + '`status` IN ('.implode(',', $pendingStatuses).')'.Shop::addSqlRestriction() + ); } public static function getAverageMessageResponseTime($date_from, $date_to, $return_seconds = false) @@ -455,13 +463,24 @@ class AdminStatsControllerCore extends AdminStatsTabController public static function getMessagesPerThread($date_from, $date_to) { + $accessWhere = ''; + $employee = Context::getContext()->employee; + if (!$employee->isSuperAdmin()) { + $idProfile = $employee->id_profile; + if ($acsHtls = HotelBranchInformation::getProfileAccessedHotels($idProfile, 1, 1)) { + $accessWhere = ' AND ct.`id_order` IN (SELECT `id_order` FROM `'._DB_PREFIX_.'htl_booking_detail` hbd WHERE `id_hotel` IN ('.implode(',', $acsHtls).'))'; + } else { + $accessWhere = ' AND ct.`id_order` = 0 '; + } + } + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT COUNT(*) as messages FROM `'._DB_PREFIX_.'customer_thread` ct LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON (ct.id_customer_thread = cm.id_customer_thread) WHERE ct.`date_add` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59" - '.Shop::addSqlRestriction().' - AND status = "closed" + '.Shop::addSqlRestriction().$accessWhere.' + AND status = '.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_CLOSED.' GROUP BY ct.id_customer_thread'); $threads = $messages = 0; foreach ($result as $row) { diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 329e71233..972aefd0c 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -60,7 +60,7 @@ class ContactControllerCore extends FrontController } elseif (!Validate::isCleanHtml($message)) { $this->errors[] = Tools::displayError('Invalid message'); } elseif (!$id_customer_thread && !$subject) { - $this->errors[] = Tools::displayError('The subject cannot be blank.'); + $this->errors[] = Tools::displayError('The title cannot be blank.'); } elseif (!$id_customer_thread && !Validate::isCleanHtml($subject)) { $this->errors[] = Tools::displayError('Invalid subject$subject'); } else if (!$id_customer_thread && $nameRequired && !trim($userName)) { @@ -72,7 +72,7 @@ class ContactControllerCore extends FrontController } else if (!$id_customer_thread && trim($phone) && !Validate::isPhoneNumber($phone)) { $this->errors[] = Tools::displayError('Invalid Phone number.'); } elseif (!Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id))) { - $this->errors[] = Tools::displayError('Please select a subject from the list provided.'); + $this->errors[] = Tools::displayError('Please choose who to send the message to.'); } elseif (!empty($file_attachment['name']) && $file_attachment['error'] != 0) { $this->errors[] = Tools::displayError('An error occurred during the file-upload process.'); } elseif (!empty($file_attachment['name']) && !in_array(Tools::strtolower(substr($file_attachment['name'], -4)), $extension) && !in_array(Tools::strtolower(substr($file_attachment['name'], -5)), $extension)) { @@ -160,7 +160,7 @@ class ContactControllerCore extends FrontController if (!count($this->errors)) { $var_list = array( '{order_name}' => '-', - '{attached_file}' => ' ', + '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{product_name}' => '', @@ -168,7 +168,7 @@ class ContactControllerCore extends FrontController ); if (isset($file_attachment['name'])) { - $var_list['{attached_file}'] = ''.$this->l('Attached file').':'.$file_attachment['name']; + $var_list['{attached_file}'] = $file_attachment['name']; } $id_product = (int)Tools::getValue('id_product'); From 17928f7f58d8ee231e4057fdf95d8bcd6798cb81 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Fri, 16 May 2025 14:42:07 +0530 Subject: [PATCH 07/13] added id order wise filter in the admin customer thread --- controllers/admin/AdminCustomerThreadsController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 21c6db2a1..4c5692832 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -172,6 +172,13 @@ class AdminCustomerThreadsControllerCore extends AdminController 'type' => 'datetime', 'optional' => true, ), + 'id_order' => array( + 'title' => $this->l('ID Order'), + 'filter_key' => 'a!id_order', + 'optional' => true, + 'visible_default' => false, + 'displayed' => false, + ), ); $this->bulk_actions = array( From 56c022032140c112cbfc6012931fb4728c905cea Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Tue, 20 May 2025 12:12:16 +0530 Subject: [PATCH 08/13] Fixed: conflict issues --- install/data/xml/configuration.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index a63ac517c..691c7c2ce 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -970,6 +970,7 @@ 1 + 5 From d179ad88c616173e95cc591e897b19564d04f096 Mon Sep 17 00:00:00 2001 From: "vishalsingh.qlo325" Date: Wed, 21 May 2025 14:26:21 +0530 Subject: [PATCH 09/13] Updated the customer/admin message flow --- .../sass/controllers/_customer-thread.sass | 11 -- .../themes/default/sass/partials/_icons.sass | 6 + .../helpers/list/list_header.tpl | 18 +- .../customer_threads/helpers/view/view.tpl | 26 ++- .../customer_threads/page_header_toolbar.tpl | 39 ++++ .../admin/AdminCustomerThreadsController.php | 180 ++++++++++-------- controllers/admin/AdminOrdersController.php | 2 +- controllers/admin/AdminStatsController.php | 1 - controllers/front/ContactController.php | 78 ++++---- controllers/front/OrderDetailController.php | 2 +- install/data/xml/configuration.xml | 10 +- js/admin/customer_thread.js | 38 ++-- mails/en/contact.html | 59 +++--- mails/en/contact.txt | 8 +- mails/en/contact_content_html.tpl | 15 ++ mails/en/contact_content_txt.tpl | 18 ++ mails/en/order_customer_comment.html | 63 +++--- mails/en/order_customer_comment.txt | 5 +- mails/en/order_merchant_comment.html | 111 ++++++----- mails/en/order_merchant_comment.txt | 11 +- mails/en/reply_msg.html | 36 ++-- mails/en/reply_msg.txt | 3 +- 22 files changed, 413 insertions(+), 327 deletions(-) create mode 100644 admin/themes/default/template/controllers/customer_threads/page_header_toolbar.tpl create mode 100644 mails/en/contact_content_html.tpl create mode 100644 mails/en/contact_content_txt.tpl diff --git a/admin/themes/default/sass/controllers/_customer-thread.sass b/admin/themes/default/sass/controllers/_customer-thread.sass index a0b8e1d65..bb2b15df4 100644 --- a/admin/themes/default/sass/controllers/_customer-thread.sass +++ b/admin/themes/default/sass/controllers/_customer-thread.sass @@ -48,17 +48,6 @@ @include left(1px) @include box-shadow(white 0 0 0 3px inset) -.submitReply - i[class^="icon-"] - display: block - width: 30px - height: 30px - margin: 0 auto - font-size: 28px - background: transparent - background-size: 26px - background-position: center - .table.customer_thread, #MeaningStatus .text-success color: #56CE56 diff --git a/admin/themes/default/sass/partials/_icons.sass b/admin/themes/default/sass/partials/_icons.sass index 2f3aa08e3..4c6454e8c 100644 --- a/admin/themes/default/sass/partials/_icons.sass +++ b/admin/themes/default/sass/partials/_icons.sass @@ -443,3 +443,9 @@ @extend .icon-toggle-on .process-icon-toggle-off @extend .icon-toggle-off + .process-icon-reply-all + @extend .icon-reply-all + .process-icon-mail-reply + @extend .icon-mail-reply + .process-icon-lock + @extend .icon-lock diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl index 4b0ded7a7..de58eaab0 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/list/list_header.tpl @@ -39,7 +39,7 @@ {assign var=id_customer_thread value=$tmp2.id_customer_thread} {/if} {/foreach} -
+
{$val.name} @@ -58,7 +58,7 @@
{/foreach} -
+
{l s='Meaning of status'} @@ -71,19 +71,5 @@
-
-
-
- {l s='Statistics'} -
-
    - {assign var=count value=0} - {foreach $stats as $key => $stat} - {assign var=count value=$count+1} -
  • {$stat.title} {$stat.val}
  • - {/foreach} -
-
-
{/block} diff --git a/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl b/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl index 6cb1f5885..b42bea915 100644 --- a/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/customer_threads/helpers/view/view.tpl @@ -30,6 +30,11 @@
@@ -45,24 +50,25 @@
- +
- {if isset($customer->firstname)} + {if isset($thread->user_name) && trim($thread->user_name)}

- - {$customer->firstname|escape:'html':'UTF-8'} {$customer->lastname|escape:'html':'UTF-8'} ({$customer->email|escape:'html':'UTF-8'}) - + {$thread->user_name|escape:'html':'UTF-8'} ({$thread->email|escape:'html':'UTF-8'})

{else}

{$thread->email|escape:'html':'UTF-8'}

{/if} + {if isset($thread->phone) && trim($thread->phone) != ''} +

{l s='Phone:'} {$thread->phone|escape:'html':'UTF-8'}

+ {/if} {if isset($contact) && trim($contact) != ''} - {l s="To:"} {$contact|escape:'html':'UTF-8'} + {l s='To:'} {$contact|escape:'html':'UTF-8'} {/if}
- {if isset($customer->firstname)} + {if isset($customer->email) && $customer->email == $thread->email}

{if $count_ok} @@ -111,9 +117,9 @@ {l s="Choose a template"} --> - - - + + +

diff --git a/admin/themes/default/template/controllers/customer_threads/page_header_toolbar.tpl b/admin/themes/default/template/controllers/customer_threads/page_header_toolbar.tpl new file mode 100644 index 000000000..9378f1eaf --- /dev/null +++ b/admin/themes/default/template/controllers/customer_threads/page_header_toolbar.tpl @@ -0,0 +1,39 @@ +{** + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License version 3.0 + * that is bundled with this package in the file LICENSE.md + * It is also available through the world-wide-web at this URL: + * https://opensource.org/license/osl-3-0-php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to support@qloapps.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade this module to a newer + * versions in the future. If you wish to customize this module for your needs + * please refer to https://store.webkul.com/customisation-guidelines for more information. + * + * @author Webkul IN + * @copyright Since 2010 Webkul + * @license https://opensource.org/license/osl-3-0-php Open Software License version 3.0 +*} + +{extends file="page_header_toolbar.tpl"} + +{block name=pageTitle} + {if isset($display) && $display == 'view'} +

+ {if is_array($title)} + {$title|end|strip_tags} + {else} + + {$title|strip_tags|truncate:40} + + {/if} +

+ {else} + {$smarty.block.parent} + {/if} +{/block} \ No newline at end of file diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 4c5692832..9a0b9f397 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -199,15 +199,16 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->fields_options = array( 'contact' => array( - 'title' => $this->l('Contact options'), - 'fields' => array( - 'PS_CUSTOMER_SERVICE_FILE_UPLOAD' => array( - 'title' => $this->l('Allow file uploading'), - 'hint' => $this->l('Allow customers to upload files using the contact page.'), - 'type' => 'bool' + 'title' => $this->l('Contact options'), + 'fields' => array( + 'PS_CUSTOMER_SERVICE_SIGNATURE' => array( + 'title' => $this->l('Default message'), + 'hint' => $this->l('Please fill out the message fields that appear by default when you answer a thread on the customer service page.'), + 'type' => 'textareaLang', + 'lang' => true ), - 'PS_MAIL_EMAIL_MESSAGE' => array( - 'title' => $this->l('Send email to'), + 'PS_MAIL_EMAIL_MESSAGE' => array( + 'title' => $this->l('Send messages from order page to'), 'desc' => $this->l('Where customers send messages from the order page.'), 'validation' => 'isUnsignedId', 'type' => 'select', @@ -215,13 +216,13 @@ class AdminCustomerThreadsControllerCore extends AdminController 'identifier' => 'email_message', 'list' => $arr ), - 'PS_CUSTOMER_SERVICE_CONTACT_ALLOW' => array( - 'title' => $this->l('Allow guest to select contact'), - 'hint' => $this->l('Allow guest to select the contact while submitting message from the contact page.'), + 'PS_CUSTOMER_SERVICE_DISPLAY_CONTACT' => array( + 'title' => $this->l('Select contact on contact page'), + 'hint' => $this->l('Allow guest to select the contact while sending message from the contact page.'), 'type' => 'bool' ), - 'PS_CUSTOMER_SERVICE_EMAIL_MESSAGE' => array( - 'title' => $this->l('Send email to'), + 'PS_CUSTOMER_SERVICE_CONTACT' => array( + 'title' => $this->l('Send messages from contact page to'), 'desc' => $this->l('Where customers send messages from the Contact page.'), 'validation' => 'isUnsignedId', 'type' => 'select', @@ -229,32 +230,31 @@ class AdminCustomerThreadsControllerCore extends AdminController 'identifier' => 'email_message', 'list' => $arr ), - 'PS_CUSTOMER_SERVICE_NAME_REQUIRED' => array( - 'title' => $this->l('Set Name as required'), - 'hint' => $this->l('Set Name as required while submitting message from the contact page.'), - 'type' => 'bool' - ), - 'PS_CUSTOMER_SERVICE_NAME_DISPLAY' => array( - 'title' => $this->l('Display Name field'), + 'PS_CUSTOMER_SERVICE_DISPLAY_NAME' => array( + 'title' => $this->l('Display name on contact page'), 'hint' => $this->l('Display name field on contact page.'), 'type' => 'bool', ), - 'PS_CUSTOMER_SERVICE_PHONE_REQUIRED' => array( - 'title' => $this->l('Set Phone as required'), - 'hint' => $this->l('Set Phone as required while submitting message from the contact page.'), + 'PS_CUSTOMER_SERVICE_REQUIRED_NAME' => array( + 'title' => $this->l('Set name as required'), + 'hint' => $this->l('Set name as required while submitting message from the contact page.'), 'type' => 'bool' ), - 'PS_CUSTOMER_SERVICE_PHONE_DISPLAY' => array( - 'title' => $this->l('Display Phone field'), + 'PS_CUSTOMER_SERVICE_DISPLAY_PHONE' => array( + 'title' => $this->l('Display phone on contact page'), 'hint' => $this->l('Display phone field on contact page.'), 'type' => 'bool', ), - 'PS_CUSTOMER_SERVICE_SIGNATURE' => array( - 'title' => $this->l('Default message'), - 'hint' => $this->l('Please fill out the message fields that appear by default when you answer a thread on the customer service page.'), - 'type' => 'textareaLang', - 'lang' => true - ) + 'PS_CUSTOMER_SERVICE_REQUIRED_PHONE' => array( + 'title' => $this->l('Set phone as required'), + 'hint' => $this->l('Set phone as required while submitting message from the contact page.'), + 'type' => 'bool' + ), + 'PS_CUSTOMER_SERVICE_FILE_UPLOAD' => array( + 'title' => $this->l('Allow file uploading'), + 'hint' => $this->l('Allow customers to upload files using the contact page.'), + 'type' => 'bool' + ), ), 'submit' => array( 'title' => $this->l('Save'), @@ -394,45 +394,10 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->_orderWay = 'DESC'; $contacts = CustomerThread::getContacts(); - $categories = Contact::getCategoriesContacts(); - - $stats = array( - array( - 'title' => $this->l('Total threads'), - 'val' => $all = CustomerThread::getTotalCustomerThreads(), - ), - array( - 'title' => $this->l('Threads pending'), - 'val' => $pending = CustomerThread::getTotalCustomerThreads( - 'status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1.' - OR status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2 - ), - ), - array( - 'title' => $this->l('Total number of customer messages'), - 'val' => CustomerMessage::getTotalCustomerMessages('cm.`id_employee` = 0'), - ), - array( - 'title' => $this->l('Total number of employee messages'), - 'val' => CustomerMessage::getTotalCustomerMessages('cm.`id_employee` != 0'), - ), - array( - 'title' => $this->l('Unread threads'), - 'val' => $unread = CustomerThread::getTotalCustomerThreads( - 'status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN - ), - ), - array( - 'title' => $this->l('Closed threads'), - 'val' => $all - ($unread + $pending), - ), - ); - $this->tpl_list_vars = array( 'contacts' => $contacts, 'categories' => $categories, - 'stats' => $stats ); return parent::renderList(); @@ -457,12 +422,12 @@ class AdminCustomerThreadsControllerCore extends AdminController if (Tools::isSubmit('submitOptionsCustomerService')) { unset($this->fields_options['general']); $this->processUpdateOptions(); - if (Tools::getValue('PS_CUSTOMER_SERVICE_NAME_REQUIRED')) { - Configuration::updateValue('PS_CUSTOMER_SERVICE_NAME_DISPLAY', 1); + if (!Tools::getValue('PS_CUSTOMER_SERVICE_DISPLAY_NAME')) { + Configuration::updateValue('PS_CUSTOMER_SERVICE_REQUIRED_NAME', 0); } - if (Tools::getValue('PS_CUSTOMER_SERVICE_PHONE_REQUIRED')) { - Configuration::updateValue('PS_CUSTOMER_SERVICE_PHONE_DISPLAY', 1); + if (!Tools::getValue('PS_CUSTOMER_SERVICE_DISPLAY_PHONE')) { + Configuration::updateValue('PS_CUSTOMER_SERVICE_REQUIRED_PHONE', 0); } } else if (Tools::isSubmit('submitOptionsIMAPConfig')) { unset($this->fields_options['contact']); @@ -633,12 +598,13 @@ class AdminCustomerThreadsControllerCore extends AdminController $this->context->link->getPageLink('contact', true, (int)$ct->id_lang, null, false, $ct->id_shop), 'token='.$ct->token ); - $headingText = $this->l('Hi') .' '.$ct->user_name; + $headingText = $this->l('Hi').' '.$ct->user_name.','; $idShop = $ct->id_shop; $params = array( '{reply}' => Tools::nl2br(Tools::getValue('reply_message')), '{link}' => $link, '{headingtext}' => $headingText, + '{contact_name}' => $contact->name, ); if (!empty(trim($ct->subject))) { $params['{subject}'] = $ct->subject; @@ -652,6 +618,7 @@ class AdminCustomerThreadsControllerCore extends AdminController if ($customer->id) { $headingText .= ' '.$customer->firstname.' '.$customer->lastname; } + $headingText .= ','; } if (Mail::Send( @@ -759,18 +726,29 @@ class AdminCustomerThreadsControllerCore extends AdminController $time = time(); $kpis = array(); + $all = CustomerThread::getTotalCustomerThreads(); + $pending = (int)AdminStatsController::getPendingMessages(); + $open = CustomerThread::getTotalCustomerThreads('status='.CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN); + $helper = new HelperKpi(); + $helper->id = 'box-messages'; + $helper->icon = 'icon-envelope'; + $helper->color = 'color1'; + $helper->title = $this->l('Total threads'); + $helper->value = $all; + $this->kpis[] = $helper; + $helper = new HelperKpi(); $helper->id = 'box-pending-messages'; $helper->icon = 'icon-envelope'; - $helper->color = 'color1'; - $helper->title = $this->l('Pending Discussion Threads', null, null, false); - $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=pending_messages'; + $helper->color = 'color2'; + $helper->title = $this->l('Threads pending', null, null, false); + $helper->value = $pending + $open; $this->kpis[] = $helper; $helper = new HelperKpi(); $helper->id = 'box-age'; $helper->icon = 'icon-time'; - $helper->color = 'color2'; + $helper->color = 'color3'; $helper->title = $this->l('Average Response Time', null, null, false); $helper->subtitle = $this->l('30 days', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=avg_msg_response_time'; @@ -779,12 +757,45 @@ class AdminCustomerThreadsControllerCore extends AdminController $helper = new HelperKpi(); $helper->id = 'box-messages-per-thread'; $helper->icon = 'icon-copy'; - $helper->color = 'color3'; + $helper->color = 'color4'; $helper->title = $this->l('Messages per Thread', null, null, false); $helper->subtitle = $this->l('30 day', null, null, false); $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=messages_per_thread'; $this->kpis[] = $helper; + $helper = new HelperKpi(); + $helper->id = 'box-pending-messages'; + $helper->icon = 'icon-envelope'; + $helper->color = 'color1'; + $helper->title = $this->l('Customer messages', null, null, false); + $helper->value = (int) CustomerMessage::getTotalCustomerMessages('cm.`id_employee` = 0'); + $this->kpis[] = $helper; + + $helper = new HelperKpi(); + $helper->id = 'box-pending-messages'; + $helper->icon = 'icon-envelope'; + $helper->color = 'color4'; + $helper->title = $this->l('Employee messages', null, null, false); + $helper->value = (int) CustomerMessage::getTotalCustomerMessages('cm.`id_employee` != 0'); + $this->kpis[] = $helper; + + + $helper = new HelperKpi(); + $helper->id = 'box-pending-messages'; + $helper->icon = 'icon-envelope'; + $helper->color = 'color2'; + $helper->title = $this->l('Unread threads', null, null, false); + $helper->value = (int) $open; + $this->kpis[] = $helper; + + $helper = new HelperKpi(); + $helper->id = 'box-pending-messages'; + $helper->icon = 'icon-envelope'; + $helper->color = 'color1'; + $helper->title = $this->l('Closed threads', null, null, false); + $helper->value = (int) ($all - ($open + $pending)); + $this->kpis[] = $helper; + return parent::renderKpis(); } @@ -911,6 +922,7 @@ class AdminCustomerThreadsControllerCore extends AdminController } } + $this->context->smarty->assign('display', 'view'); $this->tpl_view_vars = array( 'id_customer_thread' => $id_customer_thread, 'thread' => $thread, @@ -995,6 +1007,22 @@ class AdminCustomerThreadsControllerCore extends AdminController return $timeline; } + public function initToolbarTitle() + { + parent::initToolbarTitle(); + switch ($this->display) { + case 'view': + if (!($thread = $this->loadObject())) { + return; + } + + if ($thread->id) { + $this->toolbar_title[] = sprintf($this->l('Title: %1$s'), $thread->subject); + } + break; + } + } + protected function displayMessage($message, $email = false, $id_employee = null) { $tpl = $this->createTemplate('message.tpl'); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 57c7d0867..c5f55b4e7 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1568,7 +1568,7 @@ class AdminOrdersControllerCore extends AdminController $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($customer->email, $order->id); if (!$id_customer_thread) { $customer_thread = new CustomerThread(); - $customer_thread->id_contact = 0; + $customer_thread->id_contact = (int)Configuration::get('PS_MAIL_EMAIL_MESSAGE'); $customer_thread->id_customer = (int)$order->id_customer; $customer_thread->user_name = $customer->firstname.' '.$customer->lastname; $customer_thread->phone = $customer->phone; diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 47f48394b..5864228a7 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -425,7 +425,6 @@ class AdminStatsControllerCore extends AdminStatsTabController public static function getPendingMessages() { $pendingStatuses = array( - CustomerThread::QLO_CUSTOMER_THREAD_STATUS_OPEN, CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING2, CustomerThread::QLO_CUSTOMER_THREAD_STATUS_PENDING1 ); diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 3332b2f4e..691959cec 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -47,10 +47,10 @@ class ContactControllerCore extends FrontController $id_contact = (int)Tools::getValue('id_contact'); $objCustomerThread = new CustomerThread(); $id_customer_thread = (int)$objCustomerThread->getIdCustomerThreadByToken(Tools::getValue('token')); - $nameRequired = Configuration::get('PS_CUSTOMER_SERVICE_NAME_REQUIRED'); - $phoneRequired = Configuration::get('PS_CUSTOMER_SERVICE_PHONE_REQUIRED'); - if (!Configuration::get('PS_CUSTOMER_SERVICE_CONTACT_ALLOW')) { - $id_contact = (int) Configuration::get('PS_CUSTOMER_SERVICE_EMAIL_MESSAGE'); + $nameRequired = Configuration::get('PS_CUSTOMER_SERVICE_REQUIRED_NAME'); + $phoneRequired = Configuration::get('PS_CUSTOMER_SERVICE_REQUIRED_PHONE'); + if (!Configuration::get('PS_CUSTOMER_SERVICE_DISPLAY_CONTACT')) { + $id_contact = (int) Configuration::get('PS_CUSTOMER_SERVICE_CONTACT'); } if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) { @@ -158,34 +158,22 @@ class ContactControllerCore extends FrontController } if (!count($this->errors)) { - $var_list = array( - '{order_name}' => '-', - '{attached_file}' => '-', - '{message}' => Tools::nl2br(stripslashes($message)), - '{email}' => $from, - '{product_name}' => '', - '{subject}' => $ct->subject, - ); + $smartyMailVars['message'] = Tools::nl2br(stripslashes($message)); + $smartyMailVars['email'] = $ct->email; + $smartyMailVars['subject'] = $ct->subject; + $smartyMailVars['phone'] = $ct->phone; + $smartyMailVars['user_name'] = $ct->user_name; if (isset($file_attachment['name'])) { - $var_list['{attached_file}'] = $file_attachment['name']; - } - - $id_product = (int)Tools::getValue('id_product'); - - if (isset($ct) && Validate::isLoadedObject($ct) && $ct->id_order) { - $order = new Order((int)$ct->id_order); - $var_list['{order_name}'] = $order->getUniqReference(); - $var_list['{id_order}'] = (int)$order->id; - } - - if ($id_product) { - $product = new Product((int)$id_product); - if (Validate::isLoadedObject($product) && isset($product->name[Context::getContext()->language->id])) { - $var_list['{product_name}'] = $product->name[Context::getContext()->language->id]; - } + $smartyMailVars['attached_file'] = $file_attachment['name']; } + $contact_content_txt = $this->getEmailTemplateContent('contact_content_txt.tpl', Mail::TYPE_TEXT, $smartyMailVars); + $contact_content_html = $this->getEmailTemplateContent('contact_content_html.tpl', Mail::TYPE_TEXT, $smartyMailVars); + $var_list = array( + '{contact_content_txt}' => $contact_content_txt, + '{contact_content_html}' => $contact_content_html, + ); if (!empty($contact->email)) { Mail::Send( $this->context->language->id, @@ -217,6 +205,30 @@ class ContactControllerCore extends FrontController } } + protected function getEmailTemplateContent($template_name, $mail_type, $var) + { + $email_configuration = Configuration::get('PS_MAIL_TYPE'); + if ($email_configuration != $mail_type && $email_configuration != Mail::TYPE_BOTH) { + return ''; + } + + $pathToFindEmail = array( + _PS_THEME_DIR_.'mails'.DIRECTORY_SEPARATOR.$this->context->language->iso_code.DIRECTORY_SEPARATOR.$template_name, + _PS_THEME_DIR_.'mails'.DIRECTORY_SEPARATOR.'en'.DIRECTORY_SEPARATOR.$template_name, + _PS_MAIL_DIR_.$this->context->language->iso_code.DIRECTORY_SEPARATOR.$template_name, + _PS_MAIL_DIR_.'en'.DIRECTORY_SEPARATOR.$template_name, + ); + + foreach ($pathToFindEmail as $path) { + if (Tools::file_exists_cache($path)) { + $this->context->smarty->assign($var); + return $this->context->smarty->fetch($path); + } + } + + return ''; + } + public function setMedia() { parent::setMedia(); @@ -324,11 +336,11 @@ class ContactControllerCore extends FrontController 'contacts' => Contact::getContacts($this->context->language->id), 'message' => html_entity_decode(Tools::getValue('message')), 'contactKey' => $contactKey, - 'contactNameRequired' => Configuration::get('PS_CUSTOMER_SERVICE_NAME_REQUIRED'), - 'displayContactName' => Configuration::get('PS_CUSTOMER_SERVICE_NAME_DISPLAY'), - 'contactPhoneRequired' => Configuration::get('PS_CUSTOMER_SERVICE_PHONE_REQUIRED'), - 'displayContactPhone' => Configuration::get('PS_CUSTOMER_SERVICE_PHONE_DISPLAY'), - 'allowContactSelection' => Configuration::get('PS_CUSTOMER_SERVICE_CONTACT_ALLOW') + 'contactNameRequired' => Configuration::get('PS_CUSTOMER_SERVICE_REQUIRED_NAME'), + 'displayContactName' => Configuration::get('PS_CUSTOMER_SERVICE_DISPLAY_NAME'), + 'contactPhoneRequired' => Configuration::get('PS_CUSTOMER_SERVICE_REQUIRED_PHONE'), + 'displayContactPhone' => Configuration::get('PS_CUSTOMER_SERVICE_DISPLAY_PHONE'), + 'allowContactSelection' => Configuration::get('PS_CUSTOMER_SERVICE_DISPLAY_CONTACT') ) ); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 80e9a335d..3c94c1464 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -693,7 +693,7 @@ class OrderDetailControllerCore extends FrontController $objCustomer = new Customer($order->id_customer); if (!$id_customer_thread) { $ct = new CustomerThread(); - $ct->id_contact = 0; + $ct->id_contact = (int)Configuration::get('PS_MAIL_EMAIL_MESSAGE'); $ct->id_customer = (int)$order->id_customer; $ct->user_name = $objCustomer->firstname.' '.$objCustomer->lastname; $ct->subject = $order->reference; diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml index 691c7c2ce..089c2c68c 100644 --- a/install/data/xml/configuration.xml +++ b/install/data/xml/configuration.xml @@ -956,19 +956,19 @@ 0 - + 1 - + 1 - + 1 - + 1 - + 1 diff --git a/js/admin/customer_thread.js b/js/admin/customer_thread.js index 94aeea291..fd4b1be80 100644 --- a/js/admin/customer_thread.js +++ b/js/admin/customer_thread.js @@ -18,41 +18,39 @@ */ $(document).ready(function() { - if ($('#PS_CUSTOMER_SERVICE_CONTACT_ALLOW_on').prop('checked')) { - $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').hide(); + if ($('#PS_CUSTOMER_SERVICE_DISPLAY_CONTACT_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_CONTACT"]').closest('.form-group').hide(); } - if ($('#PS_CUSTOMER_SERVICE_NAME_REQUIRED_on').prop('checked')) { - $('[name="PS_CUSTOMER_SERVICE_NAME_DISPLAY"]').closest('.form-group').hide(); + if (!$('#PS_CUSTOMER_SERVICE_DISPLAY_NAME_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_REQUIRED_NAME"]').closest('.form-group').hide(); } - if ($('#PS_CUSTOMER_SERVICE_PHONE_REQUIRED_on').prop('checked')) { - $('[name="PS_CUSTOMER_SERVICE_PHONE_DISPLAY"]').closest('.form-group').hide(); + if (!$('#PS_CUSTOMER_SERVICE_DISPLAY_PHONE_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_REQUIRED_PHONE"]').closest('.form-group').hide(); } - $(document).on('change', '[name="PS_CUSTOMER_SERVICE_CONTACT_ALLOW"]', function() { - if ($('#PS_CUSTOMER_SERVICE_CONTACT_ALLOW_on').prop('checked')) { - $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').hide(); + $(document).on('change', '[name="PS_CUSTOMER_SERVICE_DISPLAY_CONTACT"]', function() { + if ($('#PS_CUSTOMER_SERVICE_DISPLAY_CONTACT_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_CONTACT"]').closest('.form-group').hide(); } else { - $('[name="PS_CUSTOMER_SERVICE_EMAIL_MESSAGE"]').closest('.form-group').show(); + $('[name="PS_CUSTOMER_SERVICE_CONTACT"]').closest('.form-group').show(); } }); - $(document).on('change', '[name="PS_CUSTOMER_SERVICE_NAME_REQUIRED"]', function() { - if ($('#PS_CUSTOMER_SERVICE_NAME_REQUIRED_on').prop('checked')) { - $('[name="PS_CUSTOMER_SERVICE_NAME_DISPLAY"]').closest('.form-group').hide(); - $('#PS_CUSTOMER_SERVICE_NAME_DISPLAY_on').prop('checked', true); + $(document).on('change', '[name="PS_CUSTOMER_SERVICE_DISPLAY_NAME"]', function() { + if ($('#PS_CUSTOMER_SERVICE_DISPLAY_NAME_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_REQUIRED_NAME"]').closest('.form-group').show(); } else { - $('[name="PS_CUSTOMER_SERVICE_NAME_DISPLAY"]').closest('.form-group').show(); + $('[name="PS_CUSTOMER_SERVICE_REQUIRED_NAME"]').closest('.form-group').hide(); } }); - $(document).on('change', '[name="PS_CUSTOMER_SERVICE_PHONE_REQUIRED"]', function() { - if ($('#PS_CUSTOMER_SERVICE_PHONE_REQUIRED_on').prop('checked')) { - $('[name="PS_CUSTOMER_SERVICE_PHONE_DISPLAY"]').closest('.form-group').hide(); - $('#PS_CUSTOMER_SERVICE_PHONE_DISPLAY_on').prop('checked', true); + $(document).on('change', '[name="PS_CUSTOMER_SERVICE_DISPLAY_PHONE"]', function() { + if ($('#PS_CUSTOMER_SERVICE_DISPLAY_PHONE_on').prop('checked')) { + $('[name="PS_CUSTOMER_SERVICE_REQUIRED_PHONE"]').closest('.form-group').show(); } else { - $('[name="PS_CUSTOMER_SERVICE_PHONE_DISPLAY"]').closest('.form-group').show(); + $('[name="PS_CUSTOMER_SERVICE_REQUIRED_PHONE"]').closest('.form-group').hide(); } }); diff --git a/mails/en/contact.html b/mails/en/contact.html index c9c93ad62..5c5aa9d53 100644 --- a/mails/en/contact.html +++ b/mails/en/contact.html @@ -66,38 +66,33 @@
- - Message from a {shop_name} customer - -
- - - - - - -
  - - - Customer e-mail address: {email}

- Title: {subject}

- Customer message: {message}

- Attached file: {attached_file} -
-
-
 
-
+ + Message from a {shop_name} customer + +
+ + + + + + +
  + + + {contact_content_html} + + +  
+
- - Hi {firstname} {lastname}, - -
- - - - - - -
  - -

- Message from a customer

- - You have received a new message regarding booking with the reference {order_name}.

- Customer: {firstname} {lastname} ({email})

- {message} -
-
-
 
-
+ + Message from a customer + +
+ + + + + + +
  + + + You have received a new message regarding booking with the reference {order_name}.

+ Name: {firstname} {lastname}

+ E-mail: {email}

+ Customer message:
{message}

+
+
+
 
+
- - Hi {firstname} {lastname}, - -
- - - - - - -
  - -

- Message from {shop_name}

- - You have received a new message from {shop_name} regarding order with the reference {order_name}.

- Message: {message} -
-
-
 
-
+ + Hi {firstname} {lastname}, + +
+ + + + + + +
  + +

+ Message from {shop_name} +

+ + You have received a new message from {shop_name} regarding booking with the reference {order_name}.

+ Message:
{message} +
+
+
 
+
- Title: {subject} -
- {reply} + + + + + + +
  + +

+ Message from {contact_name}


Title: {subject}

+ Message:
{reply}
+

+ + Please do not reply directly to this email, we will not receive it.
+ In order to reply, you can click here +
+
- - Please do not reply directly to this email, we will not receive it.
- In order to reply, you can click here
-