Jump to content

Prestashop Invoices in different languages


Recommended Posts

Hi,

 

I have a prestashop that is configured in multiple languages. It works fine however, when I come to dispatch orders it only prints the invoices in the language of the administrator and not the language that the order was placed in. Is there a way the I could configure my shop so that it automatically generates invoices in the language that orders were placed as opposed to what I have to do at the moment which is login and out in the language that I which to generate the invoice?

 

Thanks in advance,

Stephen

 

matchafactory.fr

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...

I suggest checking that the translation for the language you want exists.

 

You can do this by (1.4) back office--translations-->

 

06.14.2013-10.33.29.png

http://screencast.com/t/SgbEZXFvtg

 

hope that helps

 

I believe this doesnt work.

 

As for a semi-workable solution, you can change the language of the admin user. I have a Spanish shop, but use an English BO. I could make a user that has Spanish as default language, and print my invoices from there.

 

Of course, this becomes a very tedius job when you have more than one language people can order in. One comforting thought: when people order in language XX, they can download the invoice in their language.

 

As for the real problem here: there needs to be a fix for this really..

Link to comment
Share on other sites

Imho, the invoices and all documents for the customers should be in customer’s language. But all translations, for front or for back office rely only on the language of the context object (means on the language of the visitor: customer in front end or employee in back end). Prestashop should rethink the translations of the customer documents in back office.

 

You can use this override of AdminPdfController. Valid only for version 1.5. and lightly tested only on my test version 1.5.4.1. I use it on a production site too. Please try it, and may be it could inspire some better solutions. This one is just a plaster, but is enough for my use.

 

It switches the context language to the language of the order before generating the pdf-document. It works only for a pdf for one order. It does not work for multiple invoices in the same pdf.

 

For a solution for multiple invoices, there are many things to change and I couldn’t find a very satisfying solution.

AdminPdfController.php

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Again, even on v155 I can only print customer invoices in French if the BO is in French.

As I am trying to use Presta as my main customer invoicing system,

I do not want to change admin language to French just to print an invoice for a counter customer

and I have other modules to buy rather than M4PF

I request a fix just to select language to print invoice or

if the customer language is French, then print a French invoice even if the BO is in English.

Edited by markjl (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 6 months later...
  • 5 months later...
  • 4 weeks later...

is there any solution for this?. because i got the same issue on prestashop 1.6.

 

Regards.

in classes/pdf/HTMLTemplate.php change:

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;

return $template;
	}
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;
	}

:)) works at least in ps 1.6.0.9

  • Like 3
Link to comment
Share on other sites

The solution of clubvapea works and is a good idea to place the language switch there, but be aware that it works only for the body of the pdf documents. The header and the footer of the pdf docs won't be in the expected language, depending on the conditions:
For one invoice only: the header stays in the backoffice language.
For multiple invoices in the same pdf, the header is in the language of the preceding order, and the footer is in the language of the next order (?!#*ç*%!!!)

So you have to adapt header and footer so they do not depend on language. Didn't check the other documents, but I expect there will be same kind of problems.

Link to comment
Share on other sites

  • 2 months later...

I have been having the problem pzi describes, the pdf header was still in the backend language. I have tried to figure out a fix today and it seems the header can be generated in the order language by adding the same code to the corresponding HTMLTemplate********.php files in /classes/pdf/

 

Such as the following for the Invoice PDF, HTMLTemplateInvoice.php:

class HTMLTemplateInvoiceCore extends HTMLTemplate
{
	public $order;
	public $available_in_your_account = false;

	public function __construct(OrderInvoice $order_invoice, $smarty)
	{
		$this->order_invoice = $order_invoice;
		$this->order = new Order((int)$this->order_invoice->id_order);
		$this->smarty = $smarty;
	  
	    // SELECT ORDER LANGUAGE FOR THE TEMPLATE
	    if ( $this->order )
	    Context::getContext()->language = new Language($this->order->id_lang);	  
	  
		// header informations
		$this->date = Tools::displayDate($order_invoice->date_add);

		$id_lang = Context::getContext()->language->id;
		$this->title = HTMLTemplateInvoice::l('Invoice ').' #'.Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, (int)$this->order->id_shop).sprintf('%06d', $order_invoice->number);
		// footer informations
		$this->shop = new Shop((int)$this->order->id_shop);
	}

This also seems to work in multiple PDFs generated at the same time.

 

However I was not able to add this to an override, if i move this function to an override i get the following error: "Cannot instantiate abstract class"

 

The footer is ok for single PDFs, but not for multiple PDFs, i have no idea why it uses the language of the next PDF in that case? Does anybody have an idea how to solve this?

 

 

  • Like 1
Link to comment
Share on other sites

in classes/pdf/HTMLTemplate.php change:

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;

return $template;
	}
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;
	}

:)) works at least in ps 1.6.0.9

 

Top ! Great Job !

Link to comment
Share on other sites

  • 2 months later...

Invoices are printed in administrator's language in Back Office and customer's language in her account. As I know there is no chance to choose a different language for invoices.

 

I can imagine to print invoices in Back Office in:

 

- customer's language

- selected language

 

For bulk printing the first option can result in mixed languages, so every page can be in a different language.

 

Everything mentioned above does the M4 PDF Extensions module. See http://www.presta-addons.com/154-large_default/pdf-extensions.jpg.

Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...

It is also possible to print invoices (and other PDF documents) in two or more languages at once.

 

The product name is always stored in customer's language. It is possible to directly print the name of the product, in more languages at once as well.

 

Let me know if you are interested.

Link to comment
Share on other sites

  • 4 years later...
On 10/22/2015 at 9:39 AM, tuk66 said:

It is also possible to print invoices (and other PDF documents) in two or more languages at once.

 

The product name is always stored in customer's language. It is possible to directly print the name of the product, in more languages at once as well.

 

Let me know if you are interested.

Hi,

About what you said here:

The product name is always stored in customer's language. It is possible to directly print the name of the product, in more languages at once as well.

I'd like to know what you're proposing.
I have a PS 1.6.1.17 in 2 languages Japanese and French. The company is french and based in France, but for Japanese customers so the defualt language is Japanese and second language is french.
So the Japanese customers order in their native languagen Japanese and have their own invoice from their customer account in Japanese.

Now,  when I'm connected with the back-office in french, and try to print invoices from the back-end, they show correctly in french but ONLY the product name remains either with little squares (not decoded) or in Japanese

Now, how could I have the same invoice with the product name in french ?

Thanks

Link to comment
Share on other sites

As I wrote, I suggest to use the M4 PDF Extensions module - https://www.presta-addons.com/en/prestashop-modules/3-pdf-extensions-prestashop.html

I have already done several different kind of invoices and you are not limited in languages showed on the invoice. You can even have product names in any language or more languages at once. So in your case, the whole invoice can be in French regardless the customer's language. Of course, Japanese version isn't contain "little squares" as Chinese-Japanese-Korean fonts are available.

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