4 August 2012

Customer Messages on BO Index v1.5

Adds a list of latest customer messages on the BO index page.
#
#----------[ OPEN ]----------
#
admin/tabs/AdminHome.php

#
#----------[ FIND ]----------
#
 echo '
   </tbody>
  </table>

#
#----------[ AFTER, ADD ]----------
#
  <br />

  <table cellpadding="0" cellspacing="0" id="table_customer">
   <thead>
    <tr>
     <th class="order_id"><span class="first">'.translate('ID').'</span></th>
     <th class="order_date"><span>'.translate('Date').'</span></th>
     <th class="order_customer"><span>'.translate('Customer').'</span></th>
     <th class="order_status"><span>'.translate('Message').'</span></th>
     <th class="order_action"><span class="last">'.translate('Action').'</span></th>
    <tr>
   </thead>
   <tbody>';
 
 $messages = Message::getLastMessages(10);
 $i = 0;
 foreach ($messages AS $message)
 {
  echo '
     <tr'.($i % 2 ? ' id="order_line1"' : '').($message['is_new_for_me'] ?' class="new_message"' : '').'>
     <td class="order_td_first order_id">'.(int)$message['message_id'].'</td>
     <td class="order_date">'.$message['added'].'</td>
     <td class="order_customer">'.Tools::htmlentitiesUTF8($message['firstname']).' '.Tools::htmlentitiesUTF8($message['lastname']).'</td>
     <td class="order_status" width="50%">'.nl2br2($message['message']).'</td>
     <td class="order_action">
     '.($message['is_new_for_me'] ? '<a class="new_message" title="'.$this->l('Mark this message as \'viewed\'').'" href="index.php?tab=AdminOrders&id_order='.(int)$message['id_order'].'&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'&messageReaded='.(int)($message['message_id']).'"><img src="../img/admin/enabled.gif" alt="'.$this->l('Mark this message as \'viewed\'').'" /></a>&nbsp;' : '').'
     <a href="index.php?tab=AdminOrders&id_order='.(int)$message['id_order'].'&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'" title="'.translate('Details').'"><img src="../img/admin/details.gif" alt="'.translate('Details').'" /></a>
     </td>
    </tr>
   ';
  $i++;
 }
  
 echo '</tbody>
 </table>
#
#----------[ OPEN ]----------
#
classes/Message.php

#
#----------[ FIND ]----------
#
  ('.(int)($id_message).', '.(int)($id_employee).', NOW());
  ');
  return $result;
 }

#
#----------[ AFTER, ADD ]----------
#
 /**
   * Return last messages
   */
public static function getLastMessages($limit = NULL)
 {
  global $cookie;

  return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
   SELECT *, m.`id_message` message_id, m.`date_add` added, c.`firstname`, c.`lastname`, (COUNT(mr.`id_message`) = 0 AND m.`id_customer` != 0) is_new_for_me
   FROM `'._DB_PREFIX_.'message` m
   LEFT JOIN `'._DB_PREFIX_.'customer` c ON m.`id_customer` = c.`id_customer`
   LEFT JOIN `'._DB_PREFIX_.'message_readed` mr ON (mr.`id_message` = m.`id_message` AND mr.`id_employee` = '.(int)$cookie->id_employee.')
   WHERE m.`private` = 0 
   AND m.`id_customer` > 0
   AND m.`id_order` != 0
   GROUP BY m.`id_message`
   ORDER BY m.`date_add` DESC
   '.((int)$limit ? 'LIMIT 0, '.(int)$limit : ''));
 }
CHANGELOG:
v1.5 (2012-08-04)
[*] Changed ID to Order ID (id_order).
[*] Updated table row class to match changes in PS 1.4.9.0.
v1.4 (2012-03-23)
[*] Only display messages from orders (not carts).
v1.3 (2012-01-20)
[+] Added highlighted unread message format.
[+] Added ability to mark message as read.
v1.2 (2011-05-22)
[*] Fixed message formatting with special characters.
[*] Removed table width changes.
v1.1 (2011-03-10)
[*] Updated for new PS 1.4 AdminHome file.
[*] Fixed action icon if message not attached to an order.
v1.0 (2011-01-30)
[+] First release to the PrestaShop community.

2 comments:

  1. Hello, this is a good modifikation!
    Thank you. Cane you make the self for the tab=AdminCustomerThread also the Messages over the contactform, so that display on home tab?

    So we have all Messages on hometab =)

    That nice

    ReplyDelete