Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
evo DocLister search
<form class="head-search" id="NavSearchForm" action="[~46~]" method="post">
<input id="search-input" placeholder="Поиск по каталогу..." class="form-control cleardefault search_place validation_place" type="text" name="search" value="" />
<button class="btn btn-primary not_valid" type="submit">Найти</button>
</form>
<div class="row search-result">
[[DocLister?
&display=`20`
&orderBy=`availability ASC, price ASC`
&parents=`7`
&tvList=`new,sale,discount,quantity,code,image,price,old-price`
&renderTV=`image`
&tpl=`search_result`
&tplLast=`@CODE `
&id=`search`
&addWhereList=`c.template IN (9)`
&depth=`10`
&showParent=`1`
&dateFormat=`%d.%m.%Y`
&dateSource=`pub_date`
&ownerTPL=`@CODE:<section class="gray products">[+dl.wrap+]</section>`
&noneTPL=`@CODE:Товаров нет`
&filters=`OR(AND(tv:code:eq:[[search]]);OR(AND(content:pagetitle:containsOne:[[search]])))`
&filters=`OR(AND(content:parent:is:[*id*]);OR(AND(tv:additional_categories:containsOne:[*id*])))`
&paginate=`pages`
&TplNextP=``
&TplPrevP=``
&TplPage=`@CODE: <li><a title="[+num+]" href="[+link+]" class="">[+num+]</a></li>`
&TplCurrentPage=`@CODE:<li class="pagination-active"><a>[+num+]</a></li>`
&TplWrapPaginate=`@CODE: <div ><ul class="pagination pt15">[+wrap+]</ul></div>`
]]
</div>
[+search.pages+]
[+iteration:math=`(?)%2`:is=`0`:then=`<div class="clearfix hidden visible-xs"></div>`+]
[+iteration:math=`(?)%3`:is=`0`:then=`<div class="clearfix hidden-xs"></div>`+]
[[DLcrumbs?
&ownerTPL=`@CODE:<ul class="inline bcrumb">[+crumbs.wrap+]</ul>`
&tpl=`@CODE:<li><a href="[+url+]">[+e.title+]</a></li>`
&tplCurrent=`@CODE:<li class="active">[+e.title+]</li>`
&showCurrent=`1`
]]
[[DLBuildMenu?
&parents=`5`
&maxDepth=`2`
&activeClass=`active`
&orderBy=`menuindex ASC`
&TplMainOwner=`@CODE: <ul id="accordion" role="tablist" aria-multiselectable="false" class="panel-group">[+dl.wrap+]</ul>`
&TplSubOwner=`@CODE:<ul class="sub-menu panel-collapse collapse" id="[+iteration+]">[+dl.wrap+]</ul>`
&TplOneItem=`@CODE: <li class="panel [+dl.class+]"><div role="tab"><a class="plus-link" data-toggle="collapse" data-parent="#accordion" href="#[+iteration+]"><i class="fa fa-caret-down" aria-hidden="true"></i><i class="fa fa-caret-up" aria-hidden="true"></i></a><a href="[+url+]" title="[+e.title+]">[+title+]</a></div>[+dl.submenu+]</li>`
&TplDepth2=`@CODE:<li class="[+dl.class+]"><a href="[+url+]" title="[+e.title+]">[+title+]</a></li>`
&TplNoChildrenDepth1=`@CODE:<li class="panel [+dl.class+]"><a href="[+url+]" title="[+e.title+]">[+title+]</a></li>`
]]
/************************ сниппет поиска *************************/
search
Поиск по каталогу с помощью Ditto
<?php
$search_string = '';
if(!empty($_POST['search'])){
$search_string = $_POST['search'];
setcookie("search", $_POST['search']);
}
else{
$search_string = $_COOKIE["search"];
}
$search_string = trim($search_string);
$search_arr = explode(' ', $search_string);
$short = true;
foreach($search_arr as $word){
if(strlen($word) > 2) {
$short = false;
}
}
if($short == true){
return 'В поисковом запросе должно быть хоть одно слово длиннее 2-х символов';
}
if (!empty($search_string)) {
$result = '<div class="row"><div class="col-md-12"><b>Результаты поиcка по запросу «'.$search_string.'»:</b></div></div><div class="row search-result">';
//создаем массив параметров
$params = array();
$params['display'] = '20';
$params['parents'] = '7';
$params['tvList'] = 'new,sale,discount,quantity,code,image,price,old-price';
$params['renderTV'] = 'image';
$params['tpl'] = 'search_result';
$params['id'] = 'search';
$params['filters'] = 'OR(AND(tv:code:eq:'.$search_string.');OR(AND(content:pagetitle:containsOne:'.$search_string.')))';
$params['addWhereList'] = 'c.template IN (9)';
$params['depth'] = '10';
$params['paginate'] = 'pages';
$params['TplNextP'] = '';
$params['TplPrevP'] = '';
$params['TplPage'] = '@CODE: <li><a title="[+num+]" href="[+link+]" class="">[+num+]</a></li>';
$params['TplCurrentPage'] = '@CODE:<li class="pagination-active"><a>[+num+]</a></li>';
$params['TplWrapPaginate'] = '@CODE: <div ><ul class="pagination pt15">[+wrap+]</ul></div>';
$output = $modx->parseDocumentSource($modx->runSnippet('DocLister', $params));
//проверяем количество найденных товаров
$countResourses = $modx->getPlaceholder('search.display');
if($countResourses < 1){ //если товаров не найдено - применяем полнотекстовый поиск
$result = '<div class="row"><div class="col-md-12"><b>По запросу «'.$search_string.'» не найдено точных результатов. Возможно, вы искали что-то из товаров, указанных ниже:</b></div></div><div class="row search-result">';
$params['filters'] = 'OR(AND(tv:code:eq:'.$search_string.');OR(AND(content:pagetitle:against:'.$search_string.')))';
$output = $modx->parseDocumentSource($modx->runSnippet('DocLister', $params));
}
$finish = "</div>[+search.pages+]";
//выводим заголовок и результаты
return $result.$output.$finish;
}
@php-force

This comment has been minimized.

Copy link

@php-force php-force commented Apr 30, 2019

Hi would you be able to include "search_result" template example? when i include template i seem to get error 500...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment