-
-
Save Sentinel-7/9d1750ac465a32999d14030c46acc00c to your computer and use it in GitHub Desktop.
Localizator подгрузка лексиконов для mFilter2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$eventName = $modx->event->name; | |
switch($eventName) { | |
// case 'OnWebPageInit': | |
// if ($modx->context->get('key') == 'mgr') {return;} | |
// $modx->lexicon->load($modx->cultureKey . ':minishop2:default'); | |
// break; | |
case 'OnParseDocument': | |
if ($modx->context->get('key') == 'mgr') {return;} | |
if(isset($_COOKIE['lang'])){ | |
$lang = $_COOKIE['lang']; | |
} | |
if (!isset($lang)) { | |
$modx->lexicon->load($modx->cultureKey . ':minishop2:default'); | |
$modx->lexicon->load($modx->cultureKey . ':localizator:site'); | |
return; | |
} | |
$modx->setOption('cultureKey', $lang); | |
$modx->lexicon->load($lang . ':minishop2:default', $lang . ':localizator:site'); | |
break; | |
case 'OnLoadWebDocument': | |
if ($modx->context->get('key') == 'mgr') {return;} | |
$value = $modx->getOption('cultureKey'); | |
setcookie('lang', $value, time() + (86400 * 31)); | |
break; | |
case 'msOnBeforeAddToCart': | |
case 'msOnBeforeRemoveFromCart': | |
case 'msOnBeforeChangeInCart': | |
case 'msOnSubmitOrder': | |
$request = $_SERVER['HTTP_REFERER']; | |
$host = $find = $_SERVER['HTTP_HOST']; | |
if($request) { | |
if(strpos($request, '/') !== false) { | |
$request = str_replace($_SERVER['HTTP_ORIGIN'] . '/', '', $request); | |
$tmp = explode('/', $request); | |
$find = $host . '/' . $tmp[0] . '/'; | |
} else { | |
$find = $host . '/' . $request; | |
} | |
} | |
$q = $modx->newQuery('localizatorLanguage', array( | |
array('http_host' => $find), | |
array('OR:http_host:=' => $host) | |
)); | |
$q->select('cultureKey'); | |
$lang = $modx->getValue($q->prepare()); | |
$modx->setOption('cultureKey', $lang); | |
$modx->lexicon->load($lang . ':minishop2:cart'); | |
break; | |
case 'msOnChangeOrderStatus': | |
$address = $modx->getObject('msOrderAddress', $order->get('id')); | |
$properties = $address->get('properties'); | |
if ($properties) { | |
$lang = $properties[extfld_lang]; | |
if ($lang) { | |
// $modx->log(xPDO::LOG_LEVEL_ERROR,'$properties[extfld_lang]' . $properties[extfld_lang]); | |
// $modx->setOption('cultureKey', $lang); | |
$modx->lexicon->load($lang . ':minishop2:default', $lang . ':minishop2:cart', $lang . ':localizator:site'); | |
} | |
} | |
break; | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment