Jump to content

[Free Code] Customer Message at end of Invoice PDF


germinc

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! 

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

Link to comment
Share on other sites

  • 1 month later...
  • 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

Link to comment
Share on other sites

  • 6 months later...
  • 5 months later...
  • 4 weeks later...
On 1/1/2020 at 6:35 PM, behcet said:

 




        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	

		}

 

You are retrieving the same message inside the products loop... the message should only be retrieved once and outside the loop.

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

Do not put it in the product line!
I put it in the top right, below the date line.

in invoice.tpl

	<td style="font-size: 9pt; width: 35%;"> 
											<br /><span>{$carrier->name}</span>
											<br /><span>{foreach from=$order_invoice->getOrderPaymentCollection() item=payment}
											{$payment->payment_method} : {displayPrice currency=$payment->id_currency price=$payment->amount}
											{/foreach}
											</span>
											<span>	
											{foreach $order_details as $order_detail}{/foreach}
											<br />Not:{$order_detail.first_order_message} 
											<br />
											{if $order_detail.CustomerThread_message != $order_detail.first_order_message}
												Not:{$order_detail.CustomerThread_message}
											{/if} 
											</span>
	</td>

 

 

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

Because you are retrieve the same message over and over. Don't you see you are fetching the message inside a loop? This is your code:

foreach ($products as $row) {
  // fetching message
}

// you should fetch message HERE

Never mind... I see you have an if in there to check that is is the last row.. still it would be a lot cleaner to have it outside. 

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

  • 1 year 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...