Skip to content

Instantly share code, notes, and snippets.

@madcatgith
Created November 11, 2016 10:29
Show Gist options
  • Save madcatgith/a4e12b8f2098b278adafc1257b4c618b to your computer and use it in GitHub Desktop.
Save madcatgith/a4e12b8f2098b278adafc1257b4c618b to your computer and use it in GitHub Desktop.
/*Фикс для переключения языков в продукте*/
public static function getLangByTemplate($tplID = 1) {
$tpl = new Template();
$langArray = self::getLanguages();
$menuID = Url::get('menuID');
$contentID = Url::get('contentID');
$productID = Url::get('productID');
$tagID = Url::get('tagID');
if (count($langArray) == 0) {
return '';
}
if ($tagID > 0) {
foreach ($langArray as $key => $lang) {
$langArray[$key]['href'] = Url::setUrl(array('lang' => $key, 'menu' => $menuID, 'tag' => Url::get('tagCnc') . '-' . $tagID));
}
} else if ($contentID > 0) {
foreach ($langArray as $key => $lang) {
$langArray[$key]['href'] = Url::setUrl(array('lang' => $key, 'menu' => $menuID, 'content' => Url::get('contentCNC')));
}
} else if ($productID > 0) {
$ps = array();
$res = Registry::get('db')->query('select lang_id,cnc from ?_product where id=' . $productID,true);
foreach ($res->fetchAll() as $r) {
$ps[$r['lang_id']] = $r['cnc'];
}
foreach ($langArray as $key => $lang) {
$langArray[$key]['href'] = Url::setUrl(array('lang' => $key, 'menu' => $menuID, 'product' => $ps[$key]));
}
} else if ($menuID > 0) {
foreach ($langArray as $key => $lang) {
$langArray[$key]['href'] = Url::setUrl(array('lang' => $key, 'menu' => $menuID));
}
} else {
foreach ($langArray as $key => $lang) {
$langArray[$key]['href'] = Url::setUrl(array('lang' => $key));
}
}
$tpl->assign('langArray', $langArray);
return $tpl->fetch(BASEPATH . 'lib/wmpLang/template_' . $tplID . '.tpl');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment