Post by spstore » Wed Sep 18, 2024 9:11 am

Hello,

I want to create a second invoice template to be printed in a different language.

I know how create the new twig template, add the button, etc, but the only issue is that I don't know how to load the 2nd language on the controller instead of the default language.

Text always appears in the English language (the default language of the backend).

I guess that i need to change something to the following part:

Code: Select all


	public function invoice() {
		$this->load->language('sale/order');

		$data['title'] = $this->language->get('text_invoice');

		if ($this->request->server['HTTPS']) {
			$data['base'] = HTTPS_SERVER;
		} else {
			$data['base'] = HTTP_SERVER;
		}

		$data['direction'] = $this->language->get('direction');
		
		$data['lang'] = $this->language->get('code');

.....

OC Version: 3.0.3.8


Any suggestions?

Thanks everyone in advance!

Newbie

Posts

Joined
Sat Aug 26, 2023 8:14 pm
Location - Athens

Post by halfhope » Wed Sep 18, 2024 3:01 pm

Hi!

Code: Select all

$language = new Language('de-de'); // language directory by default it's $this->config->get('language_directory')

$this->registry->set('language', $language);

$this->load->language('sale/order');

My FREE extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by spstore » Thu Sep 19, 2024 5:55 am

halfhope wrote:
Wed Sep 18, 2024 3:01 pm
Hi!

Code: Select all

$language = new Language('de-de'); // language directory by default it's $this->config->get('language_directory')

$this->registry->set('language', $language);

$this->load->language('sale/order');
Hello Halfhope.

This worked great!
Thank you for it and the explanation also!

By the way, is there a method to change the products and totals language in the invovice?
Or can these only receive the language that the order is originaly placed ?
For example if order is placed in English I receive products and order totals in English even if I use your method.

Thank you in advance!

Newbie

Posts

Joined
Sat Aug 26, 2023 8:14 pm
Location - Athens

Post by halfhope » Thu Sep 19, 2024 6:46 am

Try to substitute config_language_id value in config class.

Code: Select all

$this->config->set('config_language_id', 3);

My FREE extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by nonnedelectari » Thu Sep 19, 2024 6:37 pm

spstore wrote:
Thu Sep 19, 2024 5:55 am
halfhope wrote:
Wed Sep 18, 2024 3:01 pm
Hi!

Code: Select all

$language = new Language('de-de'); // language directory by default it's $this->config->get('language_directory')

$this->registry->set('language', $language);

$this->load->language('sale/order');
Hello Halfhope.

This worked great!
Thank you for it and the explanation also!

By the way, is there a method to change the products and totals language in the invovice?
Or can these only receive the language that the order is originaly placed ?
For example if order is placed in English I receive products and order totals in English even if I use your method.

Thank you in advance!
Order totals are literally written to the database upon order creation, order products as well I think. They are not guided by the language id after that.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by spstore » Thu Sep 19, 2024 11:31 pm

halfhope wrote:
Thu Sep 19, 2024 6:46 am
Try to substitute config_language_id value in config class.

Code: Select all

$this->config->set('config_language_id', 3);
Thank you for the reply halfhope,

I am a bit confused with this line.
Where this could be added?

Thank you in advance!

Newbie

Posts

Joined
Sat Aug 26, 2023 8:14 pm
Location - Athens

Post by halfhope » Fri Sep 20, 2024 7:08 am

spstore wrote:
Thu Sep 19, 2024 11:31 pm
Where this could be added?
Before model getter functions. 3 it's your language_id.

My FREE extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by nonnedelectari » Fri Sep 20, 2024 7:06 pm

halfhope wrote:
Fri Sep 20, 2024 7:08 am
spstore wrote:
Thu Sep 19, 2024 11:31 pm
Where this could be added?
Before model getter functions. 3 it's your language_id.
As stated, the order product name and model as well as the order totals titles are written into the respective tables in the language the order was placed in.
They cannot be dynamically changed into a different language by means of the language id alone.
You would have to recreate that information based on the different language id as well as the order id and the product ids in the order_product_table as well as the order_totals table.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by spstore » Fri Sep 20, 2024 10:43 pm

Thank you both for the replies.

As I understand there is no way to change it dynamically as @nonnedelectari mentioned.

This has to be done through the creation of the order. So I guess I need to find a walk-around method for fixing this and being able to print a translated invoice.

Maybe a replacement method (filter) would work in the twig file?

Thank you all in advance!

Newbie

Posts

Joined
Sat Aug 26, 2023 8:14 pm
Location - Athens

Post by nonnedelectari » Fri Sep 20, 2024 11:12 pm

spstore wrote:
Fri Sep 20, 2024 10:43 pm
Thank you both for the replies.

As I understand there is no way to change it dynamically as @nonnedelectari mentioned.

This has to be done through the creation of the order. So I guess I need to find a walk-around method for fixing this and being able to print a translated invoice.

Maybe a replacement method (filter) would work in the twig file?

Thank you all in advance!

You would basically have to rewrite the public function invoice().
Give it a language id parameter of the language you want the invoice to be printed in.

Set the language id so the normal control information like headers and such are in that language, as you already have done.

Check the language id the order was written in, it is in the order table, if that is the same, no problem.
if it is different, problem.
you need to check each order product id and get the name and model from the product and product description table for that product in that language and use that.
and you need to get the order total titles from every totals extension language file in that language for every totals extension used in the order, subtotal, total, discounts, fees, shipping, handling, the works.

that is not a twig effort.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm
Who is online

Users browsing this forum: Mariogs and 33 guests