Jump to content
José Antonio

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)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More