Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Localizator подгрузка лексиконов для mFilter2
<?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