Jump to content

Add variable "lastname" in invoice pdf


webrider

Recommended Posts

Hi,

I'm trying to add the variable "lastname" (Dear "title" "lastname") in my pdf invoice to display an introduction sentence.

 

I've tried all what I have found and not working, if anyone have an idea!!! would be fantastic!

 

1/ I have modified the invoice.tpl adding various code:

 

<td><span>{l s='Dear' pdf='true'}</span>{l s='Carrier:' pdf='true'}<br />
           

{$customer->lastname}
         

($invoice_address->lastname)   
            

$this->context->customer->lastname

 

2/ I have then tried to modify  classes/pdf/templateinvoice.php  adding the line in red.

 

$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
            'lastname' => $this->customer->lastname
        ));

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

 

And in all cases, it doesn't work. I don't know too much about php but I beleive this is quite simple to do like in the email templates!

Link to comment
Share on other sites

Hi tuk66,

 

I've tried {$lastname} as follow and still can't get it. Thank you anyway!

 

<td><span>{l s='Dear' pdf='true'}</span>{l s='Carrier:' pdf='true'}<br />

           

{$lastname}

Link to comment
Share on other sites

Hi,

 

I emptied the cache with no result.

 

When I try to insert one of the 2 bolded lines in classes/pdf/templatedeliveryslip.php, I get an error (the pdf is not generated, blank page)

$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
            'lastname' => $this->context->customer->lastname,
               'lastname' => $this->formatted_delivery_address->lastname,

           
        ));


I get the same if I do it on templateinvoice.php in both cases it does break the pdf generation.

$data = array(
            'order' => $this->order,
            'order_details' => $order_details,
            'cart_rules' => $this->order->getCartRules($this->order_invoice->id),
            'delivery_address' => $formatted_delivery_address,
            'invoice_address' => $formatted_invoice_address,
            'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
            'tax_tab' => $this->getTaxTabContent(),
            'customer' => $customer
            'lastname' => $this->context->customer->lastname,
        );

 

I've tried to find some inspiration in the email sending process where it is easy to add this lastname! but my knowledge in php is far too limited...

Link to comment
Share on other sites

Hi,

 

I emptied the cache with no result.

 

When I try to insert one of the 2 bolded lines in classes/pdf/templatedeliveryslip.php, I get an error (the pdf is not generated, blank page)

 

$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

            'lastname' => $this->context->customer->lastname,

               'lastname' => $this->formatted_delivery_address->lastname,

 

           

        ));

 

 

I get the same if I do it on templateinvoice.php in both cases it does break the pdf generation.

 

$data = array(

            'order' => $this->order,

            'order_details' => $order_details,

            'cart_rules' => $this->order->getCartRules($this->order_invoice->id),

            'delivery_address' => $formatted_delivery_address,

            'invoice_address' => $formatted_invoice_address,

            'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),

            'tax_tab' => $this->getTaxTabContent(),

            'customer' => $customer

            'lastname' => $this->context->customer->lastname,

        );

 

I've tried to find some inspiration in the email sending process where it is easy to add this lastname! but my knowledge in php is far too limited...

Blank page is possibly because you need to add a comma on the line BEFORE one of the bold lines, so:

 

            'carrier' => $carrier,        <--

            'lastname' => $this->context->customer->lastname,

               'lastname' => $this->formatted_delivery_address->lastname,

 

 

and 

           'customer' => $customer,      <--

            'lastname' => $this->context->customer->lastname,

 

 

Also, make sure you temporarily turn Advanced Parameters-> Optimization: Force compilation -> ON

 

My 2 cents,

pascal

Link to comment
Share on other sites

1 week later... Pascal & PhpMadman I have applied your adivices and it works great, thank you for your time (and the others!).

 

so basically for people who'd like to personnalize their .pdf invoice, delivery slip...

 

in /CLASSES/PDF/DELIVERYSLIPTEMPLATE   I have added lines in bold

 

$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' => $customer,
'lastname' => $customer->lastname,
'firstname' => $customer->firstname,
 
));
 
return $this->smarty->fetch($this->getTemplate('delivery-slip'));
}
 
 
And in WWW/PDF/delivery-slip;php
 
<!-- / ADDRESSES -->
 
<table>
<tr><td style="line-height: 8px"> </td></tr>
</table>
<table style="width: 100%">
        <tr>
            <td style="width: 100%"><span>{l s='Dear ' pdf='true'}<b></span>{$firstname}
                {$lastname}<span>,</span>   
                             <br /><br />
                             
 
<span>Our welcome letter explained...
 
Well, on my side, perfect!
  • Like 1
Link to comment
Share on other sites

See that you don't use the {$customer}, so you could leave this one out in the smarty->assign.

Alternatively, I think you can ONLY define $customer, and then in the template file use {$customer->firstname} etc.

 

Furthermore, good work!

Happy selling,

Pascal

  • Like 1
Link to comment
Share on other sites

  • 6 years later...
On 5/5/2015 at 8:53 AM, webrider said:

Hi,

I'm trying to add the variable "lastname" (Dear "title" "lastname") in my pdf invoice to display an introduction sentence.

 

I've tried all what I have found and not working, if anyone have an idea!!! would be fantastic!

 

1/ I have modified the invoice.tpl adding various code:

 

<td><span>{l s='Dear' pdf='true'}</span>{l s='Carrier:' pdf='true'}<br />
           

{$customer->lastname}
         

($invoice_address->lastname)   
            

$this->context->customer->lastname

 

2/ I have then tried to modify  classes/pdf/templateinvoice.php  adding the line in red.

 

$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
            'lastname' => $this->customer->lastname
        ));

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

 

And in all cases, it doesn't work. I don't know too much about php but I beleive this is quite simple to do like in the email templates!

Please help me ! 

why my pdf is not chandeg when i modify invoice.tpl?

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