webrider Posted May 5, 2015 Share Posted May 5, 2015 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 More sharing options...
tuk66 Posted May 5, 2015 Share Posted May 5, 2015 Try {$lastname} Link to comment Share on other sites More sharing options...
webrider Posted May 6, 2015 Author Share Posted May 6, 2015 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 More sharing options...
tuk66 Posted May 6, 2015 Share Posted May 6, 2015 What about cache. If you have 'lastname' in the Smarty assign array, then {$lastname} should work. Link to comment Share on other sites More sharing options...
webrider Posted May 8, 2015 Author Share Posted May 8, 2015 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 More sharing options...
PhpMadman Posted May 8, 2015 Share Posted May 8, 2015 Hello. I'm curently on my phone right now. But before the smarty assign add: $customer = new Customer((int)$this->order->id_customer); And then assign lastname using $customer->lastname Link to comment Share on other sites More sharing options...
PhpMadman Posted May 8, 2015 Share Posted May 8, 2015 As for the context->customer code. That tries to retrive customer from current customer, and that you don't have in BO. Link to comment Share on other sites More sharing options...
PascalVG Posted May 9, 2015 Share Posted May 9, 2015 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 More sharing options...
webrider Posted May 16, 2015 Author Share Posted May 16, 2015 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! 2 Link to comment Share on other sites More sharing options...
PascalVG Posted May 17, 2015 Share Posted May 17, 2015 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 1 Link to comment Share on other sites More sharing options...
nasreddine hafidi Posted September 29, 2021 Share Posted September 29, 2021 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 More sharing options...
ps8modules Posted September 29, 2021 Share Posted September 29, 2021 Prestashop version ? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now