Jump to content

[SOLVED] Customer Phone number on delivery slip.


weckie

Recommended Posts

Hi all,

 

We would like to have the customers phone number on the delivery slip.

We know how to do it by going to localization and editing the address format per country... BUT.

 

The phone number is displayed directly under customers address, so it is visible to carrier to and everyone who looks at the slip. This is not convenient since not all customers want to share their phone number with just everyone.

 

So our questions is:

 

Does someone know how to get the phonenumber on the deliveryslip and/or invoice on a place we want, like for instance say at the bottom of the slip, or any other location accept for the address location.

 

We would be gratefull for any help.

Link to comment
Share on other sites

Hi Weckie,

 

Edit file:classes/pdf/HTMLTemplateDeliverySlip.php  (make backup, just in case...)

find function: public function getContent()

 
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'order_invoice' => $this->order_invoice,
'carrier' => $carrier ,            // <-- don't forget comma here!!
'delivery_phone' => (!empty($delivery_address->phone) ? $delivery_address->phone : $delivery_address->phone_mobile)
));
 
Save the file.
 
Edit file: /pdf/delivery-slip.tpl  (make backup again...)
 
find this piece of code and add the red code.
<!-- PRODUCTS TAB -->
<table style="width: 100%">
<tr>
<td style="width: 22%; padding-right: 7px; text-align: right; vertical-align: top">
<!-- CUSTOMER INFORMATIONS -->
<b>{l s='Phone :' pdf='true'}</b><br />
{$delivery_phone}<br />
<br />
<b>{l s='Order Number:' pdf='true'}</b><br />
{$order->getUniqReference()}<br />
<br />
 
save the file.
reload the delivery slips page. Generate slip.
 
You should get something like this:
post-455771-0-74804600-1380812194_thumb.jpg
 
Of course you can move it to another place if you want. The important piece of code is:
{$delivery_phone}
 
Which gives the phone number (if phone is available, it displays phone, otherwise the mobile phone)
 
Hope this helps,
pascal
Edited by PascalVG
N.B. Code snippets from Prestashop 1.5.5.0 (see edit history)
  • Like 3
Link to comment
Share on other sites

Wow... Thanks Pascal.  Worked like a charm.  I am starting to understand how the system works.... so i tried to do the same with

the customers emailaddres  :)

 

Didn't get it working yet.. but i will get there.

I guess its kinda like the same as for the phone number  right?

 

Weckie

Link to comment
Share on other sites

Should be similar, in that you add a variable name 'customer_email, ... to the assign. After that you can use it as:

{$customer_email}

 

A problem may be to add the Email address value to the assign: (take a deep breath...)

You probably have to start with the $this->order, from where you get the id of the customer ($this->order->id_customer), then get the whole customer object with all its fields fro the database ($customer = new Customer($this->order->id_customer); ) and THEN you add the $customer->email to the assign. (and breath out...) 

(Hope that this was indeed the whole path to it...)

 

Have fun exploring!

pascal

  • Like 1
Link to comment
Share on other sites

Hi Pascal,

 

I managed to get phone and email on the invoice.

 

Only the phone on the delivery slip i got the way you explained, as said works like charm.

 

But the Email on the delivery slip, i did nog get that right. Tried everything but gave up  :(

 

I am satisfied with the phone on the deliveryslip, that was most important, getting the email on there was kinda like a bonus and not neccessary.

 

Thanks for your help.

Link to comment
Share on other sites

Hi weckie,

 

in the first file we edited:

/classes/pdf/HTMLTemplateDeliverySlip.php

find again function: public function getContent()

 

add the red lines:

 

$carrier = new Carrier($this->order->id_carrier);
$carrier->name = ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name);
$customer = new Customer((int)$this->order->id_customer);
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'order_invoice' => $this->order_invoice,
'carrier' => $carrier,
'delivery_phone' => (!empty($delivery_address->phone) ? $delivery_address->phone : $delivery_address->phone_mobile),
'customer_email' => $customer->email
));
 
(don't forget  "," on delivery_phone-line (at the end ))
Save the file:
 
The second file we edited before:
/pdf/delivery-slip.tpl
 
just under the phone number you added before, add the red code:
 
<b>{l s='Phone :' pdf='true'}</b><br />
<span class="delivery_phone">{$delivery_phone}</span><br />
<br />
<b>{l s='E-mail :' pdf='true'}</b><br />
<span class="customer_email">{$customer_email}</span><br />
<br />
<b>{l s='Order Number:' pdf='true'}</b><br />
{$order->getUniqReference()}<br />
<br />
 

That should do it,

pascal

  • Thanks 1
Link to comment
Share on other sites

And again...  worked like a charm.....  Thanks Pascal.
 
My files do look a bit different then in the example...  but i got it done.  Just use some common sense and you'll get there.
 

I guess it's because we run 1.5.5

My file looks like this:

/**
* @since 1.5
*/
class HTMLTemplateDeliverySlipCore extends HTMLTemplate
{
public $order;

public function __construct(OrderInvoice $order_invoice, $smarty)
{
$this->order_invoice = $order_invoice;
$this->order = new Order($this->order_invoice->id_order);
$this->smarty = $smarty;

// header informations
$this->date = Tools::displayDate($this->order->invoice_date, (int)$this->order->id_lang);
$this->title = HTMLTemplateDeliverySlip::l('Delivery').' #'.Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id).sprintf('%06d', $this->order_invoice->delivery_number);

// footer informations
$this->shop = new Shop((int)$this->order->id_shop);
}

/**
* Returns the template's HTML content
* @return string HTML content
*/
public function getContent()
{
$delivery_address = new Address((int)$this->order->id_address_delivery);
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
$formatted_invoice_address = '';
$customer = new Customer((int)$this->order->id_customer);


if ($this->order->id_address_delivery != $this->order->id_address_invoice)
{
$invoice_address = new Address((int)$this->order->id_address_invoice);
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
}

$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'order_invoice' => $this->order_invoice,
'delivery_phone' => (!empty($delivery_address->phone) ? $delivery_address->phone : $delivery_address->phone_mobile),
'customer_email' => $customer->email
));

return $this->smarty->fetch($this->getTemplate('delivery-slip'));
}
 

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

  • 3 months later...

Hi skovbakke,

 

Yes should be possible, just add custom info to file:

classes/pdf/HTMLTemplateDeliverySlip.php in function getContents , just like customer_email in example above. Then add code to

 

Then use it in PDF/delivery-slip.tpl, again, like sample above.

 

Let me know if you need more help,

Pascal

  • Thanks 1
Link to comment
Share on other sites

Hi skovbakke,

 

Yes should be possible, just add custom info to file:

classes/pdf/HTMLTemplateDeliverySlip.php in function getContents , just like customer_email in example above. Then add code to

 

Then use it in PDF/delivery-slip.tpl, again, like sample above.

 

Let me know if you need more help,

Pascal

Thanks Pascal.

I actually got that part, but I would like to insert the info into the footer instead of the delivery-slip.tpl, since I need an absolute position from the bottom. That wouldn't be possible straight from the delivery-slip.tpl, or would it?

Thanks again

Link to comment
Share on other sites

Hi skovbakke, can you show/create some quick image how it should look like?

Well, what I've been trying to achieve is to use the delivery slip to also include an address label and then print it on one of these paper types with a peel of sticker. To make that work, I have to be certain, that no matter the size of the rest of the document, my address will always be in the same position on the bottom(where the peel of section is located on the printing paper) which is why I'm using the footer.tpl.

 

I kind of followed this guide:

http://e-shopblog.com/prestashop/how-to-add-a-shipping-label-to-prestashop-pdf-invoice/

 

I had to modify some things to make it work, but it's alright now. Only problem is, that since it's in the footer, it also goes into the other pdf documents, such as the invoice, where I'd rather have the standard footer...

Don't know if it's possible to have different footers for different documents, the way it's setup in Presta? 

Link to comment
Share on other sites

Hi Pascal.

I managed to solve it myself, so now everything is working.

What I did was to restore the footer.tpl back to default and then make an extra file called footer_delivery.tpl, and put it in my themes pdf folder. That file contains the template for the footer with the orders delivery address, as I wanted on my delivery slip.

Then I made a new file HTMLTemplateDeliverySlip.php in override/classes/pdf, that overrides the function getFooter() from HTMLTemplate.php, so it uses my footer_delivery.tpl as footer template instead of the original.

 

So now I have a custom footer for the delivery slip, while maintaining the original for the other pdf's.

 

Thanks for your help and have a nice weekend.

 

TB Jeppe

Link to comment
Share on other sites

  • 1 month later...

Sorry to bring this up again, but I've noticed a problem with my implementation, that I can't seem to wrap my head around.

When one delivery slip is printed everything is good and the customer's delivery adress is nicely located on the peel-off label in the bottom left corner.

But the reason for doing it this way is to be able to bulk print the delivery-slips for a day's sales, pack according to the slip and then peel off the address label and stick it on immediately. When I do that, the addresses are unfortunately wrong. The delivery-slip is fine, and the addresses in the top (delivery/billing) are both good, but the address in the footer is from the next delivery-slip.

So if I have four delivery-slips the address on the peel-off label in the footer of slip number one, will be the address shown in the top of label two, and so on. The last one in line will always have the right label, which means that the last label will be doubled and the first label will be missing.

 

The way I see it it must be something with how tcpdf works with footers. As if it is somehow closing the current pdf and fetching the data for the next before adding the footer to the current.

Is it really so, or is there something I'm missing?

 

Thanks, Jeppe

Link to comment
Share on other sites

  • 5 months later...
  • 4 weeks later...
  • 2 weeks later...

Hi skovbakke,

 

Yes should be possible, just add custom info to file:

classes/pdf/HTMLTemplateDeliverySlip.php in function getContents , just like customer_email in example above. Then add code to

 

Then use it in PDF/delivery-slip.tpl, again, like sample above.

 

Let me know if you need more help,

Pascal

 

Hello

I've read this poste, and this is exactly what im searching for.

But im a realy newb in programming (an english writing  to ;-) ) and im not shure how to do it correctly.

I want to print the customer massage from the checkout to the delivery slip, because it is very important for the logistician.

I've have done the changes form above for mailadresse, but im not shure how to import the customer massage.

 

My code in PS1.6 looks like this:

 

<?php

/*

* 2007-2014 PrestaShop

*

* NOTICE OF LICENSE

*

* This source file is subject to the Open Software License (OSL 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/osl-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 <[email protected]>

*  @copyright  2007-2014 PrestaShop SA

*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)

*  International Registered Trademark & Property of PrestaShop SA

*/

/**

 * @since 1.5

 */

class HTMLTemplateDeliverySlipCore extends HTMLTemplate

{

 public $order;

 public function __construct(OrderInvoice $order_invoice, $smarty)

 {

  $this->order_invoice = $order_invoice;

  $this->order = new Order($this->order_invoice->id_order);

  $this->smarty = $smarty;

  // header informations

  $this->date = Tools::displayDate($this->order->invoice_date);

  $this->title = HTMLTemplateDeliverySlip::l('Delivery').' #'.Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id).sprintf('%06d', $this->order_invoice->delivery_number);

  // footer informations

  $this->shop = new Shop((int)$this->order->id_shop);

 }

 /**

  * Returns the template's HTML content

  * @return string HTML content

  */

 public function getContent()

 {

  $delivery_address = new Address((int)$this->order->id_address_delivery);

  $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');

  $formatted_invoice_address = '';

  if ($this->order->id_address_delivery != $this->order->id_address_invoice)

  {

   $invoice_address = new Address((int)$this->order->id_address_invoice);

   $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');

  }

  

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

  $carrier->name = ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name);

$customer = new Customer((int)$this->order->id_customer);

  $this->smarty->assign(array(

   'order' => $this->order,

   'order_details' => $this->order_invoice->getProducts(),

   'delivery_address' => $formatted_delivery_address,

   'invoice_address' => $formatted_invoice_address,

   'order_invoice' => $this->order_invoice,

   'carrier' => $carrier,

'customer_info' => $customer->info

  ));

  return $this->smarty->fetch($this->getTemplate('delivery-slip'));

 }

 /**

  * Returns the template filename when using bulk rendering

  * @return string filename

  */

 public function getBulkFilename()

 {

  return 'deliveries.pdf';

 }

 /**

  * Returns the template filename

  * @return string filename

  */

 public function getFilename()

 {

  return Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop).sprintf('%06d', $this->order->delivery_number).'.pdf';

 }

}

 

 

Thank you for supporting me :-)

Thomas

Link to comment
Share on other sites

H Thomas,

 

Follow the guidelines at my post no #8, and use following modifications:

 

classes/pdf/HTMLTemplateDeliverySlip.php:   (Make backup!!!)

edit public function getContent():

 
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'order_invoice' => $this->order_invoice,
'carrier' => $carrier,            /* <-- don't forget comma... */
'order_messages' => $this->order->getFirstMessage()
));
 
And then in file pdf/delivery-slip.tpl: (Make backup!!!)
find the black code (search for <!-- / PRODUCTS TAB -->   with Ctrl-F(Windows), Cmd-F(Mac)), and add the red code.
 
    </tr>
</table>
<!-- / PRODUCTS TAB -->
                      {* suggested place, can be moved if needed *}
<b>{l s='Order checkout message:' pdf='true'}</b><br />
{$order_messages}<br />
<br />
 
<table>
    <tr><td style="line-height: 8px"> </td></tr>
</table>
 
{if isset($HOOK_DISPLAY_PDF)}
 
save files and try.
 
Hope this helps. Let me know,
pascal.
  • Like 1
Link to comment
Share on other sites

 

H Thomas,

 

Follow the guidelines at my post no #8, and use following modifications:

 

classes/pdf/HTMLTemplateDeliverySlip.php:   (Make backup!!!)

edit public function getContent():

 
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'order_invoice' => $this->order_invoice,
'carrier' => $carrier,            /* <-- don't forget comma... */
'order_messages' => $this->order->getFirstMessage()
));
 
And then in file pdf/delivery-slip.tpl: (Make backup!!!)
find the black code (search for <!-- / PRODUCTS TAB -->   with Ctrl-F(Windows), Cmd-F(Mac)), and add the red code.
 
    </tr>
</table>
<!-- / PRODUCTS TAB -->
                      {* suggested place, can be moved if needed *}
<b>{l s='Order checkout message:' pdf='true'}</b><br />
{$order_messages}<br />
<br />
 
<table>
    <tr><td style="line-height: 8px"> </td></tr>
</table>
 
{if isset($HOOK_DISPLAY_PDF)}
 
save files and try.
 
Hope this helps. Let me know,
pascal.

 

Hi Pascal,

 

It works :-) :-)

Thank you very mutch!

 

Is it possible to make the message-field obligate during the checkout process?

 

Kind regards

Thomas

Link to comment
Share on other sites

  • 2 months later...

is there a way to show only the attribute value in the delivery slip ! i need to make it bold or more clear. 

 

now the product name and the attribute is shown in normal text, but i need the attribute to be bold  or just print out the attribute again under with bold text. 

Link to comment
Share on other sites

  • 1 month later...

Hi Weckie,

 

Edit file:classes/pdf/HTMLTemplateDeliverySlip.php  (make backup, just in case...)

find function: public function getContent()

 

 

$this->smarty->assign(array(

'order' => $this->order,

'order_details' => $this->order_invoice->getProducts(),

'delivery_address' => $formatted_delivery_address,

'invoice_address' => $formatted_invoice_address,

'order_invoice' => $this->order_invoice,

'carrier' => $carrier ,            // <-- don't forget comma here!!

'delivery_phone' => (!empty($delivery_address->phone) ? $delivery_address->phone : $delivery_address->phone_mobile)

));

 

 

Save the file.

 

Edit file: /pdf/delivery-slip.tpl  (make backup again...)

 

find this piece of code and add the red code.

 

<!-- PRODUCTS TAB -->

<table style="width: 100%">

<tr>

<td style="width: 22%; padding-right: 7px; text-align: right; vertical-align: top">

<!-- CUSTOMER INFORMATIONS -->

<b>{l s='Phone :' pdf='true'}</b><br />

{$delivery_phone}<br />

<br />

<b>{l s='Order Number:' pdf='true'}</b><br />

{$order->getUniqReference()}<br />

<br />

 

 

save the file.

reload the delivery slips page. Generate slip.

 

You should get something like this:

attachicon.gifdelivery slip.jpg

 

Of course you can move it to another place if you want. The important piece of code is:

{$delivery_phone}

 

Which gives the phone number (if phone is available, it displays phone, otherwise the mobile phone)

 

Hope this helps,

pascal

 

You can probably add some simple css code to not display it in certain pages. Can you add the link to your shop, so we can have a look? Then we can probably recommend some code you can add.

 

pascal.

Hi pascal I am using a module purchaser order number which prints purchase order number on invoice I want same to happen with delivery slip I tried method you mentioned above module used 1.6 override file I am attaching , module support asked me to find answer in PS forum .

 

What can be the solution? attachd is module 1.6 override file , this override html file needs to be copy in override/classes/pdf flder on root directory for module to work

 

Thanks in advance for helpRead ME.txt

 

Link to comment
Share on other sites

  • 5 months later...

 

 

Edit file:classes/pdf/HTMLTemplateDeliverySlip.php  (make backup, just in case...)

find function: public function getContent()

 
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order_invoice->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'order_invoice' => $this->order_invoice,
'carrier' => $carrier ,            // <-- don't forget comma here!!
'delivery_phone' => (!empty($delivery_address->phone) ? $delivery_address->phone : $delivery_address->phone_mobile)
));
 
Save the file.
 
Edit file: /pdf/delivery-slip.tpl  (make backup again...)
 
find this piece of code and add the red code.
<!-- PRODUCTS TAB -->
<table style="width: 100%">
<tr>
<td style="width: 22%; padding-right: 7px; text-align: right; vertical-align: top">
<!-- CUSTOMER INFORMATIONS -->
<b>{l s='Phone :' pdf='true'}</b><br />
{$delivery_phone}<br />
<br />
<b>{l s='Order Number:' pdf='true'}</b><br />
{$order->getUniqReference()}<br />
<br />
 
save the file.
reload the delivery slips page. Generate slip.
 
Of course you can move it to another place if you want. The important piece of code is:

{$delivery_phone}
 
Which gives the phone number (if phone is available, it displays phone, otherwise the mobile phone)
 
Hope this helps,
pascal

 

Thanks for this valuable tip. It works if I alter the file directly in classes/pdf/HTMLTemplateDeliverySlip.php

It won't work if I put the file in override/classes/pdf

 

Can't I use the override folder for such changes?

Link to comment
Share on other sites

  • 3 weeks later...

I'm also trying to add customer email address to our PDF Delivery Slip in PS 1.6.1.0. Here's what I have:

 

Modified 'classes/pdf/HTMLTemplateDeliverySlip.php', line 112:

 

$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,
'customer_email' => $customer->email,
'display_product_images' => Configuration::get('PS_PDF_IMG_DELIVERY')
));

Modified 'pdf/delivery-slip.addresses-tab.tpl':

 

<table id="addresses-tab" cellspacing="0" cellpadding="0">
<tr>
<td width="33%"><span class="bold"> </span><br/><br/>
{$order_invoice->shop_address}
</td>
{if !empty($invoice_address)}
<td width="33%">{if $delivery_address}<span class="bold">{l s='Delivery Address' pdf='true'}</span><br/><br/>
{$delivery_address}<br />
<b>{l s='Email: ' pdf='true'}</b>{$customer_email}<br />
        {/if}
</td>
<td width="33%"><span class="bold">{l s='Billing Address' pdf='true'}</span><br/><br/>
{$invoice_address}<br />
<b>{l s='Email: ' pdf='true'}</b>{$customer_email}<br />
</td>
{else}
<td width="66%">{if $delivery_address}<span class="bold">{l s='Ship  To:' pdf='true'}</span><br/><br/>
{$delivery_address}<br />
<b>{l s='Email: ' pdf='true'}</b>{$customer_email}<br />
{/if}
</td>
{/if}
</tr>
</table>

The word "Email:" in bold is showing below each address on the PDF, however the email address is not, any idea why?

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

  • 2 weeks 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...