Jump to content

Back Office Order Comments No Longer in Order Page


Recommended Posts

Hello All,

 

To show order comments on order detail page in back office in 1.5.6.1 you all just need to do following steps and you will done with that i have implemented and tested well on prestashop 1.5.6.1.

 

1) Open CustomerThread.php file from classes folder and add following function just after function getNextThread.

public static function getCustomerMessagesByOrderId($id_order)
{
  $sql = 'SELECT ct.*,cm.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname
   FROM '._DB_PREFIX_.'customer_thread ct
   LEFT JOIN '._DB_PREFIX_.'customer_message cm
    ON ct.id_customer_thread = cm.id_customer_thread
   LEFT JOIN `'._DB_PREFIX_.'customer` c
    ON ct.`id_customer` = c.`id_customer`
   LEFT JOIN '._DB_PREFIX_.'employee e
    ON cm.id_employee = e.id_employee
   WHERE id_order = '.(int)$id_order.' ORDER BY cm.id_customer_message DESC';

  return Db::getInstance()->executeS($sql);
}

2) Open AdminOrdersController.php file from controllers/admin folder and replace this line ( line #1368 )

'messages' => Message::getMessagesByOrderId($order->id, true),

with this code

'messages' => CustomerThread::getCustomerMessagesByOrderId($order->id, true),

3) To show date and time both in messages open file view.tpl from your_Admin/themes/default/template/controllers/orders/helpers/view folder and change this line ( line # 780 )

{l s='At'} <i>{dateFormat date=$message['date_add']}

with this code

{l s='At'} <i>{$message['date_add']}

Follow these threes steps and Enjoy!!!

 

@divyeshp this code running well on 1.5.6.1

But when i try it on 1.5.6.2 there is still no customer message shows in backoffice order.

Could you tell us how to do it on 1.5.6.2

We all really appriciate it

 

Thanks

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

The solution works perfectly.

Thank you!

 

Hi,

 

if you don't want to give some money for displaying comments in orders page, i'll give you a solution.

It makes the display of the comments like prestashop < 1.5

 

Just modify the function of the Message class,

Replace the function getMessageByOrderId by this one (on line 91) :

 

public static function getMessagesByOrderId($id_order, $private = false, Context $context = null)
{
   if (!Validate::isBool($private))
    die(Tools::displayError());
  if (!$context)
   $context = Context::getContext();
  $m = Db::getInstance()->executeS('
   SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname,
   (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS 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` = '.(isset($context->employee) ? (int)$context->employee->id : '\'\'').'
   LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
   WHERE m.`id_order` = '.(int)$id_order.'
   '.(!$private ? ' AND m.`private` = 0' : '').'
   GROUP BY m.id_message
   ORDER BY m.date_add DESC
  ');
 
  $o = Db::getInstance()->executeS('
   SELECT ct.*, m.*, e.`firstname` AS efirstname, e.`lastname` AS elastname  
   FROM `'._DB_PREFIX_.'customer_thread` ct
   LEFT JOIN `'._DB_PREFIX_.'customer_message` m ON m.`id_customer_thread` = ct.`id_customer_thread`
   LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
   WHERE ct.`id_order` = '.(int)$id_order.'
   ORDER BY ct.`date_add` DESC'
  );
 
  return array_merge($o,$m);
 
}
Works fine

...and its free :)

 

 

Thank you it works also on PS1.5.6.2 much appreciated.

Link to comment
Share on other sites

  • 3 weeks later...

I have followed these instructions on PS 1.5.6.2 and it seems to be working.

Thanks guys for giving me a fix on this.

WWWWWWHHHHHYYYYYY would prestashop disable this function from something that was very useful in PS1.4.x

Beats my.

Thank GOD for the forum and you guys!

With Much appreciation. Nik

Hello All,

 

To show order comments on order detail page in back office in 1.5.6.1 you all just need to do following steps and you will done with that i have implemented and tested well on prestashop 1.5.6.1.

 

1) Open CustomerThread.php file from classes folder and add following function just after function getNextThread.

public static function getCustomerMessagesByOrderId($id_order)
{
  $sql = 'SELECT ct.*,cm.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname
   FROM '._DB_PREFIX_.'customer_thread ct
   LEFT JOIN '._DB_PREFIX_.'customer_message cm
    ON ct.id_customer_thread = cm.id_customer_thread
   LEFT JOIN `'._DB_PREFIX_.'customer` c
    ON ct.`id_customer` = c.`id_customer`
   LEFT JOIN '._DB_PREFIX_.'employee e
    ON cm.id_employee = e.id_employee
   WHERE id_order = '.(int)$id_order.' ORDER BY cm.id_customer_message DESC';

  return Db::getInstance()->executeS($sql);
}

2) Open AdminOrdersController.php file from controllers/admin folder and replace this line ( line #1368 )

'messages' => Message::getMessagesByOrderId($order->id, true),

with this code

'messages' => CustomerThread::getCustomerMessagesByOrderId($order->id, true),

3) To show date and time both in messages open file view.tpl from your_Admin/themes/default/template/controllers/orders/helpers/view folder and change this line ( line # 780 )

{l s='At'} <i>{dateFormat date=$message['date_add']}

with this code

{l s='At'} <i>{$message['date_add']}

Follow these threes steps and Enjoy!!!

Link to comment
Share on other sites

I have followed these instructions on PS 1.5.6.2 and it seems to be working.

Thanks guys for giving me a fix on this.

WWWWWWHHHHHYYYYYY would prestashop disable this function from something that was very useful in PS1.4.x

Beats my.

Thank GOD for the forum and you guys!

With Much appreciation. Nik

This was some what tricky but works fine anyway...

And many many thanks for using this..

One should have to ask moderators to include this in prestashop 1.5.x.y.

Edited by divyeshp (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hello All,

 

To show order comments on order detail page in back office in 1.5.6.1 you all just need to do following steps and you will done with that i have implemented and tested well on prestashop 1.5.6.1.

 

1) Open CustomerThread.php file from classes folder and add following function just after function getNextThread.

public static function getCustomerMessagesByOrderId($id_order)
{
  $sql = 'SELECT ct.*,cm.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname
   FROM '._DB_PREFIX_.'customer_thread ct
   LEFT JOIN '._DB_PREFIX_.'customer_message cm
    ON ct.id_customer_thread = cm.id_customer_thread
   LEFT JOIN `'._DB_PREFIX_.'customer` c
    ON ct.`id_customer` = c.`id_customer`
   LEFT JOIN '._DB_PREFIX_.'employee e
    ON cm.id_employee = e.id_employee
   WHERE id_order = '.(int)$id_order.' ORDER BY cm.id_customer_message DESC';

  return Db::getInstance()->executeS($sql);
}

2) Open AdminOrdersController.php file from controllers/admin folder and replace this line ( line #1368 )

'messages' => Message::getMessagesByOrderId($order->id, true),

with this code

'messages' => CustomerThread::getCustomerMessagesByOrderId($order->id, true),

3) To show date and time both in messages open file view.tpl from your_Admin/themes/default/template/controllers/orders/helpers/view folder and change this line ( line # 780 )

{l s='At'} <i>{dateFormat date=$message['date_add']}

with this code

{l s='At'} <i>{$message['date_add']}

Follow these threes steps and Enjoy!!!

Can I follow same procedure in prestashop 1.5.4.1?

Link to comment
Share on other sites

Yes for sure.

WHen I click on order, on top menu bo orders displays and each order have its own message, but PS 1,5.4.1 dont have any space for customer cmments line PS 149 has, I followed procedure you mentioned that way order page and customer page stop displayinh just a white page then. 

I want customer message to be displayed same way they are being displayed in 149 

Thanks a lot [spam-filter] in advance 

post-411458-0-08622900-1404369863_thumb.jpg

post-411458-0-07302600-1404369905_thumb.jpg

Edited by lovemyseo (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

I have followed these instructions on PS 1.5.6.2 and it seems to be working.

Thanks guys for giving me a fix on this.

WWWWWWHHHHHYYYYYY would prestashop disable this function from something that was very useful in PS1.4.x

Beats my.

Thank GOD for the forum and you guys!

With Much appreciation. Nik

Could you please send me Chstomerthread.php full source file by attachment using PS 1.5.6.2

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

Hi,

 

if you don't want to give some money for displaying comments in orders page, i'll give you a solution.

It makes the display of the comments like prestashop < 1.5

 

Just modify the function of the Message class,

Replace the function getMessageByOrderId by this one (on line 91) :

 

public static function getMessagesByOrderId($id_order, $private = false, Context $context = null)
{
   if (!Validate::isBool($private))
    die(Tools::displayError());
  if (!$context)
   $context = Context::getContext();
  $m = Db::getInstance()->executeS('
   SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname,
   (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS 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` = '.(isset($context->employee) ? (int)$context->employee->id : '\'\'').'
   LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
   WHERE m.`id_order` = '.(int)$id_order.'
   '.(!$private ? ' AND m.`private` = 0' : '').'
   GROUP BY m.id_message
   ORDER BY m.date_add DESC
  ');
 
  $o = Db::getInstance()->executeS('
   SELECT ct.*, m.*, e.`firstname` AS efirstname, e.`lastname` AS elastname  
   FROM `'._DB_PREFIX_.'customer_thread` ct
   LEFT JOIN `'._DB_PREFIX_.'customer_message` m ON m.`id_customer_thread` = ct.`id_customer_thread`
   LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
   WHERE ct.`id_order` = '.(int)$id_order.'
   ORDER BY ct.`date_add` DESC'
  );
 
  return array_merge($o,$m);
 
}
Works fine

...and its free :)

 

 

 

hoplajetzt solution works but the messages displays the date without the time. This makes the messages sort in random order when both messages occur during the same day.

 

Any fix?

1. Solved.

2. Just replace return array_merge($o,$m); with return array_merge($o);

Link to comment
Share on other sites

I tested hoplajetzt's version in Prestashop 1.6.0.9 without any return array_merge fixes and it's working fine.

 

 

Is there any way to display timestamp and sort by it?

 

Thanks

 

Have tested it on PS 1.6.0.9 and it shows messages in descending order by date.

 

Can you explain better what you want?

Link to comment
Share on other sites

Yeap, that's true... Messages show in desc. order by date, but if you send couple of messages during the day they will be shown in a random order. Is it possible to sort them in chronological order - by date and time?

 

Hi,

 

I have used this code in classes/CustomerThread.php

$sql = 'SELECT ct.*,cm.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname
FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'customer_message cm
ON ct.id_customer_thread = cm.id_customer_thread
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON ct.`id_customer` = c.`id_customer`
LEFT JOIN '._DB_PREFIX_.'employee e
ON cm.id_employee = e.id_employee
WHERE id_order = '.(int)$id_order.' ORDER BY cm.id_customer_message DESC';

Then in controllers/admin/AdminOrdersController.php

change this line:

'messages' => Message::getMessagesByOrderId($order->id, true),

with this one:

'messages' => CustomerThread::getCustomerMessagesByOrderId($order->id, true),

after that go to .tpl file in adminFolder/themes/default/template/controllers/orders/helpers/view and change this line

{dateFormat date=$message['date_add']}

with this one:

{$message['date_add']}

And you are done!

Link to comment
Share on other sites

 

i get this error in order i use 1.5.6.2

 

Notice: Undefined index: is_new_for_me in/var/www/prestashop/cache/smarty/compile/fc/bd/a1/fcbda1d5741ea53f4d8add89f15f7105f0a74762.file.view.tpl.phpon line 1271

Notice: Undefined index: is_new_for_me in/var/www/prestashop/cache/smarty/compile/fc/bd/a1/fcbda1d5741ea53f4d8add89f15f7105f0a74762.file.view.tpl.phpon line 1272

 

 

<div style="overflow:auto; width:400px;" <?php if ($_smarty_tpl->tpl_vars['message']->value['is_new_for_me']){?>class="new_message"<?php }?>>

<?php if (($_smarty_tpl->tpl_vars['message']->value['is_new_for_me'])){?>

 

This error is pretty innocent as I understand. If it bugs you and you want to get rid of it simply change the following code in admin/themes/default/template/controllers/orders/helpers/view/view.tpl

<div style="overflow:auto; width:400px;" {if $message['is_new_for_me']}class="new_message"{/if}>
	{if ($message['is_new_for_me'])}
	<a class="new_message" title="{l s='Mark this message as \'viewed\''}" href="{$smarty.server.REQUEST_URI}&token={$smarty.get.token}&messageReaded={$message['id_message']}"><img src="../img/admin/enabled.gif" alt="" /></a>
	{/if}

to just one line:

<div style="overflow:auto; width:400px;">

I think Prestashop wants to show you if a message is new and give you ability to mark it as read. Divyesh's getCustomerMessagesByOrderId function which overrides the original getMessagesByOrderId function however does not pull this kind of information from the database. So you do not have 'is_new_for_me' element in $message array.

 

Divyesh's solution also has another side effect. If you create an order from the BO you no longer see the 'Manual Order' message on the order page which is a minor inconvenience compared to no messages at all.

Edited by gkorolkov (see edit history)
Link to comment
Share on other sites

  • 8 months later...

Hi,

 

if you don't want to give some money for displaying comments in orders page, i'll give you a solution.

It makes the display of the comments like prestashop < 1.5

 

Just modify the function of the Message class,

Replace the function getMessageByOrderId by this one (on line 91) :

 

public static function getMessagesByOrderId($id_order, $private = false, Context $context = null)
{
   if (!Validate::isBool($private))
    die(Tools::displayError());
  if (!$context)
   $context = Context::getContext();
  $m = Db::getInstance()->executeS('
   SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname,
   (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS 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` = '.(isset($context->employee) ? (int)$context->employee->id : '\'\'').'
   LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
   WHERE m.`id_order` = '.(int)$id_order.'
   '.(!$private ? ' AND m.`private` = 0' : '').'
   GROUP BY m.id_message
   ORDER BY m.date_add DESC
  ');
 
  $o = Db::getInstance()->executeS('
   SELECT ct.*, m.*, e.`firstname` AS efirstname, e.`lastname` AS elastname  
   FROM `'._DB_PREFIX_.'customer_thread` ct
   LEFT JOIN `'._DB_PREFIX_.'customer_message` m ON m.`id_customer_thread` = ct.`id_customer_thread`
   LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
   WHERE ct.`id_order` = '.(int)$id_order.'
   ORDER BY ct.`date_add` DESC'
  );
 
  return array_merge($o,$m);
 
}
Works fine

...and its free smile.png

 

 

Just PERFECT !!! works like a charm on 1.6.0.6

Link to comment
Share on other sites

  • 1 month later...

Thanks for the fix suggestion, I think this is slightly improved version:

  • Defaults to 0 as is_new_for_me to prevent warnings
  • Does not return private messages when asked for not private messages
  public static function getMessagesByOrderId($id_order, $private = false, Context $context = null)
  {
    if (!Validate::isBool($private))
      die(Tools::displayError());

    if (!$context)
      $context = Context::getContext();

    $messages = Db::getInstance()->executeS('
      SELECT m.*, c.`firstname` AS cfirstname, c.`lastname` AS clastname, e.`firstname` AS efirstname, e.`lastname` AS elastname,
      (COUNT(mr.id_message) = 0 AND m.id_customer != 0) AS 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` = '.(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' : '').'
      GROUP BY m.id_message
      ORDER BY m.date_add DESC
    ');

    $customer_messages = Db::getInstance()->executeS('
      SELECT ct.*, m.*, e.`firstname` AS efirstname, e.`lastname` AS elastname, 0 as is_new_for_me
      FROM `'._DB_PREFIX_.'customer_thread` ct
      LEFT JOIN `'._DB_PREFIX_.'customer_message` m ON m.`id_customer_thread` = ct.`id_customer_thread`
      LEFT OUTER JOIN `'._DB_PREFIX_.'employee` e ON e.`id_employee` = m.`id_employee`
      WHERE ct.`id_order` = '.(int)$id_order.'
      '.(!$private ? ' AND m.`private` = 0' : '').'
      ORDER BY ct.`date_add` DESC'
    );

    return array_merge($customer_messages, $messages);
  }

Link to comment
Share on other sites

  • 1 month later...

This error is pretty innocent as I understand. If it bugs you and you want to get rid of it simply change the following code in admin/themes/default/template/controllers/orders/helpers/view/view.tpl

<div style="overflow:auto; width:400px;" {if $message['is_new_for_me']}class="new_message"{/if}>
	{if ($message['is_new_for_me'])}
	<a class="new_message" title="{l s='Mark this message as \'viewed\''}" href="{$smarty.server.REQUEST_URI}&token={$smarty.get.token}&messageReaded={$message['id_message']}"><img src="../img/admin/enabled.gif" alt="" /></a>
	{/if}

to just one line:

<div style="overflow:auto; width:400px;">

I think Prestashop wants to show you if a message is new and give you ability to mark it as read. Divyesh's getCustomerMessagesByOrderId function which overrides the original getMessagesByOrderId function however does not pull this kind of information from the database. So you do not have 'is_new_for_me' element in $message array.

 

Divyesh's solution also has another side effect. If you create an order from the BO you no longer see the 'Manual Order' message on the order page which is a minor inconvenience compared to no messages at all.

 

 

Hello

 

i have the same problem with "Undefined index: is_new_for_me in /var/www/web56/web/cache/smarty/compile/a1/a9/e6/dfdfsdfdf.file.view.tpl.php on line 1272"

and debug mode is not on "ON"

 

this solution is very safe ?

Link to comment
Share on other sites

  • 1 month later...

I've been trying to get this to work on 1.6.1.2 but I keep getting a 500 error.  I have tried the latest modifications and also the older ones.  No luck.  Anyone get this working on the latest PS version?  I have been using this modification up until my last upgrade.  I love it.  Wish it was a standard feature in PS.

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

Hi everyone,

 

Thank you for all the information posted here, it is very helpful.

I have tested this with 1.6.1.4 and it works great, but I get this error:

Notice on line 1192 in file /home/bocaneco/public_html/cache/smarty/compile/ef/3c/7e/ef3c7e30d88cef3b70b50e2cfd830cdcdc226dda.file.view.tpl.php
[8] Undefined index: cfirstname

Notice on line 1193 in file /home/bocaneco/public_html/cache/smarty/compile/ef/3c/7e/ef3c7e30d88cef3b70b50e2cfd830cdcdc226dda.file.view.tpl.php
[8] Undefined index: clastname

I have copied GL's code into Message.php replacing the original function and also added the code to view.tpl and I have debug mode ON and cache off.

If anyone could help, I would appreciate it very much.

 

Also, the first message gets inserted twice, both in the beginning and the end. Could this be fixed?

 

 

 

Thank you!

 

post-303912-0-82411400-1458143178_thumb.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...