Answer the question
In order to leave comments, you need to log in
How to filter products?
There is a selection of the desired values:
<?php
//Присваивание значения в поле, показывающее максимально большую цену
$modx->setPlaceholder('priceMaxValue', getPriceMaxValue());
//Вовзращает самое большое значение из всех существующих в таблице (максимальная цена)
function getPriceMaxValue(){
global $modx;
$filter = array("tmplvarid" => 5);
$priceMaxValueArray = $modx->GetCollection("modTemplateVarResource", $filter);
$maxValueResultArray = array();
foreach($priceMaxValueArray as $k=>$v){
$res = preg_replace('/[^0-9]/', '', $v->get("value"));
array_push($maxValueResultArray, $res);
}
return max($maxValueResultArray);
}
//Фильтры по ценам
function getCatPrice(){
$catPrice = $_GET["catPrice"];
$catPriceArray = array();
global $modx;
for($i=0; $i<count($catPrice); $i++){
$filter = array("tmplvarid" => 21, "value" => $catPrice[$i]);
$tvs = $modx->getCollection("modTemplateVarResource", $filter);
foreach($tvs as $k=>$v){
$id = $v->get("contentid");
array_push($catPriceArray, $id);
}
}
return $catPriceArray;
}
//Фильтр по диапазону цен
function getRangePrice(){
$priceMinValue = $_GET["priceMinValue"];
$priceMaxValue = $_GET["priceMaxValue"];
global $modx;
$filter = array("tmplvarid" => 5);
$tvs = $modx->getCollection("modTemplateVarResource", $filter);
$rangePriceArray = array();
foreach ($tvs as $k=>$v){
if($v->get("value") >= $priceMinValue && $v->get("value") <= $priceMaxValue){
$res = $v->get("contentid");
array_push($rangePriceArray, $res);
}
}
return $rangePriceArray;
}
//Фильтр по категории "На праздник"
function getCatHoliday(){
$catHoliday = $_GET["catHoliday"];
global $modx;
$filter = array("tmplvarid" => 19, "value" => $catHoliday);
$tvs = $modx->getCollection("modTemplateVarResource", $filter);
$catHolidayArray = array();
foreach($tvs as $k=>$v){
$res = $v->get("contentid");
array_push($catHolidayArray, $res);
}
return $catHolidayArray;
}
//Фильтр по категории "Подарки"
function getCatGifts(){
$catGifts = $_GET["catGifts"];
global $modx;
$catGiftsArray = array();
for($i=0;$i<count($catGifts);$i++){
$filter = array("tmplvarid" => 18, "value" => $catGifts[$i]);
$tvs = $modx->getCollection("modTemplateVarResource", $filter);
foreach($tvs as $k=>$v){
$res = $v->get("contentid");
array_push($catGiftsArray, $res);
}
}
return $catGiftsArray;
}
if($_GET["filter_submit"]){
$globalArray = array();
if($_GET["catPrice"]){
$globalArray = array_merge($globalArray, getCatPrice());
}
if($_GET["priceMinValue"] && $_GET["priceMaxValue"]){
$globalArray = array_merge($globalArray, getRangePrice());
}
if($_GET["catHoliday"]){
$globalArray = array_merge($globalArray, getCatHoliday());
}
if($_GET["catGifts"]){
$globalArray = array_merge($globalArray, getCatGifts());
}
$globalArray = array_unique($globalArray);
$lastArray = implode(",", $globalArray);
$modx->setPlaceholder('queryResult', $lastArray);
}
catalog/?priceMinValue=1&priceMaxValue=77555&catHoliday=%238+марта%23&filter_submit=Отсортировать
Answer the question
In order to leave comments, you need to log in
Umm, you use getCollection and at the same time want to run through getResources, there is little logic.
if according to your plan, you need to run getResources in this snippet and run through it the array that you fill in the functions
$output = $modx->runSnippet('getPage',array(
'element' => 'getResources',
'resources' => $array // id
));
return $output;
$output = $modx->runSnippet('getPage',array(
'element' => 'getResources',
'parent' => 0,
'tvFilters' => ''// условие
));
return $output;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question