AndriusS Posted November 12, 2013 Share Posted November 12, 2013 Hey! Site requires some more controls.Rather than going to the settings and changing the language there, I'd like to have a language switch in a different place. I've decided on getting the languages in the header.tpl. So, I've worked out some stuff like this: <a href="?change_lang=4">Lang4</a> <a href="?change_lang=1">Lang1</a> <a href="?change_lang=6">Lang6</a> <a href="?change_lang=5">Lang5</a> I felt lazy and just updated the admin's index.php file to have this: if(isset($_GET['change_lang'])) { $_GET['id_lang'] = $_GET['change_lang']; Tools::switchLanguage(); Tools::setCookieLanguage(); } The language changes at first, BUT it is not saved. I've skimmed through the methods and they should do that stuff themselves as switchLanguage uses $_GET['id_lang'] and puts it in the cookie. And, well, the second one is just a guess that I might also need it too. Does not seem to work for me now. Thanks for the help! Link to comment Share on other sites More sharing options...
AndriusS Posted November 13, 2013 Author Share Posted November 13, 2013 Bump bump! Link to comment Share on other sites More sharing options...
vekia Posted November 13, 2013 Share Posted November 13, 2013 hello why not to use {$link->getLanguageLink(1)|escape:htmlall} {$link->getLanguageLink(2)|escape:htmlall} {$link->getLanguageLink(3)|escape:htmlall} method than links like <a href="?change_lang=5"> and function with Tools object? much easier and will work. always Link to comment Share on other sites More sharing options...
AndriusS Posted November 13, 2013 Author Share Posted November 13, 2013 Thanks for the reply! That does not seem to work in the Back Office. It adds a domain/SOME_LANG/... which results in a front office "page not found". 1 Link to comment Share on other sites More sharing options...
vekia Posted November 13, 2013 Share Posted November 13, 2013 ohhh my bad! you're talking about back office, so sorry, my mistake :/ Link to comment Share on other sites More sharing options...
AndriusS Posted November 13, 2013 Author Share Posted November 13, 2013 Yeah Well. If you have any other ideas, I'll take them! Any clue where the method is that does the language change on those language links? Uhhh, annoying! Link to comment Share on other sites More sharing options...
AndriusS Posted November 14, 2013 Author Share Posted November 14, 2013 Bump. Still no idea! Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted November 14, 2013 Share Posted November 14, 2013 (edited) You can override classes file ../classes/controller/AdminController.php in function postProcess() and function initHeader() something like this ... class AdminController extends AdminControllerCore { public function postProcess() { if(Tools::isSubmit('changeLang')) { $context = Context::getContext(); $employee = new Employee($context->employee->id); if($employee->id_lang != Tools::getValue('id_lang')) { $employee->id_lang = Tools::getValue('id_lang'); if($employee->update()) $this->redirect_after = self::$currentIndex.'&token='.$this->token; } } parent::postProcess(); } public function initHeader() { parent::initHeader(); $this->context->smarty->assign(array( 'languages' => Language::getLanguages(false), 'thisIndex' => self::$currentIndex.'&token='.$this->token )); } } And then modify admin theme file header.tpl within <ul id="employee_links"> to add : {foreach from=$languages item=lang} {if $iso_user != $lang.iso_code} <li><a href="{$thisIndex}&id_lang={$lang.id_lang}&changeLang">{$lang.iso_code}</a></li> <li class="separator"> </li> {/if} {/foreach} Edited November 14, 2013 by gonebdg - webindoshop.com (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now