José Antonio Posted August 9, 2018 Share 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) Link to comment Share on other sites More sharing options...
José Antonio Posted August 9, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
José Antonio Posted August 10, 2018 Author Share 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 Link to comment Share on other sites More sharing options...
JohnDom Posted August 1, 2019 Share 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. Link to comment Share on other sites More sharing options...
José Antonio Posted August 2, 2019 Author Share 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. Link to comment Share on other sites More sharing options...
zklid Posted September 15, 2020 Share 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? 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