Jump to content

Barcode in invoice pdf with Order number


alldz

Recommended Posts

Hello,

To generate an barcode in pdf i user this code:


$pdf = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'));
$barcode_params = $pdf->serializeTCPDFtagParameters(array($this->order->invoice_number, 'C128', '', '', 0, 0, 0.2, array('position'=>'S', 'border'=>false, 'padding'=>0, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>0), 'N'));
$this->smarty->assign(array('barcode_params' => $barcode_params));

The problem is that the bar code generated with "$ this-> order-> INVOICE_NUMBER," uses the invoice number without the prefix, eg: 100 in places of IN000100

 

Do you have an idea on what to do to have the full invoice number?
Edited by alldz (see edit history)
Link to comment
Share on other sites

Try changing it to:

$pdf = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'));
$barcode_params = $pdf->serializeTCPDFtagParameters(array(Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number), 'C128', '', '', 0, 0, 0.2, array('position'=>'S', 'border'=>false, 'padding'=>0, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>0), 'N'));
$this->smarty->assign(array('barcode_params' => $barcode_params));
Link to comment
Share on other sites

  • 11 months later...

I found solution for convert order number to BARCODE image with this script 

https://www.codeproject.com/Articles/146336/Creating-a-Code-39-Barcode-using-HTML-CSS-and-Java

But i have problems to insert it inside a mail on Mailalert.

 

I tried to insert script directly mail but probabily is should modifiy mailalert.php

 

<script type="text/javascript" src="code39.js"></script>
    <style type="text/css">
   #barcode {font-weight: normal; font-style: normal; line-height:normal; sans-serif; font-size: 12pt}
    </style>
</head>
<body>


Input : {order_name}<br />


<div id="externalbox" style="width:5in">
<div id="inputdata" >{order_name}</div>
</div>


<br />


<script type="text/javascript">
/* <![CDATA[ */
  function get_object(id) {
   var object = null;
   if (document.layers) {
    object = document.layers[id];
   } else if (document.all) {
    object = document.all[id];
   } else if (document.getElementById) {
    object = document.getElementById(id);
   }
   return object;
  }
get_object("inputdata").innerHTML=DrawCode39Barcode(get_object("inputdata").innerHTML,0);
/* ]]> */
</script>
 
 

Can anyone help me please? thanks

Link to comment
Share on other sites

ok thanks.

 
I had seen the PHP script but I have a problem:
order confirmation email is sent as soon as we receive the order, so I should place that script to generate the images at the end of the order process to get the picture available for the mail .. can you suggest which route to take? thank you
Link to comment
Share on other sites

  • 11 months later...
On 30/09/2016 at 4:20 AM, rocky said:

Try changing it to:


$pdf = new PDFGenerator((bool)Configuration::get('PS_PDF_USE_CACHE'));
$barcode_params = $pdf->serializeTCPDFtagParameters(array(Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number), 'C128', '', '', 0, 0, 0.2, array('position'=>'S', 'border'=>false, 'padding'=>0, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>0), 'N'));
$this->smarty->assign(array('barcode_params' => $barcode_params));

 

Where do I add this code and would it work with PS 1.7?

Link to comment
Share on other sites

  • 7 months later...
  • 3 years later...

SOLVED - Hello guys , i've been searching many times and tried to use TCPDFBarcode module i wrote the code as mentioned in the TCPDF Documentation but did not work

i got an idea, which is to convert text to barcode using only html and css, i found it using a font family, and tried many times to include it in prestashop and finally found a solution ,

TCPDF can't recognize new fonts we have to convert it to its supported formats, so follow those steps :

A : Generate font by CLI (if there is a command line interface in your server otherwise read A steps and go to B steps)

1 - download woff2 file from : https://fonts.gstatic.com/s/librebarcode39/v19/-nFnOHM08vwC6h8Li1eQnP_AHzI2G_Bx0g.woff2
2 - convert it to .ttf format using this link : https://cloudconvert.com/woff2-to-ttf
3 - put .ttf file to this path \vendor\tecnickcom\tcpdf\tools (optionally: rename it because you will use that name as font-family name, Ex : barcodefont)
4 - use this command line to convert/add font by TCPDF : php tcpdf_addfont.php -i barcodefont.ttf (php required in your local host if you use B steps)
then 3 files will be generating to this path : \vendor\tecnickcom\tcpdf\fonts including font name 

barcodefont.php
barcodefont.ctg.z

barcodefont.z

B : convert font to TCPDF formats using your local machine

1 - install prestashop to your local host using xampp with compatible php version to prestashop 1.7 (xampp V3.3.0) Google that if you are not familiar with local host server
2 - after doing A steps , put those 3 files to \vendor\tecnickcom\tcpdf\fonts in your server
3 - use this in *.tpl file : <p style="font-family: 'barcodefont';font-size: 30px;text-align:center">*{$YOUR_VAR} or your text*</p>
NOTE : * is required before and after text, it's an encode technique of 'C39 type'
 

if you want to include some variables in invoice.tpl follow those steps:

1 - go to classes/pdf/HTMLTemplateInvoice.php

2 - search for getContent function 

3 - and add your variables before Data array ($data)  Ex : 

$phone_mobile= $invoice_address->phone_mobile; 
$phone= $invoice_address->phone;
$nb_orders = count(Order::getCustomerOrders((int)$this->order->id_customer)); // this is total orders of a client

4 - then add them below to Data array : 

'phone_mobile' => $phone_mobile,
'phone' => $phone,
'nb_orders' => $nb_orders,

5 - then insert your variable to invoice.tpl like this : {$phone_mobile)

if you want to convert it to barcode use this : 

<p style="font-family: 'barcodefont';font-size: 30px;text-align:center">*{$phone_mobile}*</p> // do not forget * before and after variable

DONE, if you find this useful share it ^^

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