фильтр ресурсов по тв чз ajax не срабатывает
прикрепил к товарам твшки все настроил вроде правильно а не работает сволочуга, может я чтото упустил?
такой фильтр верстка
такой фильтр верстка
<div class="filterbox filter_content p-4 row">
<form class="filter_plan ajax-form">
<input type="hidden" name="sortby" value="pagetitle">
<input type="hidden" name="sortdir" value="asc">
<h2 class="text-center">Фильтр</h2>
<div class="area_form_box">
<h4 class="text-left">тип</h4>
<div class="form-check">
<input class="form-check-input checkbox-stage" value="ready" type="radio" name="types" >
<label class="form-check-label" >
готовое решение
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox-stage" value="modul" type="radio" name="types" >
<label class="form-check-label">
модульная кухня
</label>
</div>
</div>
<div class="area_form_box">
<h4 class="text-left">конфигурация</h4>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="config" value="line">
<label class="form-check-label">
прямая
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="config" value="ugol">
<label class="form-check-label">
угловая
</label>
</div>
</div>
<div class="area_form_box">
<h4 class="text-left">стиль</h4>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="style" value="classic">
<label class="form-check-label">
классика
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="style" value="sovr">
<label class="form-check-label">
современный
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="style" value="hitec">
<label class="form-check-label">
хай-тек
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="style" value="loft">
<label class="form-check-label">
лофт
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="style" value="scand">
<label class="form-check-label">
скандинавский
</label>
</div>
</div>
<div class="area_form_box">
<h4 class="text-left">материал фасада</h4>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="fasad" value="dsp">
<label class="form-check-label">
дсп
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="fasad" value="massive">
<label class="form-check-label">
массив
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="fasad" value="plastic">
<label class="form-check-label">
пластик
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="fasad" value="steklo">
<label class="form-check-label">
стекло
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="fasad" value="mdfplenka">
<label class="form-check-label">
мдф пленка
</label>
</div>
<div class="form-check">
<input class="form-check-input checkbox_stage" type="radio" name="fasad" value="mdfkraska">
<label class="form-check-label">
мдф краска
</label>
</div>
</div>
<div class="submit_btn mt-4">
<input class='reset_form ajax-reset mx-2 px-4' type="submit" value="Сбросить фильтр">
<input class='show mx-2 px-5 ajax-start' type="submit" value="Подобрать">
</div>
</form>
</div>сниппет<?php
//Filter Fields Settings
$filter = array();
//Radio, Select & Text Fields Type
if($_GET['types']) {
$filter[] = 'types='.$_GET['types'];
}
if($_GET['config']) {
$filter[] = 'config='.$_GET['config'];
}
if($_GET['style']) {
$filter[] = 'style='.$_GET['style'];
}
if($_GET['fasad']) {
$filter[] = 'fasad='.$_GET['fasad'];
}
//Two Text Fields From To
/*if($_GET['plot_area_from']) {
$filter[] = 'plot_area>='.$_GET['plot_area_from'];
}
if($_GET['plot_area_to']) {
$filter[] = 'plot_area<='.$_GET['plot_area_to'];
}
if($_GET['area_house_from']) {
$filter[] = 'area_house>='.$_GET['area_house_from'];
}
if($_GET['area_house_to']) {
$filter[] = 'area_house<='.$_GET['area_house_to'];
}
*/
//Checkbox Type
/*if($_GET['garage']) {
$filter[] = 'garage=1';
}*/
//End Settings
//Sort
if($_GET['sortby']) {
$sortby = $_GET['sortby'];
} else {
$sortby = 'pagetitle';
}
if($_GET['sortdir']) {
$sortdir = $_GET['sortdir'];
} else {
$sortdir = 'asc';
}
//End Sort
//Offset
$offset = 0;
if($_GET['offset']){
$offset = $_GET['offset'];
}
if($filter) {
$where = $modx->toJSON(array($filter));
} else {
$where = '';
}
$params_count = array(
'parents' => $parents,
'limit' => 0,
'tpl' => '@INLINE ,',
'select' => 'id',
'includeTVs' => $fields,
'showHidden' => '1',
'where' => $where
);
$count = $modx->runSnippet('msProducts',$params_count);
$count = count(explode(',',$count))-1;
$modx->setPlaceholder('count',$count);
$params = array(
'parents' => $parents,
'limit' => $limit,
'offset' => $offset,
'tpl' => $tpl,
'select' => 'id,pagetitle,introtext,content',
'includeTVs' => $fields,
'showHidden' => '1',
'sortby' => $sortby,
'sortdir' => $sortdir,
'where' => $where
);
$more = $count - $offset - $limit;
$lim = $more > $limit ? $limit : $more;
$button = '';
if($more > 0){
$button = '<div class="ajax-filter-count" data-count="'.$count.'"><a href="#" class="ajax-more">Загрузить еще '.$lim.' из '.$more.'</a></div>';
}
return $modx->runSnippet('msProducts',$params).$button;и сам скрипт js$(function() {
//MODx pdoResources Ajax Filter
//Filter Settings
var fadeSpeed = 200, // Fade Animation Speed
ajaxCountSelector = '.ajax-count', // CSS Selector of Items Counter
ajaxContainerSelector = '.ajax-container', // CSS Selector of Ajax Container
ajaxItemSelector = '.ajax-item', // CSS Selector of Ajax Item
ajaxFormSelector = '.ajax-form', // CSS Selector of Ajax Filter Form
ajaxFormButtonStart = '.ajax-start', // CSS Selector of Button Start Filtering
ajaxFormButtonReset = '.ajax-reset', // CSS Selector of Button Reset Ajax Form
sortDownText = 'По убыванию',
sortUpText = 'По возрастанию';
$('' + ajaxFormSelector + '').submit(function() {
return false;
});
function ajaxCount() {
if($('.ajax-filter-count').length) {
var count = $('.ajax-filter-count').data('count');
$(ajaxCountSelector).text(count);
} else {
$(ajaxCountSelector).text($(ajaxItemSelector).length);
}
}ajaxCount();
function ajaxMainFunction() {
$.ajax({
data: $(ajaxFormSelector).serialize()
}).done(function(response) {
var $response = $(response);
$(ajaxContainerSelector).fadeOut(fadeSpeed);
setTimeout(function() {
$(ajaxContainerSelector).html($response.find(ajaxContainerSelector).html()).fadeIn(fadeSpeed);
ajaxCount();
}, fadeSpeed);
});
}
$(ajaxContainerSelector).on('click', '.ajax-more', function(e) {
e.preventDefault();
var offset = $(ajaxItemSelector).length;
$.ajax({
data: $(ajaxFormSelector).serialize()+'&offset='+offset
}).done(function(response) {
$('.ajax-more').remove();
var $response = $(response);
$response.find(ajaxItemSelector).hide();
$(ajaxContainerSelector).append($response.find(ajaxContainerSelector).html());
$(ajaxItemSelector).fadeIn();
});
})
$(ajaxFormButtonStart).click(function(e) {
e.preventDefault();
ajaxMainFunction();
})
$(ajaxFormButtonReset).click(function(e) {
e.preventDefault();
$(ajaxFormSelector).trigger('reset');
$('input[name=sortby]').val('pagetitle');
$('input[name=sortdir]').val('asc');
setTimeout(function() {
$('[data-sort-by]').data('sort-dir', 'asc').toggleClass('button-sort-asc').text(sortUpText);
}, fadeSpeed);
ajaxMainFunction();
ajaxCount();
})
$(''+ajaxFormSelector+' input').change(function() {
ajaxMainFunction();
})
$('[data-sort-by]').data('sort-dir', 'asc').click(function() {
var ths = $(this);
$('input[name=sortby]').val($(this).data('sort-by'));
$('input[name=sortdir]').val($(this).data('sort-dir'));
setTimeout(function() {
$('[data-sort-by]').not(this).toggleClass('button-sort-asc').text(sortUpText);
ths.data('sort-dir') == 'asc' ? ths.data('sort-dir', 'desc').text(sortDownText) : ths.data('sort-dir', 'asc').text(sortUpText);
$(this).toggleClass('button-sort-asc');
}, fadeSpeed);
ajaxMainFunction();
});
});что с ним не так? не заводится собака — вот оно Комментарии: 46
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
или так
for и id были из стандартного бутстраповского примера — не работало )))))
сделал как в рабочем примере разметку и все равно не работает :(
Ну и как минимум упростить код:
includeTVs:
https://maltipuhome.ru/test?config=line
Сортировка работает, значит проблема с where, ее нужно решать.
Возможно проблема в этом:
может хостер чтото не поддерживает? или в чем может быть проблема?
/test?sortby=pagetitle&sortdir=desc
/test?sortby=price&sortdir=asc
/test?sortby=price&sortdir=desc
но оба варианта не работают
В catalogFilter нужно добавить &showLog=`1`, чтобы посмотреть, какой запрос идет в базу
сейчас поглядимс
а где смотреть лог?
как проверить что за массив он получает и вообще получает ли из
Попробуй htmx для фронта, не надо будет писать js.
Напишите какие у вас версии пакетов модх и конфиг сервера(пхп, мускл)
PHP Version 8.0.24 была ранее 7,4 это ничего не меняло
mysql 5.7.36-39
pdotools 2.13.2-pl
minishop 3.0.6-pl
в целом на хосте несколько сайтов, но там нет такого фильтра
сайт где работает на 7.4.28
на сайте где 7.4.32 не работает
пробовал и старее весрии ставить не помогло
Вот мой сниппет для фильтров в минишопе, может поможет
и where
в итоге получаю в лог такое
ну и в результатах фильтрации 0
B там смотрите, что передается в mysql какой запрос.
https://modstore.pro/packages/utilities/debugparser
но чтото не завелось :(
словил такую ошибку