diff --git a/adm/tabs/AdminCustomerThreads.php b/adm/tabs/AdminCustomerThreads.php index 08f39104..4af7f1a2 100755 --- a/adm/tabs/AdminCustomerThreads.php +++ b/adm/tabs/AdminCustomerThreads.php @@ -38,17 +38,21 @@ class AdminCustomerThreads extends AdminTab $this->view = 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, ( - SELECT IFNULL(CONCAT(LEFT(e.firstname, 1),". ",e.lastname), "--") - 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->_select = ' + CONCAT(c.firstname, " ", c.lastname) as customer, cl.name as contact, + l.name as language, group_concat(message) as messages, + (SELECT IFNULL(CONCAT(LEFT(e.firstname, 1), ". ", e.lastname), "--") + 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->_join = ' - 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_.'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_.'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_.'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.')'; $contactArray = array(); $contacts = Contact::getContacts($cookie->id_lang); diff --git a/modules/ant_support_form/support.php b/modules/ant_support_form/support.php index 91fe913a..cbdb106c 100644 --- a/modules/ant_support_form/support.php +++ b/modules/ant_support_form/support.php @@ -173,9 +173,15 @@ if (Tools::isSubmit('submitMessage')) { if ($contact->customer_service) { + $ctStatusLast = false; + if ((int)$id_customer_thread) { $ct = new CustomerThread($id_customer_thread); + + $ctStatusLast = $ct->status; + $ctStatusDate = $ct->date_upd; + $ct->status = 'open'; $ct->id_lang = (int)$cookie->id_lang; $ct->id_contact = (int)($id_contact); @@ -213,6 +219,12 @@ if (Tools::isSubmit('submitMessage')) { 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 if (Tools::getValue('id_reason')) { $id_reason = (int) Tools::getValue('id_reason'); diff --git a/override/controllers/ContactController.php b/override/controllers/ContactController.php index ed58ea85..b32b1391 100755 --- a/override/controllers/ContactController.php +++ b/override/controllers/ContactController.php @@ -169,9 +169,15 @@ class ContactController extends ContactControllerCore { if ($contact->customer_service) { + $ctStatusLast = false; + if ((int)$id_customer_thread) { $ct = new CustomerThread($id_customer_thread); + + $ctStatusLast = $ct->status; + $ctStatusDate = $ct->date_upd; + $ct->status = 'open'; $ct->id_lang = (int)self::$cookie->id_lang; $ct->id_contact = (int)($id_contact); @@ -202,6 +208,12 @@ class ContactController extends ContactControllerCore { 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->id_customer_thread = $ct->id; $cm->message = htmlentities($message, ENT_COMPAT, 'UTF-8');