Merge remote-tracking branch 'origin/ticket/r16159-customer-message'

This commit is contained in:
Michael RICOIS 2018-03-05 09:49:15 +01:00
commit 322c019c5c
3 changed files with 37 additions and 9 deletions

View File

@ -38,17 +38,21 @@ class AdminCustomerThreads extends AdminTab
$this->view = true; $this->view = true;
$this->delete = true; $this->delete = true;
$this->_select = 'CONCAT(c.firstname," ",c.lastname) as customer, cl.name as contact, l.name as language, group_concat(message) as messages, ( $this->_select = '
SELECT IFNULL(CONCAT(LEFT(e.firstname, 1),". ",e.lastname), "--") CONCAT(c.firstname, " ", c.lastname) as customer, cl.name as contact,
FROM '._DB_PREFIX_.'customer_message cm2 INNER JOIN '._DB_PREFIX_.'employee e ON e.id_employee = cm2.id_employee l.name as language, group_concat(message) as messages,
WHERE cm2.id_employee > 0 AND cm2.`id_customer_thread` = a.`id_customer_thread` (SELECT IFNULL(CONCAT(LEFT(e.firstname, 1), ". ", e.lastname), "--")
ORDER BY cm2.date_add DESC LIMIT 1) as employee'; FROM '._DB_PREFIX_.'customer_message cm2 INNER JOIN '._DB_PREFIX_.'employee e ON e.id_employee = cm2.id_employee
WHERE cm2.id_employee > 0 AND cm2.`id_customer_thread` = a.`id_customer_thread`
ORDER BY cm2.date_add DESC LIMIT 1
) as employee';
$this->_group = 'GROUP BY cm.id_customer_thread'; $this->_group = 'GROUP BY cm.id_customer_thread';
$this->_join = ' $this->_join = '
LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = a.`id_customer` LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = a.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON cm.`id_customer_thread` = a.`id_customer_thread` LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON cm.`id_customer_thread` = a.`id_customer_thread`
LEFT JOIN `'._DB_PREFIX_.'lang` l ON l.`id_lang` = a.`id_lang` LEFT JOIN `'._DB_PREFIX_.'lang` l ON l.`id_lang` = a.`id_lang`
LEFT JOIN `'._DB_PREFIX_.'contact_lang` cl ON (cl.`id_contact` = a.`id_contact` AND cl.`id_lang` = '.(int)$cookie->id_lang.')'; LEFT JOIN `'._DB_PREFIX_.'contact_lang` cl ON (cl.`id_contact` = a.`id_contact` AND cl.`id_lang` = '.(int)$cookie->id_lang.')';
$contactArray = array(); $contactArray = array();
$contacts = Contact::getContacts($cookie->id_lang); $contacts = Contact::getContacts($cookie->id_lang);

View File

@ -173,9 +173,15 @@ if (Tools::isSubmit('submitMessage')) {
if ($contact->customer_service) if ($contact->customer_service)
{ {
$ctStatusLast = false;
if ((int)$id_customer_thread) if ((int)$id_customer_thread)
{ {
$ct = new CustomerThread($id_customer_thread); $ct = new CustomerThread($id_customer_thread);
$ctStatusLast = $ct->status;
$ctStatusDate = $ct->date_upd;
$ct->status = 'open'; $ct->status = 'open';
$ct->id_lang = (int)$cookie->id_lang; $ct->id_lang = (int)$cookie->id_lang;
$ct->id_contact = (int)($id_contact); $ct->id_contact = (int)($id_contact);
@ -213,6 +219,12 @@ if (Tools::isSubmit('submitMessage')) {
if ($ct->id) if ($ct->id)
{ {
// Update date_upd to the last interesting date
if ($ctStatusLast !== false && $ctStatusLast == 'open') {
$sql = 'UPDATE `'._DB_PREFIX_.'customer_thread` SET `date_upd` = "'.$ctStatusDate.'" WHERE id_customer_thread='. $ct->id;
Db::getInstance()->Execute($sql);
}
// adding (antadis) - linking reason and customer_thread // adding (antadis) - linking reason and customer_thread
if (Tools::getValue('id_reason')) { if (Tools::getValue('id_reason')) {
$id_reason = (int) Tools::getValue('id_reason'); $id_reason = (int) Tools::getValue('id_reason');

View File

@ -169,9 +169,15 @@ class ContactController extends ContactControllerCore {
if ($contact->customer_service) if ($contact->customer_service)
{ {
$ctStatusLast = false;
if ((int)$id_customer_thread) if ((int)$id_customer_thread)
{ {
$ct = new CustomerThread($id_customer_thread); $ct = new CustomerThread($id_customer_thread);
$ctStatusLast = $ct->status;
$ctStatusDate = $ct->date_upd;
$ct->status = 'open'; $ct->status = 'open';
$ct->id_lang = (int)self::$cookie->id_lang; $ct->id_lang = (int)self::$cookie->id_lang;
$ct->id_contact = (int)($id_contact); $ct->id_contact = (int)($id_contact);
@ -202,6 +208,12 @@ class ContactController extends ContactControllerCore {
if ($ct->id) if ($ct->id)
{ {
// Update date_upd to the last interesting date
if ($ctStatusLast !== false && $ctStatusLast == 'open') {
$sql = 'UPDATE `'._DB_PREFIX_.'customer_thread` SET `date_upd` = "'.$ctStatusDate.'" WHERE id_customer_thread='. $ct->id;
Db::getInstance()->Execute($sql);
}
$cm = new CustomerMessage(); $cm = new CustomerMessage();
$cm->id_customer_thread = $ct->id; $cm->id_customer_thread = $ct->id;
$cm->message = htmlentities($message, ENT_COMPAT, 'UTF-8'); $cm->message = htmlentities($message, ENT_COMPAT, 'UTF-8');