Post by spstore » Thu Jul 25, 2024 3:05 am

Hello,

I am working on OC 3.0.3.8

It's the first time that i attempt to pass data from an extension (shipping extension) to the order info page.
So basically I am trying to pass the tracking number and some other info from the extension to the order info page.

As I understand I need to pass the data from the extension's controller to controller/sale/order.php first.
So the values will be displayed to order_info.twig

I start with the basics as I am a beginner.
Therefore I am trying to load the language files first.

I named the extension as "MyExtension" for reference.

The code that I use is:

in admin/controller/sale/order.php
After line 1273: $data['footer'] = $this->load->controller('common/footer');

Code: Select all

$this->load->controller('extension/shipping/MyExtenison');
$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');      
If I use {{ my_extenion_text }} I receive the English language always. I want to load the Greek language instead of English.
I tried to use $this->load->language('el-gr/extension/shipping/MyExtenison');
But I guess it doesn't work like that since I get no value at all.

How could I do this?

Thank you in advance!

Newbie

Posts

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

Post by nonnedelectari » Thu Jul 25, 2024 11:09 am

spstore wrote:
Thu Jul 25, 2024 3:05 am
Hello,

I am working on OC 3.0.3.8

It's the first time that i attempt to pass data from an extension (shipping extension) to the order info page.
So basically I am trying to pass the tracking number and some other info from the extension to the order info page.

As I understand I need to pass the data from the extension's controller to controller/sale/order.php first.
So the values will be displayed to order_info.twig

I start with the basics as I am a beginner.
Therefore I am trying to load the language files first.

I named the extension as "MyExtension" for reference.

The code that I use is:

in admin/controller/sale/order.php
After line 1273: $data['footer'] = $this->load->controller('common/footer');

Code: Select all

$this->load->controller('extension/shipping/MyExtenison');
$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');      
If I use {{ my_extenion_text }} I receive the English language always. I want to load the Greek language instead of English.
I tried to use $this->load->language('el-gr/extension/shipping/MyExtenison');
But I guess it doesn't work like that since I get no value at all.

How could I do this?

Thank you in advance!

Code: Select all

$this->language->get
uses the currently set language id in config so you have to temporarily change that to the id of your greek language

you could try:

Code: Select all

// save current language id
$language_id_save = $this->config->get('config_language_id');
// set new language id
$language_id_new = the id of your greek language;
$this->config->set('config_language_id',$language_id_new);


$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');  


// restore previous language id
$this->config->set('config_language_id',$language_id_save);

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by spstore » Fri Jul 26, 2024 1:53 am

nonnedelectari wrote:
Thu Jul 25, 2024 11:09 am
spstore wrote:
Thu Jul 25, 2024 3:05 am
Hello,

I am working on OC 3.0.3.8

It's the first time that i attempt to pass data from an extension (shipping extension) to the order info page.
So basically I am trying to pass the tracking number and some other info from the extension to the order info page.

As I understand I need to pass the data from the extension's controller to controller/sale/order.php first.
So the values will be displayed to order_info.twig

I start with the basics as I am a beginner.
Therefore I am trying to load the language files first.

I named the extension as "MyExtension" for reference.

The code that I use is:

in admin/controller/sale/order.php
After line 1273: $data['footer'] = $this->load->controller('common/footer');

Code: Select all

$this->load->controller('extension/shipping/MyExtenison');
$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');      
If I use {{ my_extenion_text }} I receive the English language always. I want to load the Greek language instead of English.
I tried to use $this->load->language('el-gr/extension/shipping/MyExtenison');
But I guess it doesn't work like that since I get no value at all.

How could I do this?

Thank you in advance!

Code: Select all

$this->language->get
uses the currently set language id in config so you have to temporarily change that to the id of your greek language

you could try:

Code: Select all

// save current language id
$language_id_save = $this->config->get('config_language_id');
// set new language id
$language_id_new = the id of your greek language;
$this->config->set('config_language_id',$language_id_new);


$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');  


// restore previous language id
$this->config->set('config_language_id',$language_id_save);
Thank you for the answer nonnedelectari.
I appreciate your time to respond.

I tried this but still loads the same English text.
I simply added the 'el-gr' to the $language_id_new

Code: Select all

// save current language id
$language_id_save = $this->config->get('config_language_id');
// set new language id
$language_id_new = 'el-gr';
$this->config->set('config_language_id',$language_id_new);


$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');  


// restore previous language id
$this->config->set('config_language_id',$language_id_save);
Do I miss something? or do I need to change something else?

Thank you in advance!

Newbie

Posts

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

Post by by mona » Fri Jul 26, 2024 2:11 am

id is a number not a 'code'. You need to look it up in your database, or use right click in admin
languages use language files - these files are codes
This is Opencarts filing structure and the way it works
https://github.com/opencart/opencart/wi ... art-Basics

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by spstore » Fri Jul 26, 2024 3:16 am

by mona wrote:
Fri Jul 26, 2024 2:11 am
id is a number not a 'code'. You need to look it up in your database, or use right click in admin
languages use language files - these files are codes
This is Opencarts filing structure and the way it works
https://github.com/opencart/opencart/wi ... art-Basics
hello Mona

Thanks for the reply and the clarification!

You are correct about the id. My mind was stacked on the 'code'
I found that my language id is 2.

So I used this:

Code: Select all

$language_id_new = '2';
            $this->config->set('config_language_id','$language_id_new');
I tried to use simple 2 and '2'.
It still appears in English .

I am so confused with this.

Attachments

db-language.jpg

db-language.jpg (29.78 KiB) Viewed 1101 times


Newbie

Posts

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

Post by by mona » Fri Jul 26, 2024 3:36 am

You have created a language file for greek as per the orange box in the link I attached?

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by spstore » Fri Jul 26, 2024 3:58 am

by mona wrote:
Fri Jul 26, 2024 3:36 am
You have created a language file for greek as per the orange box in the link I attached?
Yes. The store is fully functional as it's a clone of my live store.

The specific extension that I use has both English and Greek file structures.

Does it play any role in the admin language or anything else in twig?

Thanks in advance!

Newbie

Posts

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

Post by nonnedelectari » Fri Jul 26, 2024 8:44 am

spstore wrote:
Fri Jul 26, 2024 1:53 am
nonnedelectari wrote:
Thu Jul 25, 2024 11:09 am
spstore wrote:
Thu Jul 25, 2024 3:05 am
Hello,

I am working on OC 3.0.3.8

It's the first time that i attempt to pass data from an extension (shipping extension) to the order info page.
So basically I am trying to pass the tracking number and some other info from the extension to the order info page.

As I understand I need to pass the data from the extension's controller to controller/sale/order.php first.
So the values will be displayed to order_info.twig

I start with the basics as I am a beginner.
Therefore I am trying to load the language files first.

I named the extension as "MyExtension" for reference.

The code that I use is:

in admin/controller/sale/order.php
After line 1273: $data['footer'] = $this->load->controller('common/footer');

Code: Select all

$this->load->controller('extension/shipping/MyExtenison');
$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');      
If I use {{ my_extenion_text }} I receive the English language always. I want to load the Greek language instead of English.
I tried to use $this->load->language('el-gr/extension/shipping/MyExtenison');
But I guess it doesn't work like that since I get no value at all.

How could I do this?

Thank you in advance!

Code: Select all

$this->language->get
uses the currently set language id in config so you have to temporarily change that to the id of your greek language

you could try:

Code: Select all

// save current language id
$language_id_save = $this->config->get('config_language_id');
// set new language id
$language_id_new = the id of your greek language;
$this->config->set('config_language_id',$language_id_new);


$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');  


// restore previous language id
$this->config->set('config_language_id',$language_id_save);
Thank you for the answer nonnedelectari.
I appreciate your time to respond.

I tried this but still loads the same English text.
I simply added the 'el-gr' to the $language_id_new

Code: Select all

// save current language id
$language_id_save = $this->config->get('config_language_id');
// set new language id
$language_id_new = 'el-gr';
$this->config->set('config_language_id',$language_id_new);


$this->load->language('extension/shipping/MyExtenison');
$data['my_extension_text'] = $this->language->get('this_is_my_text');  


// restore previous language id
$this->config->set('config_language_id',$language_id_save);
Do I miss something? or do I need to change something else?

Thank you in advance!
give this a try:

Code: Select all

		// overwrite language object with greek
		$language = new Language('el-gr');
		$language->load('el-gr');
		$this->registry->set('language', $language);		
		
		$this->load->language('extension/shipping/MyExtenison');
		$data['my_extension_text'] = $this->language->get('this_is_my_text'); 
		
		// restore default language
		$language = new Language($this->config->get('config_admin_language'));
		$language->load($this->config->get('config_admin_language'));
		$this->registry->set('language', $language);

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by by mona » Fri Jul 26, 2024 7:23 pm

spstore wrote:
Fri Jul 26, 2024 3:58 am
by mona wrote:
Fri Jul 26, 2024 3:36 am
You have created a language file for greek as per the orange box in the link I attached?
Yes. The store is fully functional as it's a clone of my live store.

The specific extension that I use has both English and Greek file structures.

Does it play any role in the admin language or anything else in twig?

Thanks in advance!
I am not sure what you are doing, but if you are trying to call a catalog language file from a admin controller it is not the same. You can duplicate the language file from catalog into admin and call it from the admin controller.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am
Who is online

Users browsing this forum: jog2le and 17 guests