Jump to content

Show order note in invoice PDF


dmo@hispeed.ch

Recommended Posts

 It's not a pretty solution but it works...

You could create a variable inside the invoice template (bad practice but I'm lazy) like: 

{$customer_messages = CustomerMessage::getMessagesByOrderId($order->id)}
{$my_message = ''}
{if $customer_messages}
  {foreach from=$customer_messages item=customer_message}
    {if $customer_message.id_employee}
      {$my_message = $customer_message.message}
      {break}
    {/if}
  {/foreach}
{/if}

This will get the newest note that you have entered onto the order, but will not display messages left by the customer.

Then wherever you want the message to display, just call the variable...

{$my_message}

Like I said it's a sloppy way to do it but that's how I roll 🤣

Link to comment
Share on other sites

Dear @lordignus
Thank you very much for your reply. I find it the best solution. Whether beautiful or not. It may make invoice generation a bit slower. But I don't see any other solution. It would be nice to pack the whole thing into a module and write it on the invoice via HOOK_DISPLAY_PDF.

My code now looks like this (writen direct in invoice.tpl):

{$msgs = CustomerMessage::getMessagesByOrderId($order_invoice->id_order)}
	{if $msgs|@count > 0} 
		<tr>
			<td colspan="12" height="10">&nbsp;</td>
		</tr>

		<tr>
			<td colspan="12" >
			<table id="note-tab" style="width: 100%">
					<thead>
						<tr>
							<th class=" header small">{l s='Note' d='Shop.Pdf' pdf='true'}</th>
						</tr>
					</thead>
					<tbody>
						{foreach $msgs as $msg}
							{cycle values=["color_line_even", "color_line_odd"] assign=bgcolor_class}
							<tr class="{$bgcolor_class}">
								<td class="center">{$msg.message|escape:'html':'UTF-8'|nl2br}</td>
							</tr>
						{/foreach}
					</tbody>
				</table>
			</td>
		</tr>
	{/if}

Have a nice day.

Daniel

  • Thanks 1
Link to comment
Share on other sites

  • 9 months later...

Hi,

I would really need this feature in one of my shops, which files did you guys edit more precisely?

Anyone that could make an "official solution", I would gladly pay! A code snipped that works for 8.1.2 and upcoming version 9 etc.

Best regards,

Link to comment
Share on other sites

  • 6 months later...

This also works for 8.1.2. I've just tested.

thank you so much for sharing :)

 

open file invoice.tpl inside public_html\pdf

 

i've put the code on line 109, right under the code

            {$shipping_tab}

        </td>
        <td colspan="1">&nbsp;</td>
    </tr>

 

 

hope this helps you too :)

Link to comment
Share on other sites

  • 1 month later...

It's not a perfect solution, though.

there are 22 PHP notice lines in the error_log every time there's a new order.

PHP Notice:  Undefined index: startcolumn in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19649
PHP Notice:  Undefined index: startx in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19650
PHP Notice:  Undefined index: startpage in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19653
PHP Notice:  Undefined index: startpage in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19656
PHP Notice:  Undefined index:  in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19656
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19656
PHP Notice:  Undefined index: startpage in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19657
PHP Notice:  Undefined index:  in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19657
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19657
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 2468
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 2468
PHP Notice:  Undefined index: startcolumn in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19649
PHP Notice:  Undefined index: startx in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19650
PHP Notice:  Undefined index: startpage in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19653
PHP Notice:  Undefined index: startpage in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19656
PHP Notice:  Undefined index:  in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19656
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19656
PHP Notice:  Undefined index: startpage in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19657
PHP Notice:  Undefined index:  in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19657
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 19657
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 2468
PHP Notice:  Trying to access array offset on value of type null in /home/XXXX/public_html/vendor/tecnickcom/tcpdf/tcpdf.php on line 2468

 

And all messages get on the invoice instead of just the first one.

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