Jump to content

Invoice template by iso country


Recommended Posts

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 by José Antonio (see edit history)
Link to comment
Share on other sites

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

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;
    }

 

  • Like 1
Link to comment
Share on other sites

  • 11 months later...

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

  • 1 year later...

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

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