Post by scottyboyyy » Fri Feb 03, 2023 1:32 am

I'm trying to access what the default language set to a store within Stores - Settings - local (tab) - language, here it can be set to any language but I can't find how to access it or where it is stored in the database.

This just gets the current language:

Code: Select all

(int)$this->config->get('config_language_id');
But I want to access the language it is set to within admin settings.

Anyone know? :D

Thanks!

opencart 3.0.1.2

Active Member

Posts

Joined
Fri Apr 07, 2017 2:36 am

Post by TMD Extension @ » Fri Feb 03, 2023 12:25 pm

get the current language from the session
$this->session->data['language']

from the database get the list of languages
$this->config->get('config_language')

or just print the current language code
echo $this->language->get('code')

You can use all these codes to get the language of the OpenCart Store

Image

Thanks & Regards
Sehaj Kaur
TMD Extensions
Contact Us For Customisations


Active Member

Posts

Joined
Thu Mar 17, 2022 12:59 pm

Post by by mona » Fri Feb 03, 2023 9:11 pm

Yes the above and to add to that ..

Code: Select all

$this->model_localisation_language->getLanguages();
gets all the languages you support in an array

Code: Select all

$this->request->cookie['language'];
gets the language code from the client cookie (if set)

Code: Select all

$this->config->get('config_language_id');
gets the current language id

Code: Select all

$this->session->data['language'];
gets the current language code (if set)

Code: Select all

$this->config->get('config_language');
gets your store's default language code (as set in admin)

All of these are used in the language part of catalog/controller/startup/startup.php
on every request, in order:
1) use the language stored in the session if present
2) otherwise use the language stored in the cookie if present
3) otherwise use the language set in the client language-accept header if present and supported
4) otherwise use the default language as set in admin
5) store the language code in the session and the language id in config

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: Google [Bot], moreduff and 268 guests