= explode(',', $scriptProperties['filters']);
$tplRow = $scriptProperties['tplFilter.row'];
$tplOuter = $scriptProperties['tplFilter.outer'];
$filterKeys = [];
foreach($filters as $filter) {
$filterKey = reset(explode(':', end(explode('|', $filter))));
$filterKeys[$filterKey] = $filterKey;
}
$q = $modx->newQuery($copKey);
$q->select(array(
"{$copKey}.category_id",
"{$copKey}.option_id",
"{$opKey}.key"
));
$q->where(["{$copKey}.category_id" => $id]);
$q->leftJoin($opKey, $opKey, "{$copKey}.option_id = {$opKey}.id");
$q->prepare();
$q->stmt->execute();
$options = $q->stmt->fetchAll(PDO::FETCH_ASSOC);
$_options = [];
if(count($exclude) > 0) {
foreach ($options as $key => $option) {
if (array_search($option['key'], $exclude) > -1) {
unset($options[$key]);
}
}
}
foreach ($options as $option) {
if(!array_key_exists($option['key'], $filterKeys)) {
switch($option['type']) {
case 'checkbox':
$filter = ':boolean';
break;
case 'numberfield':
$filter = ':number';
break;
default:
$filter = '';
break;
}
if ($option['type'] == 'checkbox') {
$filter = ':boolean';
}
$_options[] = 'msoption|' . $option['key'] . $filter;
$scriptProperties['tplFilter.outer.msoption|' . $option['key']] = $tplOuter;
$scriptProperties['tplFilter.row.msoption|' . $option['key']] = $tplRow;
}
}
$scriptProperties['filters'] = implode(',', array_merge($_options, $filters));
return $modx->runSnippet('mFilter2@filter', $scriptProperties);
вот вызов сниппета
{'!mFilter3' | snippet : [
'includeThumbs' => 'standard',
'parents' => $_modx->resource.id,
'filters' => '
msoption|length:number,
msoption|width:number,
msoption|height:number,
msoption|thickness_mm:number,
msoption|color,
msoption|strana,
msoption|class,
msoption|species,
msoption|construction,
msoption|structure,
msoption|brightness,
msoption|coating,
msoption|collection,
msoption|lay_type,
[[--msoption|material,]]
ms|price:number',
'sortby' => '{"thumb":"desc","price":"asc"}',
'exclude' => $exclude,
'where' => '{ "template":"3"}',
'limit' => '40',
'cacheTime' => '3600',
'cache' => '3600',
'tplOuter' => 'tpl.mFilter2.outer.custom',
'tplFilter.outer' => 'tpl.mFilter2.filter.outer.custom',
'tplFilter.row' => 'tpl.mFilter2.filter.checkbox.custom',
Сниппет странный.. Попробуй с дефолтным
Тотже результат
Обсуждают сегодня