diff --git a/classes/CustomerMessage.php b/classes/CustomerMessage.php
index a4b6c920d..21798c993 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 = null, $limit = false)
{
return Db::getInstance()->executeS('
SELECT cm.*,
@@ -89,29 +91,33 @@ 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
- ');
+ ORDER BY cm.date_add DESC'.
+ (($limit) ? ' LIMIT '.(int) $limit: ' ')
+ );
}
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 7e1b721af..e692dd724 100644
--- a/classes/CustomerThread.php
+++ b/classes/CustomerThread.php
@@ -30,15 +30,23 @@ class CustomerThreadCore extends ObjectModel
public $id_shop;
public $id_lang;
public $id_contact;
+ public $id_employee;
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 +56,13 @@ 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_employee' =>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 +169,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).'\''
);
}
@@ -176,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
@@ -184,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().'
@@ -194,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)
@@ -234,7 +269,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/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/PaymentModule.php b/classes/PaymentModule.php
index f121e067f..ed4ad37ee 100644
--- a/classes/PaymentModule.php
+++ b/classes/PaymentModule.php
@@ -716,7 +716,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();
@@ -724,7 +724,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/classes/Product.php b/classes/Product.php
index 894b2aa54..cf29770ae 100644
--- a/classes/Product.php
+++ b/classes/Product.php
@@ -1063,11 +1063,12 @@ class ProductCore extends ObjectModel
}
if (!$this->booking_product) {
- $objHotelRoomTypeBedType = new HotelRoomTypeBedType();
- $objHotelRoomTypeBedType->deleteRoomTypeBedTypes(false, $this->id);
if (!$this->deleteServiceInfo()) {
return false;
}
+ } else {
+ $objHotelRoomTypeBedType = new HotelRoomTypeBedType();
+ $objHotelRoomTypeBedType->deleteRoomTypeBedTypes(false, $this->id);
}
Hook::exec('actionProductDelete', array('id_product' => (int)$this->id, 'product' => $this));
diff --git a/classes/webservice/WebserviceSpecificManagementBookings.php b/classes/webservice/WebserviceSpecificManagementBookings.php
index 91d68d9e6..539593f8c 100644
--- a/classes/webservice/WebserviceSpecificManagementBookings.php
+++ b/classes/webservice/WebserviceSpecificManagementBookings.php
@@ -2679,7 +2679,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;
@@ -3499,7 +3499,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 2d7b52891..4d120c055 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,25 +93,41 @@ 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'),
+ 'title' => $this->l('Contact'),
'type' => 'select',
'list' => $contact_array,
'filter_key' => 'cl!id_contact',
'filter_type' => 'int',
),
+ 'subject' => array(
+ 'title' => $this->l('Title'),
+ 'filter_key' => 'a!subject',
+ 'tmpTableFilter' => true,
+ 'maxlength' => 30,
+ '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'),
@@ -112,29 +142,42 @@ class AdminCustomerThreadsControllerCore extends AdminController
'title' => $this->l('Employee'),
'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'),
+ '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(
- 'title' => $this->l('Private'),
- 'type' => 'select',
- 'filter_key' => 'private',
+ 'has_private' => array(
+ 'title' => $this->l('Has 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'),
'havingFilter' => true,
'type' => 'datetime',
+ 'optional' => true,
+ ),
+ 'id_order' => array(
+ 'title' => $this->l('ID Order'),
+ 'filter_key' => 'a!id_order',
+ 'optional' => true,
+ 'visible_default' => false,
+ 'displayed' => false,
),
);
@@ -147,22 +190,71 @@ 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('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
- )
+ '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 messages from order page 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_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_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',
+ 'cast' => 'intval',
+ 'identifier' => 'email_message',
+ 'list' => $arr
+ ),
+ '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_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_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_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'),
@@ -242,6 +334,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 +364,8 @@ 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, 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
@@ -262,9 +374,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
@@ -274,33 +389,10 @@ 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';
- $contacts = CustomerThread::getContacts();
-
- $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)
- );
-
- $this->tpl_list_vars = array(
- 'contacts' => $contacts,
- 'categories' => $categories,
- 'params' => $params
- );
-
return parent::renderList();
}
@@ -323,6 +415,13 @@ class AdminCustomerThreadsControllerCore extends AdminController
if (Tools::isSubmit('submitOptionsCustomerService')) {
unset($this->fields_options['general']);
$this->processUpdateOptions();
+ if (!Tools::getValue('PS_CUSTOMER_SERVICE_DISPLAY_NAME')) {
+ Configuration::updateValue('PS_CUSTOMER_SERVICE_REQUIRED_NAME', 0);
+ }
+
+ 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']);
$this->processUpdateOptions();
@@ -334,6 +433,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
@@ -342,14 +442,13 @@ 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
');
}
- 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
@@ -363,7 +462,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.id_employee, cm.private, cm.date_add DESC
');
$output = $this->displayMessage($messages, true, (int)Tools::getValue('id_employee_forward'));
$cm = new CustomerMessage();
@@ -395,7 +494,10 @@ 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)
+ ) {
+ $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;
@@ -424,13 +526,14 @@ class AdminCustomerThreadsControllerCore extends AdminController
$this->errors[] = '
'.Tools::displayError('The email address is invalid.').'
';
}
}
- if (Tools::isSubmit('submitReply')) {
- $ct = new CustomerThread($id_customer_thread);
-
+ if (Tools::isSubmit('submitReply') || Tools::isSubmit('submitReplyAndClose')) {
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');
@@ -446,15 +549,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
$file_attachment['mime'] = $_FILES['joinFile']['type'];
}
$customer = new Customer($ct->id_customer);
- $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
- );
+
//#ct == id_customer_thread #tc == token of thread <== used in the synchronization imap
$contact = new Contact((int)$ct->id_contact, (int)$ct->id_lang);
@@ -466,13 +561,80 @@ 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').' '.$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;
+ }
+
+ $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;
+ }
+ $headingText .= ',';
+ }
+
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)) {
- $ct->status = 'closed';
+ (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();
}
Tools::redirectAdmin(
@@ -481,6 +643,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')) {
+ 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;
+ $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');
+ }
}
}
@@ -539,19 +719,34 @@ 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->tooltip = $this->l('Total number of 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;
+ $helper->tooltip = $this->l('Total number of threads having "open", "pending 1" and "pending 2" statuses.');
$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->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;
@@ -559,12 +754,79 @@ class AdminCustomerThreadsControllerCore extends AdminController
$helper = new HelperKpi();
$helper->id = 'box-messages-per-thread';
$helper->icon = 'icon-copy';
- $helper->color = 'color3';
- $helper->title = $this->l('Messages per Thread', null, null, false);
+ $helper->color = 'color4';
+ $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;
+ $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->tooltip = $this->l('Total number of messages sent by customers.');
+ $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->tooltip = $this->l('Total number of messages sent by employees.');
+ $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->tooltip = $this->l('Total number of messages having open status.');
+ $helper->value = (int) $open;
+ $this->kpis[] = $helper;
+
+ $helper = new HelperKpi();
+ $helper->id = 'box-pending-messages';
+ $helper->icon = 'icon-envelope';
+ $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();
}
@@ -603,64 +865,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
);
}
@@ -701,6 +953,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
}
}
+ $this->context->smarty->assign('display', 'view');
$this->tpl_view_vars = array(
'id_customer_thread' => $id_customer_thread,
'thread' => $thread,
@@ -710,7 +963,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 +973,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 +985,22 @@ class AdminCustomerThreadsControllerCore extends AdminController
$content = '';
if (!$message['private']) {
- $content .= $this->l('Message to: ').'
'.(!$message['id_employee'] ? $message['subject'] : $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').'';
}
+
if (Validate::isLoadedObject($product)) {
- $content .= '
'.$this->l('Room type: ').'
'.$product->name.'';
+ $content .= $this->l('Room type: ').'
'.$product->name.'';
}
$content .= Tools::safeOutput($message['message']);
@@ -778,6 +1038,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');
@@ -1079,7 +1355,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 5d39ddd50..3131c50fa 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 6289e393f..fd7fbf766 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -1722,13 +1722,17 @@ 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;
+ $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;
$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 {
@@ -1761,7 +1765,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,
@@ -2820,13 +2824,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;
@@ -3474,10 +3480,28 @@ class AdminOrdersControllerCore extends AdminController
}
}
+ $objCustomerThread = new CustomerThread();
+ $messages = Message::getMessagesByOrderId($order->id, true);
+ if ($customerMessages = CustomerMessage::getMessagesByOrderId($order->id, true)) {
+ foreach ($messages as $messageKey => $message) {
+ foreach ($customerMessages as $customerMessageKey => $customerMessage) {
+ if (strcmp($message['message'], $customerMessage['message']) == 0) {
+ unset($messages[$messageKey]);
+ }
+ }
+ }
+
+ $messages = array_merge($customerMessages, $messages);
+ usort($messages, function ($a, $b) {
+ return strtotime($a['date_add']) < strtotime($b['date_add']);
+ });
+ }
+
// send hotel standalone and standalone products
$objProduct = new Product();
$hotelStandaloneProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_HOTEL_STANDALONE);
$standaloneProducts = $objProduct->getServiceProducts(null, Product::SELLING_PREFERENCE_STANDALONE);
+
$this->tpl_view_vars = array(
'hotelStandaloneProducts' => $hotelStandaloneProducts,
'standaloneProducts' => $standaloneProducts,
@@ -3527,8 +3551,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/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php
index 9b2f91f28..5de24e205 100644
--- a/controllers/admin/AdminProductsController.php
+++ b/controllers/admin/AdminProductsController.php
@@ -3000,8 +3000,6 @@ class AdminProductsControllerCore extends AdminController
$objRoomType = new HotelRoomType();
$objRoomType->id_product = $product->id;
$objRoomType->id_hotel = $id_hotel;
- $idBedTypes = Tools::getValue('id_bed_types', array());
- $objRoomType->id_bed_types = json_encode($idBedTypes);
$objRoomType->save();
}
}
diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php
index 7d301dc2b..9e21fbe5d 100644
--- a/controllers/admin/AdminStatsController.php
+++ b/controllers/admin/AdminStatsController.php
@@ -499,7 +499,14 @@ 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_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)
@@ -530,13 +537,23 @@ 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.'
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 731780e78..691959cec 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_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)) {
$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 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)) {
+ $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 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)) {
@@ -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,36 +118,31 @@ class ContactControllerCore extends FrontController
if ($contact->customer_service) {
if ((int)$id_customer_thread) {
$ct = new CustomerThread($id_customer_thread);
- $ct->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();
if (isset($customer->id)) {
$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->id_contact = (int)$id_contact;
- $ct->id_lang = (int)$this->context->language->id;
+ $ct->phone = $phone;
+ $ct->user_name = $userName;
+ $ct->subject = $subject;
$ct->email = $from;
- $ct->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;
+ 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);
@@ -168,33 +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}' => '',
- );
+ $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,
@@ -226,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();
@@ -259,27 +262,30 @@ 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()
));
- 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);
}
$objShop = new Shop();
@@ -330,6 +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_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 d35f793c3..d8548f305 100644
--- a/controllers/front/OrderDetailController.php
+++ b/controllers/front/OrderDetailController.php
@@ -493,7 +493,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'),
@@ -758,26 +758,32 @@ 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_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;
+ $ct->phone = $objCustomer->phone;
$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']);
@@ -829,7 +835,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 {
@@ -887,4 +893,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 5162f1983..0afb0273e 100644
--- a/install/data/db_structure.sql
+++ b/install/data/db_structure.sql
@@ -634,6 +634,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,9 +659,12 @@ 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,
- `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,
@@ -670,8 +674,7 @@ CREATE TABLE `PREFIX_customer_thread` (
KEY `id_lang` (`id_lang`),
KEY `id_contact` (`id_contact`),
KEY `id_customer` (`id_customer`),
- KEY `id_order` (`id_order`),
- KEY `id_product` (`id_product`)
+ KEY `id_order` (`id_order`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8 COLLATION;
CREATE TABLE `PREFIX_order_customer_guest_detail` (
diff --git a/install/data/xml/configuration.xml b/install/data/xml/configuration.xml
index b7747bbe4..808ce70fb 100644
--- a/install/data/xml/configuration.xml
+++ b/install/data/xml/configuration.xml
@@ -955,6 +955,21 @@
0
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
0
diff --git a/js/admin/customer_thread.js b/js/admin/customer_thread.js
new file mode 100644
index 000000000..fd4b1be80
--- /dev/null
+++ b/js/admin/customer_thread.js
@@ -0,0 +1,57 @@
+/*
+* 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_DISPLAY_CONTACT_on').prop('checked')) {
+ $('[name="PS_CUSTOMER_SERVICE_CONTACT"]').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_DISPLAY_PHONE_on').prop('checked')) {
+ $('[name="PS_CUSTOMER_SERVICE_REQUIRED_PHONE"]').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_CONTACT"]').closest('.form-group').show();
+ }
+ });
+
+ $(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_REQUIRED_NAME"]').closest('.form-group').hide();
+ }
+ });
+
+ $(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_REQUIRED_PHONE"]').closest('.form-group').hide();
+ }
+ });
+
+});
diff --git a/mails/en/contact.html b/mails/en/contact.html
index 3ebbf35d5..5c5aa9d53 100644
--- a/mails/en/contact.html
+++ b/mails/en/contact.html
@@ -66,37 +66,33 @@