Jump to content
Pressed0024

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

Share this post


Link to post
Share on other sites

Got it working in 1.4.9.1. It doesn't seem to work now in 1.5.6.1. Any idea?

But my prestashop 1.5.6.2 old comment not display this code.new comment display very well..

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

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!!!

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

Yes for sure.

 

Yes for sure.

Could you please paste the full code for CustomerThread.php may be I am putting code at wrong place 

Share this post


Link to post
Share on other sites

Worked!

 

I replaced the codes in the file /classes/Message.php

 

Thanks.

Could you please send me your Message.php code file or show me full code here it didnt work on Prestashop 1.5.6.2

Share this post


Link to post
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

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

Share this post


Link to post
Share on other sites

In PS 1.6.0.6 is OK... but in newest 1.6.0.9 I heve error on order page: Fatal error: Call to undefined method CustomerThread::getCustomerMessagesByOrderId()

 

How to fix it?

Share this post


Link to post
Share on other sites

Everyone having "Undefined index: is_new_for_me" make sure you have made ALL the modifications to view.tpl, CustomerThread.php, AdminOrdersController.php and not just Message.php

 

Regards.

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites

 

 

 

1. Solved.

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

 

Which version of prestashop was this tested on?

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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?

Share this post


Link to post
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!

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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);
  }

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Hi,

 

It's an old post but i want to say many thanks to all and confirm that working for PS 1.6.1.3 with the GL-'s code.

 

Ckarone

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More