Jump to content

Add Customer Messages in PDF Delivery Slip


Recommended Posts

I'm trying to add to the PDF Delivery Slip the Message that a customer send during checkout.

Table `ps_message` field `message` selecting the message for that `id_order` with the earliest date.

 

The query look like the second code here, but I dont know how to make it into a usable variable for the pdf:

$order = new Order(intval($_GET["id_order"]));

SELECT `ps_message`.`message`, MIN(`ps_message`.`date_add`) AS DateTime
FROM ps_message
WHERE `ps_message`.`id_order` =$order

 

Any clues?

Link to comment
Share on other sites

I would use the Message class. The following will return all the public messages for the supplied order, in date descending order.

 

$result = Message::getMessagesByOrderId($order->id)

 

So you would just have to take the last order returned in $result

Link to comment
Share on other sites

if this is something you would like me to create for you, just send me a PM with the version of Prestashop that you use, as well as a sample PDF document showing where you would like the message to appear.

 

I do charge for my services, so we can discuss that in the PM.

Link to comment
Share on other sites

Yes that checkbox would be very useful. The first message carries the specific instructions for the order. The rest of the customer message history is usually not very relevant to preparing the package.

 

Since you are asking about additional features, May I suggest adding a checkbox to display customer messages only on the "Delivery Slip" The reason being is that an Invoice is an accounting instrument and should not display these messages, but the messages on the "Delivery Slip" will help in preparing the package.

 

Is there a way I can manually hook the messages ONLY to the Delivery Slip and not the invoice?

Link to comment
Share on other sites

  • 1 month later...

I would like to show the customer message on the Shopping Cart Summary Page (shopping-cart.tpl)?

 

Is there a Smarty variable that I can expose in the template?

 

I tried

 

{if isset($oldMessage)}{$oldMessage}{/if}

 

But didnt work.

 

Sorry, it doesn't work that way. It hooks only into PDFs

 

Your idea could be a subject of a new module.

Link to comment
Share on other sites

I would like to show the customer message on the Shopping Cart Summary Page (shopping-cart.tpl)?

 

Is there a Smarty variable that I can expose in the template?

 

I tried

 

{if isset($oldMessage)}{$oldMessage}{/if}

 

But didnt work.

 

The ParentOrderController.php does this, so you could probably add this or something similar to CartController.php so that your template change would work

 

   	 if ($oldMessage = Message::getMessageByCartId((int)(self::$cart->id)))
           self::$smarty->assign('oldMessage', $oldMessage['message']);

Link to comment
Share on other sites

  • 1 month later...

Is there a way to add the customer message to the order confirmation email?

I am using the message text box as a way for customers to add information about their prefered delivery

times so it would be useful to have that on the order confirmation also.

 

Is there a smarty variable like {message} that can be simply added to the email templates?

Link to comment
Share on other sites

  • 2 weeks later...

Just bought this module, and it doesn't work!!!

Module is installed, configurated, but PDFs are not affected.

Prestashop 1.4.8.2

 

Did you fill in the "Title of the delivery slip in your language(s):" fields in the configuration?

Link to comment
Share on other sites

This modules has only satisfied customers so far.

 

I contacted enagen to detect the problem.

 

Yes I already like all your products :) I'm sure you'll get the bug fixed and then I'll download asap

 

The theme maker i'm looking forward to cause I could use it on a site I'm working on now!

Link to comment
Share on other sites

Thanks Andrej!! Works perfect now! Prestashop 1.4.8.2

I wish to know what was the problem, please email me or post it! :)

Thanks a lot!! very nice support service!

 

The problem was in the main titles:

Title of the delivery slip in your language(s):

 

Title of the invoice in your language(s):

 

 

They were not filled out correctly - it is described in the documentation which is included in the ZIP

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

  • 5 months later...
  • 5 months later...
  • 2 months later...
  • 4 weeks later...
  • 11 months later...
  • 1 year later...

Sorry, it doesn't work that way. It hooks only into PDFs

 

Your idea could be a subject of a new module.

Do you have module for latest version of PS i,e 1.6.1.5 ? aso will it allow to add custom message by shop owner? on invoice and delivery slips?

Link to comment
Share on other sites

  • 5 months later...
  • 4 months later...
  • 6 years later...

I know this is a long time after the original question and answers presented then, but for those folks who are STILL running PS 1.6.x Maybe this code will be of assistance (because Prestashop documentation is really useless).

I will not upload the php or template files because at this point, either YOU need to learn how to do these minor modifications, or your developer does, so here are the instructions:

Step 1: Copy your /classes/pdf/HTMLTemplateDeliverySlip.php file to the override folders at /override/classes/pdf/HTMLTemplateDeliverySlip.php
(this is the easiest way to get there if you are new to php object oriented programming)

Step 2: Search for the following line in that file: 

$carrier = new Carrier($this->order->id_carrier);

Step 3: Modify the code to read like this:

/* following line retrieves Customer Order Message */
$customer_message = $this->order->getFirstMessage();
		
$carrier = new Carrier($this->order->id_carrier);

Step 4: Find this block of code:

        $this->smarty->assign(array(
            'order' => $this->order,
            'order_details' => $order_details,
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'order_invoice' => $this->order_invoice,
            'carrier' => $carrier,
            'display_product_images' => Configuration::get('PS_PDF_IMG_DELIVERY')
        ));

Step 5: Modify the code to read like this:

        $this->smarty->assign(array(
            'order' => $this->order,
            'order_details' => $order_details,
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'order_invoice' => $this->order_invoice,
            'carrier' => $carrier,
            'message' => $customer_message, /* adds customer_message to smarty variables */
            'display_product_images' => Configuration::get('PS_PDF_IMG_DELIVERY')
        ));

Step 6: Find this block of code (right after the last one):

        $tpls = array(
            'style_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.product-tab')),
            'payment_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.payment-tab')),
        );

Step 7: Modify the code to read like this:

        $tpls = array(
            'style_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.style-tab')),
            'addresses_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.addresses-tab')),
            'summary_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.summary-tab')),
            'product_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.product-tab')),
            'payment_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.payment-tab')),
            /* creates a template file to display the customer_message in on the form */
            'message_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.message-tab')),
        );

Save changes and this file is ready to upload to your /override/classes/pdf/ folder AFTER you have completed the following files AND uploaded them. (If you are working on a non-live site, the order that you upload the files doesn't really matter.)

A quick comment: It is absolutely true that you do not need to include the comment lines that describe the changes being made - however, it is my opinion that you should - because somewhere down the line might want to know what you changed, and if you don't work with this code on a daily basis, sometimes even if you do, these comments can provide critical information to refresh your memory why those changes are there, or in the cases of new methods, etc. the parameters and other information expected by the method.

We're not quite finished yet, so moving on...

Step 8: Create a /pdf/delivery-slip.message-tab.tpl file to setup your message display within the pdf template with the following content:

{*
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2015 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*
*  @author Obewan <obewanz@yahoo.com>
* This is a private modification to prestashop 1.6.x to add the customer order message to the generated pdf delivery slip document.
*
*}
<table id="message-tab" width="100%" cellpadding="4" cellspacing="0">
	<tr>
		<td class="message center small grey bold" width="44%">{l s='Order Message' pdf='true'}</td>
		<td class="message left white" width="56%">
			{$message|escape:'html':'UTF-8'|nl2br}
		</td>
	</tr>
</table>

Comments: There are a number of ways to effect this output, but I felt this not only gave you more information on how to modify pdf generated output for other possible future needs, it also tends to provide a much cleaner solution in the end as it leverages the template system to set this apart from the rest of the form code.

Note: You can ALSO place this same file in your /themes/your-theme-name/pdf/ folder to lessen the possibility of it getting overridden as there is no provision made to create overrides for template files in Prestashop 1.6.x.

Step 9: COPY your /pdf/delivery-slip.tpl file to something like "/pdf/delivery-slip-replaced.tpl (you will use this file to restore your pdf generation template if things go wrong!

Step 10: Search for the following code in the /pdf/delivery-slip.tpl file:

	<tr>
		<td colspan="7" class="left">

			{$payment_tab}

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

	<!-- Hook -->
	{if isset($HOOK_DISPLAY_PDF)}
	<tr>
		<td colspan="12" height="30">&nbsp;</td>
	</tr>

	<tr>
		<td colspan="2">&nbsp;</td>
		<td colspan="10">
			{$HOOK_DISPLAY_PDF}
		</td>
	</tr>
	{/if}

Step 11: Modify the code to read like this:

	<tr>
		<td colspan="7" class="left">

			{$payment_tab}

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

	{* -- load message tab and display order message if one exists -- *}
	{if isset($message)} 
	<tr>
		<td colspan="7" class="left">
		{$message_tab}
		</td>
		<td colspan="5">&nbsp;</td>
	</tr>
	{/if}

	<!-- Hook -->
	{if isset($HOOK_DISPLAY_PDF)}
	<tr>
		<td colspan="12" height="30">&nbsp;</td>
	</tr>

	<tr>
		<td colspan="2">&nbsp;</td>
		<td colspan="10">
			{$HOOK_DISPLAY_PDF}
		</td>
	</tr>
	{/if}

Comments: I used the smarty comment method to indicate where the new code insert begins, I could just have easily used html comments as those that already appear in the above code snippet. While I prefer to use the smarty comment method whenever possible, the purpose here was simply to show you something new that you may not be aware of. {* comment *} 

After uploading the files above, the following image depicts the pdf output produced by the above modifications in the standard template:

image.thumb.png.0ec89464ab2faec91c7c0eceec9f8610.png

Note: IF you wanted a separator line between the payment and message elements, you could always add a border between them by either inserting a <tr><td class="separator"></td></tr> as the first row of the table in the /pdf/delivery-slip.message-tabl.tpl file OR by using/adding a css directive like table#message-tab {border-top:1px solid #000;} in the /pdf/delivery-style-tab.tpl file.

Hopefully presenting the answer in this format will not only allow you to add something that SHOULD HAVE ALREADY BEEN IN THE RELEASED CODE of Prestashop 1.6, but it will also help you to learn more about how to modify your own Prestashop site in the future... or maybe even help out a new developer to the codebase.

 

Edited by obewanz (see edit history)
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...