Jump to content

[Guide] Modifying Prestashop 1.5/1.6 Invoice Template.


Supremacy2k

Recommended Posts

After copy the code in my invoice.tpl i became this error:

 

Warning: Division by zero in /www/htdocs/....../....../....../....../tools/tcpdf/tcpdf.php on line 23203

 

Warning: array_fill() [function.array-fill]: Number of elements must be positive in /www/htdocs/....../....../....../....../tools/tcpdf/tcpdf.phpon line 23205

 

Warning: Invalid argument supplied for foreach() in /www/htdocs/....../....../....../....../tools/tcpdf/tcpdf.php on line 24618

 

Warning: Invalid argument supplied for foreach() in /www/htdocs/....../....../....../....../tools/tcpdf/tcpdf.php on line 24650

TCPDF ERROR: Some data has already been output, can't send PDF file

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

Well then its at 1.4 upgraded to 1.5, because 1.5 do not have a "tools" folder.

 

And in that case I'm not sure what your problem is, because I'm not getting any errors on my shop, which is live. :/

 

Edit: I can see you get your error in the .php file, and not the tpl file.

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

very nice guide, thanks for sharing!

 

v1.5 does indeed include a tools folder, which is where all the plugins and 3rd party libraries are stored. The error is occuring in the writeHTML function of tcpdf.php. Most likely something in the invoice.tpl is not correct or conflicting with the users specific installation. It would need to be debugged further to understand the problem.

Link to comment
Share on other sites

Okey I'm blind.

I totally missed the "tools" folder, hehe.

 

Anyways.

 

On line 23.203 i have the following:

} else {

on 23.205 i have this:

}

On 24.618 this:

$this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');

and on 24.650 this

if (isset($this->theadMargins['top'])) {

 

m3442a .. can you post your lines from 24203 to 24205 and from 24618 to 24650 ?

Link to comment
Share on other sites

how can I change {$invoice_address} and {$delivery_address} format.

 

 

Company name (bold) or font size 18

firstname lastname (small)

address1, address2

city, country

 

actually I need this format on every document

 

To be honest I'm not quite sure where address text is generated.

I havent looked into it, and might go beyond my skills for now. :(

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

I made some alterations to my invoice also. But at the reference number/order number I can't make that show.

I tried inseting

{$order_detail.product_reference}

but on the PDF I see only a blank space and then I looked at your guide and tried with

{$order_detail.product_ean13}

.

 

The result is the same. I don't understand what I did wrong with the invoice template because all the other cells and data in them are shown properly.

 

Can anybody give me some pointers to what should I try next?

 

Thanks

Link to comment
Share on other sites

Hi

 

I have the same problem with EAN codes - it is blank. All other fields are fine. Latest stable PrestShop.

Hi,

 

I made some alterations to my invoice also. But at the reference number/order number I can't make that show.

I tried inseting

{$order_detail.product_reference}

but on the PDF I see only a blank space and then I looked at your guide and tried with

{$order_detail.product_ean13}

.

 

The result is the same. I don't understand what I did wrong with the invoice template because all the other cells and data in them are shown properly.

 

Can anybody give me some pointers to what should I try next?

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Found a similar solution in the french forum:

http://www.prestasho...-prestashop-15/

 

This version contains a section for display weight, carrier and tracking ID I used just as option for my own slightly modified invoice.tpl, which is attached as pdf.

(Full coding you find here: http://www.prestasho...36#entry1117036 )

 

<!-- Optional display of weight, carrier and tracking ID -->

{foreach from=$order->getShipping() item=shipping name=shippingsLoop}
<table style="width: 100%; text-align: center; border: 1px solid #CCC; font-size: 9pt;">
 <tr>
  <td colspan = "3" style="background-color: #CCC; color: #000;">
	<b>{l s='Paket Nr. ' pdf='true'}{$smarty.foreach.shippingsLoop.iteration}</b>
  </td>
 </tr>
 <tr>
  <td style="width: 33%; background-color: #EEE; color: #000;">
	<b>{l s='Gewicht:' pdf='true'}</b>
  </td>
  <td style="width: 33%; background-color: #EEE; color: #000;">
	<b>{l s='Versanddienst:' pdf='true'}</b>
  </td>
  <td style="width: 34%; background-color: #EEE; color: #000;">
	<b>{l s='Tracking-Nr.:' pdf='true'}</b>
  </td>
 </tr>
 <tr>
  <td style="width: 33%;">
	{$shipping.weight|string_format:"%.3f"} Kg
  </td>
  <td style="width: 33%;">
	{$shipping.state_name}
  </td>
  <td style="width: 34%;">
	{$shipping.tracking_number}
  </td>
 </tr>
</table>
{/foreach}

 

For printouts on own business paper I recommend just to deactivate line 73 and 74 in /classes/pdf/pdf.php with /* ... */:

 

$this->pdf_renderer->createHeader($template->getHeader());
$this->pdf_renderer->createFooter($template->getFooter());

 

If the billing address doesn't fit, either change the margins in /classes/pdf/PDFgenerator.php or

adjust table width from 100% to about 92%, which matches about 1in for left margin.

 

Anyhow, as our tax laws in Germany are very complicated, I got an urgent request too:

Does anybody know how to display the tax rate for each product in every line of the invoice's products section?

 

It's jinxed, but I just can't manage it. I really have no idea.

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

Anyhow, as our tax laws in Germany are very complicated, I got an urgent request too:

Does anybody know how to display the tax rate for each product in every line of the invoice's products section?

 

It's jinxed, but I just can't manage it. I really have no idea.

 

you could have a look into the template of ps1.4 (if nobody changed the name of the methods/functions for 1.5)

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

Why not? If you're desperate to include the reference to any particular style in the invoice.tpl, it should work.

 

Maybe even with a separate css file if you activate option Smart Cache for CSS. This forces PrestaShop to conbine all css files into a single file.

 

didn't try with smart cache for CSS (I already started coding the template without it), but without didn't work

Link to comment
Share on other sites

With the modifications explained in the OP, this removes the content from the header.tpl file and inserts it into the invoice.tpl file.

That's fine, however the invoice then has a large gap at the top where the header should be, since the header file is now empty.

 

Is there any way to move the invoice.tpl content higher to the top of the page, i.e. reduce the height of the header.tpl allowance within the PDF?

Link to comment
Share on other sites

I'll been fighting with this my self.

 

The reason why i chose to move the header content into the main document, was because the header.tpl don't have access to all variables used with this invoice template.

 

The major factor was the order number.

 

How to either remove the header.tpl from this template or reduces it's occupied space on the pdf, i don't know. :(

Link to comment
Share on other sites

@cammo & Supremacy2k

 

Is there any way to move the invoice.tpl content higher to the top of the page, i.e. reduce the height of the header.tpl allowance within the PDF?

 

How to either remove the header.tpl from this template or reduces it's occupied space on the pdf, i don't know

 

So once again what JohnJohn already posted on page 2 of this thread:

 

You may reduce space for header or footer in lines 153 and 154 of /classes/pdf/PDFgenerator.php:

 

 * Write a PDF page
 */
public function writePage()
{
 $this->SetHeaderMargin(5);
 $this->SetFooterMargin(18);
 $this->setMargins(10, 40, 10);
 $this->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);

 $this->AddPage();

 $this->writeHTML($this->content, true, false, true, false, '');
}

  • Like 2
Link to comment
Share on other sites

No, don't just duplicate the file! You need to replace

 

class PDFGeneratorCore extends TCPDF

 

with this line already written in the overrrides file:

 

class PDFGenerator extends PDFGeneratorCore

 

With this modifications you may copy the whole file to /overrides/pdf.

 

Or you just modify the funktion with an overrides file containing just the function with your range modification like shown below:

 

<?
class PDFGenerator extends PDFGeneratorCore
{
* Write a PDF page
 */
public function writePage()
{
 $this->SetHeaderMargin(5);
 $this->SetFooterMargin(18);
 $this->setMargins(10, 40, 10);
 $this->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
 $this->AddPage();
 $this->writeHTML($this->content, true, false, true, false, '');
}
}

 

Full modified copy does work, in case of the second I'm not quite sure. Normally I use the full mode.

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

@ Supremacy2k: Thanks a lot for this guide, it made my day. :-)

 

A related question: Does anyone know how I can add the customers phone number to the pdf invoice? I'm using v. 1.5.3.1

 

I have tried editing the address format in "cuntries" but it doesn't seem to do anything.

Link to comment
Share on other sites

@dklap3

 

Sounds weird.

 

I think you should

  • either delete the smarty cache in \cache\smarty\cache and \cache\smarty\compile
  • or switch for one time to Force compile in Advanced Parameters second menu item in section Smarty.
    (Then switch back to normal mode. Slows down your shop system)

 

Then your modifications should work.

Link to comment
Share on other sites

@ eleazer: thank you for the reply. I think I found the problem.

 

In "country", when trying to add the phone, I clicked "Address" > "phone_mobile" which added a "Address:phone_mobile" to the format field. This didn't show up on my invoice. However, deleting the first part and just writing "phone_mobile" made it show up..not sure why but a bit confusing. Anyway it works now. :)

 

On last thing: Do you also know if I can possibly add a little "(Tlf)", or any other text, after or before the phone number? My adress format includes 2 things with 8 numbers (phone and tax nr.) and I would like to add such a little text next to them to avoid confusion.

Link to comment
Share on other sites

Nope, inserting other text isn't allowed here. Just the field names. And in future you should better klick on the button "Apply standard" or something like that (sorry, but my buttons are in German) displayed below the field as second one. This forces PrestaShop to dislplay all valid field names and you avoid misspelling.

 

Anyhow, it should be possible to add some text to the billing or delivery address, but that's a bit tricky because you have to modify the core file where the address formats are generated.

PDFs in PrestaShop just display these elsewhere generated address formats.

Link to comment
Share on other sites

Thank you again for the answer eleazar.

 

I might try to modify the core files later, but for now I found another more simple solution.

 

For my new invoice (based on the example in this thread), I have just added the text manually in the <td> next to the address. All the fields in the address are mandatory, so I'm sure it will be the same fields used every time.

 

It's in Danish, but you'll probably get it:

 

faktura.jpg

Link to comment
Share on other sites

  • 2 weeks later...

Great post. Learned a lot today... Even though still a newbie managed to fit the adresses to work with my peel of labels and did some other design changes. Although the one thing I can not seam to find and modify is the the table with total tax under the product table? I see something called {$tax_tab} but not sure how to modify. I primarily would like to adjust the background for the titles and potentially move it.

A perfect continuation of this guide/post would be some guidence how to modify the delivery slip as well? Although after this guide I feel confident enough to have a look at least... :)

Link to comment
Share on other sites

  • 3 weeks later...

Great Info here! I learned so much!

 

Quick question:

 

Anyone know how to create seperate invoices for different countries and have the system recognize this? I would be interested in having two seperate types of invoices, one for my clients in Switz and the others for Germany/ france.

 

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

I have found this post very useful. Currently when I upgrade Prestashop, I keep a folder on my local drive that includes the modified .tpl files to upload into the PDF directory after an upgrade. I was wondering if it would be possible to create a PDF directory in my custom theme directory that inludes the .tpl files, then have an Override file in override/classes/pdf that would force the PDF generation to pickup the modified template files in my custom theme? That would simplify upgrading for everyone.

 

Anybody care to take this on, or suggest a similar approach so that autoupgrade doesn't overwrite the customized PDF files?

Link to comment
Share on other sites

Hi Rhapsody,

why so complicated. ;)

It's totally simple. Just create the pdf directory in your custom themes directory.

The files you put here will automatically override the default PDF files. That's all. No additional change necessary.

 

Same solution possible for the mails directory, if you apply some modifications here, too.

  • Like 1
Link to comment
Share on other sites

Okey I'm blind.

I totally missed the "tools" folder, hehe.

 

Anyways.

 

On line 23.203 i have the following:

} else {

on 23.205 i have this:

}

On 24.618 this:

$this->y += $this->getHTMLUnitToUnits($table_el['attribute']['cellspacing'], 1, 'px');

and on 24.650 this

if (isset($this->theadMargins['top'])) {

 

m3442a .. can you post your lines from 24203 to 24205 and from 24618 to 24650 ?

this error is normal when there is a typo in your invoice.txt

<table style="width: 100%;">
<tr>
 <td style="width: 17%"></td>
  <td style="width: 66%">{if $available_in_your_account}{l s='An electronic version of this invoice is available in your account. To access it, log in to our website using your e-mail address and password (which you created when placing your first order).' pdf='true'}{/if}</td>
 </td style="width: 17%"></td>
</tr>
</table>  

You have a closing td instead of an opening td in the last td rule ;)

Link to comment
Share on other sites

Does anybody know of you guys how I manage to add the gender to both invoice and delivery address, so that you get something like

 

Mrs

Ronda Nuttleback

,,,

 

in invoice.tpl

This really drives me mad because I don't know how to solve this problem and in Germany a personalized address format is the normal case.

Link to comment
Share on other sites

I have some custom fields defined in the ps_customer table. In the old 1.4 PS I was able to include these in the PDF.php override file to have them display on the PDF invoice. Can I do similar using just the template files with 1.5? For example - the custom field names in the ps_customer table are member and spouse. If the customer purchase products with ID 6, 10, 15, 17 or 26 then display a section on the invoice that includes the custom fields.

 

Bellini helped me with this as on override for my custom invoice in PS 1.4. I'm doing other shop mods and getting ready to upgrade a shop from 1.4.10.0 to 1.5. The customized invoice is the last item I need to make work.

 

What I want to do is check if certain products were purchased, and if they were, display a section with the custom field names.

Link to comment
Share on other sites