Jump to content

Invoice Language


Recommended Posts

Hello, i searched half-google and didn`t get clear answer.

 

How can i set invoices in only one language? I have 2-language website, latvian and russian. We have official language in country - latvian, and i want to get ALL invoices in latvian, not on russian (my admin accaunt uses rus, and some customers uses it too). 

 

I tried to translate all PDF in localisation, but delivery and some module names still in russian. So - what should i modify? (Presta default language is latvian).

 

P.S.:

 

Found this soulution:

 

But i dont know how to make this line 

$this->order->id_lang

to get latvian (or default language, or lang id.). Tried some variants, but they didnt worked.

protected function getTemplate($template_name)
{
  $template = false;
  $default_template = _PS_PDF_DIR_.'/'.$template_name.'.tpl';
  $overriden_template = _PS_THEME_DIR_.'pdf/'.$template_name.'.tpl';
  if (file_exists($overriden_template))
   $template = $overriden_template;
  else if (file_exists($default_template))
   $template = $default_template;
  
  // SELECT ORDER LANGUAGE FOR THE TEMPLATE
  if ( $this->order )
    Context::getContext()->language = new Language($this->order->id_lang);
  
  return $template;
}
Link to comment
Share on other sites

You set the language for the whole shop using:

Context::getContext()->language

You should rather change the language just for the invoice. Look at the /classes/pdf/PDF.php file, the setFontForLang function

public function render($display = true)
    {
        $render = false;
        $this->pdf_renderer->setFontForLang(Context::getContext()->language->iso_code);
...
Link to comment
Share on other sites

  • 2 weeks later...

Hello! Thank you for answer. I changed

$this->pdf_renderer->setFontForLang(lv); /* Context::getContext()->language->iso_code*/

but invoice still generates in account language.

 

 

Found for me:

protected function getTemplate($template_name)
{
$template = false;
$default_template = _PS_PDF_DIR_.'/'.$template_name.'.tpl';
$overriden_template = _PS_THEME_DIR_.'pdf/'.$template_name.'.tpl';
if (file_exists($overriden_template))
$template = $overriden_template;
else if (file_exists($default_template))
$template = $default_template;

// SELECT ORDER LANGUAGE FOR THE TEMPLATE
if ( $this->order )
Context::getContext()->language = new Language($this->order->id_lang);

return $template;
}

In this line:

Context::getContext()->language = new Language($this->order->id_lang);

Changed 

$this->order->id_lang

to my language ID (Latvian was 2, so changed for 2) and my invoices become in one language.

Edited by Mr.SerikuS (see edit history)
Link to comment
Share on other sites

  • 1 month later...

first of all thanks for the answers. I´ve a similar problem.

I´ve customers from different countries with different languages.

 

When I download an invoice from an italian customer with my german backend language, than the invoice is generated in german.

Therefore I´ve to change my backends language for a few seconds to italian, download the invoice (now it´s in italian) and switch back to german again.

 

do you have any idead how I can change this behavior.

 

thx

Edited by Dr.Radon (see edit history)
Link to comment
Share on other sites

  • 3 years later...
On 2/1/2016 at 4:00 PM, tuk66 said:

It is a feature. In the Back Office, employee's language is used. In the Front Office, customer's one.

 

The M4 PDF Extensions module has a switch for changing the invoice language. See 11th image in the slideshow at http://www.presta-addons.com/en/modules/3-pdf-extensions.html

It's kind of an anti-feature if you print the PDF from backend in order to put it into shipping for the customer.

Also, paying for a rather expensive addon shouldn't be a necessity for something as basic as this.

So is there a possibility to change the file pdf.php in such a way that it always generates the invoice in the customer's language?

Link to comment
Share on other sites

  • 2 years later...

For anyone who may interest.

For Prestashop 1.6 & 1.7

To print invoice from BO with customer language, go to /classes/pdf/HTMLTemplateInvoice.php

 

Under public function __construct, serach for :

 // header informations
$this->date = Tools::displayDate($order_invoice->date_add);

Just insert below:

Context::getContext()->language = new Language($this->order->id_lang);

 

That's all

Edited by Crezco (see edit history)
  • Thanks 1
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...