José Antonio 1 Posted August 9, 2018 (edited) I can not make this function work. I should take the invoice template by country code, I have tried as invoice.tpl.US or invoice.US but it does not work, it always returns template by default, does anyone know how to create templates by delibery address? HTMLTemplateIvoice.tpl /** * Returns the invoice template associated to the country iso_code * * @param string $iso_country */ protected function getTemplateByCountry($iso_country) { $file = Configuration::get('PS_INVOICE_MODEL'); // try to fetch the iso template $template = $this->getTemplate($file.'.'.$iso_country); // else use the default one if (!$template) { $template = $this->getTemplate($file); } return $template; } I need to use templates by country of delibery destination. Thanks! Edited August 9, 2018 by José Antonio (see edit history) Share this post Link to post Share on other sites
José Antonio 1 Posted August 9, 2018 Ok, its solved, filenamed as invoice.US.tpl but i want take ISO by state no country. public function getContent() { $invoiceAddressPatternRules = json_decode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true); $deliveryAddressPatternRules = json_decode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true); $invoice_address = new Address((int)$this->order->id_address_invoice); $country = new Country((int)$invoice_address->id_country); $state = new State((int)$invoice_address->id_state); $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, $invoiceAddressPatternRules, '<br />', ' '); $delivery_address = null; $formatted_delivery_address = ''; if (isset($this->order->id_address_delivery) && $this->order->id_address_delivery) { $delivery_address = new Address((int)$this->order->id_address_delivery); $state = new State((int)$id_address_delivery->id_state); $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, '<br />', ' '); } ////////////////////// return $this->smarty->fetch($this->getTemplateByState($state->iso_code)); ////////////////////// protected function getTemplateByState($iso_state) { $file = Configuration::get('PS_INVOICE_MODEL'); // try to fetch the iso template $template = $this->getTemplate($file.'.'.$iso_state); // else use the default one if (!$template) { $template = $this->getTemplate($file); } return $template; } Not working Share this post Link to post Share on other sites
José Antonio 1 Posted August 10, 2018 solved: $state = $delivery_address->id_state; ///// return $this->smarty->fetch($this->getTemplateByState($state)); ///// protected function getTemplateByState($state) { $file = Configuration::get('PS_INVOICE_MODEL'); // try to fetch the iso template $template = $this->getTemplate($file.'.'.$state); // else use the default one if (!$template) { $template = $this->getTemplate($file); } return $template; } 1 Share this post Link to post Share on other sites
JohnDom 0 Posted August 1, 2019 Hi José Could you explain how you managed to create this? I have the same need to create a template based on the customer's delivery address country. Share this post Link to post Share on other sites
José Antonio 1 Posted August 2, 2019 Hi. Template by state is default in prestashop, you must create template as invoice.iso_country.tpl in pdf folder. Example: invoice.61.tpl You can see this function on ROOT/classes/pdf/HTMLTemplateInvoice.php protected function getTemplateByCountry($iso_country) { $file = Configuration::get('PS_INVOICE_MODEL'); // try to fetch the iso template $template = $this->getTemplate($file . '.' . $iso_country); // else use the default one if (!$template) { $template = $this->getTemplate($file); } return $template; } I modified the function for a template by state. Regards. Share this post Link to post Share on other sites
zklid 0 Posted September 15, 2020 Hi, I'm interested in this solution. I would like a different invoice for each country of sale. Does your solution assign an increasing number (id) to the invoice based on the country? example: Italy: invoice 1, 2, 3 etc. Spain: Invoice 1, 2, 3 etc? Share this post Link to post Share on other sites