Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
Created August 29, 2019 21:26
Show Gist options
  • Save reanim8ed/1f50ab6df9e1ec6470531a144de21b80 to your computer and use it in GitHub Desktop.
Save reanim8ed/1f50ab6df9e1ec6470531a144de21b80 to your computer and use it in GitHub Desktop.
[Prestashop - remove default lang from url] #prestashop
class Link extends LinkCore
{
protected function getLangLink($id_lang = null, Context $context = null, $id_shop = null)
{
$parent_result = parent::getLangLink($id_lang, $context, $id_shop);
if ($parent_result) {
if ($id_lang == Configuration::get('PS_LANG_DEFAULT')) {
return '';
} else {
return $parent_result;
}
}
}
}
/*---------------*/
class Tools extends ToolsCore
{
public static function setCookieLanguage($cookie = null)
{
parent::setCookieLanguage($cookie);
if (!$cookie) {
$cookie = Context::getContext()->cookie;
}
if(!Tools::getValue('isolang') && !Tools::getValue('id_lang') && !Tools::isSubmit('id_category_layered')) {
$cookie->id_lang = Configuration::get('PS_LANG_DEFAULT');
Context::getContext()->language = new Language($cookie->id_lang);
}
/* If language file not present, you must use default language file */
if (!$cookie->id_lang || !Validate::isUnsignedId($cookie->id_lang)) {
$cookie->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
Context::getContext()->language = new Language($cookie->id_lang);
}
$iso = Language::getIsoById((int)$cookie->id_lang);
@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');
return $iso;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment