Jump to content

Adding customer comment message to delivery / invoice pdf


Amy JB Clayton

Recommended Posts

Is there anyway to display the customer comment that customers can add on the address page of the checkout procedure to the delivery pdf.

 

I've managed to edit it so that the gift-wrapping message is shown, but am not sure of the variable that needs to be included so that the order message is shown.

 

Any help would be much appreciated.

Link to comment
Share on other sites

  • 5 weeks later...
  • 3 weeks later...
  • 2 years later...

This is how to to add customer comment message to the PDF invoice. Tested in 1.5.2.

 

1. Edit the file /override/classes/order/OrderInvoice.php.
2. Copy the function getProducts() from /classes/order/OrderInvoice.php and paste it inside the class in the override file.
3. In the override file, paste the following lines directly after the statement foreach ($products as $row) {.

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

4. Edit the file /pdf/invoice.tpl.

5. Paste the following where you want the customer comment message to appear. NOTE! This has to be after the listing of products. (Because it utilizes a remaining variable from the product foreach loop.)

{$order_detail.first_order_message}

That's it! :)

 

 

As a further example - here's my complete /override/classes/order/OrderInvoice.php:

Note that the original function getProducts() can be vary between versions of Prestashop. My current version is 1.5.2.

<?php

class OrderInvoice extends OrderInvoiceCore
{
	
	/**
	 * Get order products
	 *
	 * @return array Products with price, quantity (with taxe and without)
	 */
	/*
		overridden to add order customer note to pdf invoice
	*/
	public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
	{
		if (!$products)
			$products = $this->getProductsDetail();

		$order = new Order($this->id_order);
		$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
		
		$resultArray = array();
		foreach ($products as $row)
		{
			
			// hack start
			if( end($products) === $row ) {
				$row['first_order_message'] = nl2br($order->getFirstMessage());
			}
			// hack end
			
			// Change qty if selected
			if ($selectedQty)
			{
				$row['product_quantity'] = 0;
				foreach ($selectedProducts as $key => $id_product)
					if ($row['id_order_detail'] == $id_product)
						$row['product_quantity'] = (int)($selectedQty[$key]);
				if (!$row['product_quantity'])
					continue;
			}

			$this->setProductImageInformations($row);
			$this->setProductCurrentStock($row);
			$this->setProductCustomizedDatas($row, $customized_datas);

			// Add information for virtual product
			if ($row['download_hash'] && !empty($row['download_hash']))
			{
				$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
				// Get the display filename
				$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
			}
			
			$row['id_address_delivery'] = $order->id_address_delivery;
			
			/* Stock product */
			$resultArray[(int)$row['id_order_detail']] = $row;
		}

		if ($customized_datas)
			Product::addCustomizationPrice($resultArray, $customized_datas);

		return $resultArray;
	}
	
}
Edited by patrikar (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 3 weeks later...

 

This is how to to add customer comment message to the PDF invoice. Tested in 1.5.2.

 

1. Edit the file /override/classes/order/OrderInvoice.php.

2. Copy the function getProducts() from /classes/order/OrderInvoice.php and paste it inside the class in the override file.

3. In the override file, paste the following lines directly after the statement foreach ($products as $row) {.

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

4. Edit the file /pdf/invoice.tpl.

5. Paste the following where you want the customer comment message to appear. NOTE! This has to be after the listing of products. (Because it utilizes a remaining variable from the product foreach loop.)

{$order_detail.first_order_message}

That's it! :)

 

 

As a further example - here's my complete /override/classes/order/OrderInvoice.php:

Note that the original function getProducts() can be vary between versions of Prestashop. My current version is 1.5.2.

<?php

class OrderInvoice extends OrderInvoiceCore
{
	
	/**
	 * Get order products
	 *
	 * @return array Products with price, quantity (with taxe and without)
	 */
	/*
		overridden to add order customer note to pdf invoice
	*/
	public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
	{
		if (!$products)
			$products = $this->getProductsDetail();

		$order = new Order($this->id_order);
		$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
		
		$resultArray = array();
		foreach ($products as $row)
		{
			
			// hack start
			if( end($products) === $row ) {
				$row['first_order_message'] = nl2br($order->getFirstMessage());
			}
			// hack end
			
			// Change qty if selected
			if ($selectedQty)
			{
				$row['product_quantity'] = 0;
				foreach ($selectedProducts as $key => $id_product)
					if ($row['id_order_detail'] == $id_product)
						$row['product_quantity'] = (int)($selectedQty[$key]);
				if (!$row['product_quantity'])
					continue;
			}

			$this->setProductImageInformations($row);
			$this->setProductCurrentStock($row);
			$this->setProductCustomizedDatas($row, $customized_datas);

			// Add information for virtual product
			if ($row['download_hash'] && !empty($row['download_hash']))
			{
				$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
				// Get the display filename
				$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
			}
			
			$row['id_address_delivery'] = $order->id_address_delivery;
			
			/* Stock product */
			$resultArray[(int)$row['id_order_detail']] = $row;
		}

		if ($customized_datas)
			Product::addCustomizationPrice($resultArray, $customized_datas);

		return $resultArray;
	}
	
}

 

How could I do to show it in the delivery-slip

 

 

very thanks

Link to comment
Share on other sites

How could I do to show it in the delivery-slip

 

 

very thanks

 

In the same way as described earlier. But in step 5 use the following smarty variable instead:

{$product.first_order_message}

Because in delivery-slip.tpl, the product loop looks like this: {foreach $order_details as $product} compared to: {foreach $order_details as $order_detail} in invoice.tpl.

 

Can you verify if this works?

Link to comment
Share on other sites

In the same way as described earlier. But in step 5 use the following smarty variable instead:

{$product.first_order_message}

Because in delivery-slip.tpl, the product loop looks like this: {foreach $order_details as $product} compared to: {foreach $order_details as $order_detail} in invoice.tpl.

 

Can you verify if this works?

Works like a charm

 

Any posibilitity show only no private messages like order generate by employe or payments methods  confirmations?

 

 

 

Thanks a lot

Link to comment
Share on other sites

Works like a charm

 

Any posibilitity show only no private messages like order generate by employe or payments methods  confirmations?

 

 

 

Thanks a lot

 

Sorry but I don't know anything about that. I suggest you look inside classes/order.php, maybe there is some options for getFirstMessage() or some other appropriate method.

Link to comment
Share on other sites

I managed this with the help of a module

 

http://www.presta-addons.com/moduly/3-pdf-rozsireni.html

 

The one draw back that I have not managed to sort out yet is that if the customer pays woth PayPal on Moneybookers, then the customer message also contains the transaction details

Here is a recipe - http://www.prestashop.com/forums/topic/270613-module-m4-pdf-extensions-with-online-editor/page-6?do=findComment&comment=1677379

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...

 

This is how to to add customer comment message to the PDF invoice. Tested in 1.5.2.

 

1. Edit the file /override/classes/order/OrderInvoice.php.

2. Copy the function getProducts() from /classes/order/OrderInvoice.php and paste it inside the class in the override file.

3. In the override file, paste the following lines directly after the statement foreach ($products as $row) {.

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

4. Edit the file /pdf/invoice.tpl.

5. Paste the following where you want the customer comment message to appear. NOTE! This has to be after the listing of products. (Because it utilizes a remaining variable from the product foreach loop.)

{$order_detail.first_order_message}

That's it! :)

 

 

As a further example - here's my complete /override/classes/order/OrderInvoice.php:

Note that the original function getProducts() can be vary between versions of Prestashop. My current version is 1.5.2.

<?php

class OrderInvoice extends OrderInvoiceCore
{
	
	/**
	 * Get order products
	 *
	 * @return array Products with price, quantity (with taxe and without)
	 */
	/*
		overridden to add order customer note to pdf invoice
	*/
	public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
	{
		if (!$products)
			$products = $this->getProductsDetail();

		$order = new Order($this->id_order);
		$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
		
		$resultArray = array();
		foreach ($products as $row)
		{
			
			// hack start
			if( end($products) === $row ) {
				$row['first_order_message'] = nl2br($order->getFirstMessage());
			}
			// hack end
			
			// Change qty if selected
			if ($selectedQty)
			{
				$row['product_quantity'] = 0;
				foreach ($selectedProducts as $key => $id_product)
					if ($row['id_order_detail'] == $id_product)
						$row['product_quantity'] = (int)($selectedQty[$key]);
				if (!$row['product_quantity'])
					continue;
			}

			$this->setProductImageInformations($row);
			$this->setProductCurrentStock($row);
			$this->setProductCustomizedDatas($row, $customized_datas);

			// Add information for virtual product
			if ($row['download_hash'] && !empty($row['download_hash']))
			{
				$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
				// Get the display filename
				$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
			}
			
			$row['id_address_delivery'] = $order->id_address_delivery;
			
			/* Stock product */
			$resultArray[(int)$row['id_order_detail']] = $row;
		}

		if ($customized_datas)
			Product::addCustomizationPrice($resultArray, $customized_datas);

		return $resultArray;
	}
	
}

 

 

Is there any way to display all order messages instead of just the first one?

Link to comment
Share on other sites

Create a similar function and get all messages, instead of the first only.

public static function getMessages($id_order)
{
    $messages = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT `message`
        FROM `'._DB_PREFIX_.'message`
        WHERE `id_order` = '.(int)$id_order.'
        ORDER BY `id_message`
    ');

    return nl2br(implode("\n", (array)$messages));
}

not tested

  • Like 1
Link to comment
Share on other sites

  • 9 months later...
  • 2 months later...

Here is a little module I did for a client to show the note the customer leaves during checkout on the PDF Invoice on PS 1.6.1. Hope it is useful for anyone.

 

Update 2016/11/08

New version of module: as requested by several users the order comment now shows on the delivery slip PDF too. 

To update, just download attachment and install module normally as any other module. 

 

Update 2016/11/15

Module is now available at http://addons.prestashop.com/en/24711-order-note-on-pdfs.html - all support will be given via the PS addons shop.

 

Update 2016/11/18

Module is now compatible with PS 1.5 too. 

 

Kind regards..

Edited by fire2 (see edit history)
  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

 

This is how to to add customer comment message to the PDF invoice. Tested in 1.5.2.

 

1. Edit the file /override/classes/order/OrderInvoice.php.

2. Copy the function getProducts() from /classes/order/OrderInvoice.php and paste it inside the class in the override file.

3. In the override file, paste the following lines directly after the statement foreach ($products as $row) {.

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

4. Edit the file /pdf/invoice.tpl.

5. Paste the following where you want the customer comment message to appear. NOTE! This has to be after the listing of products. (Because it utilizes a remaining variable from the product foreach loop.)

{$order_detail.first_order_message}

That's it! :)

 

 

As a further example - here's my complete /override/classes/order/OrderInvoice.php:

Note that the original function getProducts() can be vary between versions of Prestashop. My current version is 1.5.2.

<?php

class OrderInvoice extends OrderInvoiceCore
{
	
	/**
	 * Get order products
	 *
	 * @return array Products with price, quantity (with taxe and without)
	 */
	/*
		overridden to add order customer note to pdf invoice
	*/
	public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
	{
		if (!$products)
			$products = $this->getProductsDetail();

		$order = new Order($this->id_order);
		$customized_datas = Product::getAllCustomizedDatas($order->id_cart);
		
		$resultArray = array();
		foreach ($products as $row)
		{
			
			// hack start
			if( end($products) === $row ) {
				$row['first_order_message'] = nl2br($order->getFirstMessage());
			}
			// hack end
			
			// Change qty if selected
			if ($selectedQty)
			{
				$row['product_quantity'] = 0;
				foreach ($selectedProducts as $key => $id_product)
					if ($row['id_order_detail'] == $id_product)
						$row['product_quantity'] = (int)($selectedQty[$key]);
				if (!$row['product_quantity'])
					continue;
			}

			$this->setProductImageInformations($row);
			$this->setProductCurrentStock($row);
			$this->setProductCustomizedDatas($row, $customized_datas);

			// Add information for virtual product
			if ($row['download_hash'] && !empty($row['download_hash']))
			{
				$row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']);
				// Get the display filename
				$row['display_filename'] = ProductDownload::getFilenameFromFilename($row['filename']);
			}
			
			$row['id_address_delivery'] = $order->id_address_delivery;
			
			/* Stock product */
			$resultArray[(int)$row['id_order_detail']] = $row;
		}

		if ($customized_datas)
			Product::addCustomizationPrice($resultArray, $customized_datas);

		return $resultArray;
	}
	
}

 

Not sure if i'm missing anything, but this doesn't seem to work for 1.5.4. I'm not getting any errors, but it doesn't show in the invoice PDF. Force compile on, cache off.

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Here is a little module I did for a client to show the note the customer leaves during checkout on the PDF Invoice on PS 1.6.1. Hope it is useful for anyone.

 

Hello, module works like a charm with invoice. is possible to add to slip hook too?

I need to have first order message on slip without modify prestashop core

 

thanks in advance

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

  • 3 weeks later...

@Fire2 

 

Great to see there is a module for this! Is there anyway to adapt it to show the comments in the Delivery Slip?

 

Thanks and best,

Decorocco

 

 

Hi, PS confirmed (http://forge.prestashop.com/browse/PSCSX-7533) they will add order note field on the default invoice template again in PS 1.6.1.5, I would wait to see if they add it to delivery slip too.

 

Regards,

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

HTMLTemplateDeliverySlip.phpWhat about delivery slip , in my case there is purchase order number on invoice but its not printing on delviery slip , I used purchase order module, and it uss a htmltemplateinvoice.php which is being copied override/classes/pdf folder which make PO to be copied on invoice but its not copying on delviery slip any idea attached is the file

HTMLTemplateDeliverySlip.php

Link to comment
Share on other sites

  • 4 months later...

@Fire2 

 

Great to see there is a module for this! Is there anyway to adapt it to show the comments in the Delivery Slip?

 

Thanks and best,

Decorocco

 

Edit: new version of the module is in my original post:  https://www.prestashop.com/forums/topic/145386-adding-customer-comment-message-to-delivery-invoice-pdf/?p=2157392 

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

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