Jump to content

[Free Code] Customer Message at end of Invoice PDF


Recommended Posts

Ok so I hunted everywhere and I could not find it on any forums, so I paid someone on Upwork to do it for me, use it if it helps you.

All this does is take the customer message from the order process, and add it to the Invoice so my packers will be able to take note of any special requests.

I am using this code on Prestashop 1.7.5.1

In /classes/order/OrderInvoice.php file and add the following code in line 179

if( end($products) === $row ) {
$row['first_order_message'] = nl2br($order->getFirstMessage());
}

In pdf/invoice.product-tab.tpl file add this to the end

<!-- Customer Order Message -->
<br/>

{if isset($order_detail.first_order_message) && $order_detail.first_order_message}

<table class="product" width="100%" cellpadding="4" cellspacing="0" style="margin-top: 10px">
<thead>
<tr class="product" style="width: 100%">
<th class="product header small" width="100%">{l s='Customer Message' d='Shop.Pdf' pdf='true'}</th>
</tr>
</thead>
<tbody>
<tr class="product left {$bgcolor_class}" style="width: 100%">
{foreach $order_details as $order_detail}
<td class="product left">
{$order_detail.first_order_message}
</td>
{/foreach}
</tr>
</tbody>
</table>
{/if}
<!-- Customer Order Message -->

If you want to buy me a coffee, here's the link: https://www.paypal.me/jeremyko88

Cheers! 

Share this post


Link to post
Share on other sites
  • 5 months later...

\classes\order\OrderInvoice.php

 

    public function getProducts($products = false, $selected_products = false, $selected_qty = false)
    {
        if (!$products) {
            $products = $this->getProductsDetail();
        }
        $order = new Order($this->id_order);
        $customized_datas = Product::getAllCustomizedDatas($order->id_cart);
			
        $result_array = array();
        foreach ($products as $row) {
					// hack start
			if( end($products) === $row ) { 
			$row['first_order_message'] = nl2br($order->getFirstMessage());
			$CustomerThread_messagelar = CustomerMessage::getMessagesByOrderId($order->id, $private = false); 	// last Customer Message private = false
			$row['CustomerThread_message'] = $CustomerThread_messagelar[0][message];							// last Customer Message		

		 // 	ddd($CustomerThread_message);

			}


in invoice.tpl 

{$order_detail.CustomerThread_message}

 

Edited by behcet (see edit history)

Share this post


Link to post
Share on other sites

Hello, I have a problem with the conditional that controls if there are messages, without  that conditional works for me perfect:
 

<!--
		{if isset($order_details.first_order_message) && $order_detail.first_order_message} -->
			<td width="40%"><span class="bold">Mensaje Pedido</span><br/><br/>
				{foreach $order_details as $order_detail}
					<span id="mensajefacturas" >{$order_detail.first_order_message}</span>
				{/foreach}
			</td>
	<!--
		{/if}-->

Thanks for the code

Share this post


Link to post
Share on other sites
  • 1 month later...

Hello dev, I have an issue. If the order is one product then the customer message appears in the invoice. If the products are more than one then I have a blank customer message.

Any ideas why that is happening?

 

Kind Regards,

Share this post


Link to post
Share on other sites
  • 2 months later...
On 7/2/2019 at 4:33 AM, germinc said:

Ok so I hunted everywhere and I could not find it on any forums, so I paid someone on Upwork to do it for me, use it if it helps you.

All this does is take the customer message from the order process, and add it to the Invoice so my packers will be able to take note of any special requests.

I am using this code on Prestashop 1.7.5.1

In /classes/order/OrderInvoice.php file and add the following code in line 179


if( end($products) === $row ) {
$row['first_order_message'] = nl2br($order->getFirstMessage());
}

In pdf/invoice.product-tab.tpl file add this to the end


<!-- Customer Order Message -->
<br/>

{if isset($order_detail.first_order_message) && $order_detail.first_order_message}

<table class="product" width="100%" cellpadding="4" cellspacing="0" style="margin-top: 10px">
<thead>
<tr class="product" style="width: 100%">
<th class="product header small" width="100%">{l s='Customer Message' d='Shop.Pdf' pdf='true'}</th>
</tr>
</thead>
<tbody>
<tr class="product left {$bgcolor_class}" style="width: 100%">
{foreach $order_details as $order_detail}
<td class="product left">
{$order_detail.first_order_message}
</td>
{/foreach}
</tr>
</tbody>
</table>
{/if}
<!-- Customer Order Message -->

If you want to buy me a coffee, here's the link: https://www.paypal.me/jeremyko88

Cheers! 

Thanks for sharing this information, I have followed your guide but the message does not appear in the pdf in PS_1.7.5.1
Can you share the two files?

Thanks in advance

Share this post


Link to post
Share on other sites
  • 6 months later...

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

Important Information

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