Created
May 31, 2024 14:36
-
-
Save EscApp2/de41dea9d7465ae55e6e7a10509583a0 to your computer and use it in GitHub Desktop.
property filter section
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function getFilterBySlug($slug, $IBLOCK_ID, $arProperties){ | |
$arReturn = array(); | |
if($slug){ | |
\Bitrix\Main\Loader::includeModule('iblock'); | |
$properties = \Bitrix\Iblock\PropertyTable::getList(array( | |
'filter' => array( | |
"CODE" => $arProperties, | |
"IBLOCK_ID" => $IBLOCK_ID, | |
), | |
'cache' => [ | |
'ttl' => 3600, | |
'cache_joins' => true, | |
] | |
)); | |
while ($prop_fields = $properties->fetch()) { | |
$arProps[$prop_fields['ID']] = $prop_fields; | |
} | |
foreach($arProps as $id=>$arProp){ | |
if( | |
$arProp['PROPERTY_TYPE'] == "E" | |
&& !empty($arProp['LINK_IBLOCK_ID']) | |
){ | |
$res_elem = CIBlockElement::GetList( | |
array(), | |
array( | |
"IBLOCK_ID"=>$arProp['LINK_IBLOCK_ID'], | |
"CODE"=>$slug, | |
), | |
false, | |
array('nTopCount'=>1), | |
array("ID","IBLOCK_ID","CODE","NAME")); | |
if($ar_elem = $res_elem->Fetch()){ | |
$arReturn['=PROPERTY_'.$arProp['CODE']] = $ar_elem['ID']; | |
break;// foreach | |
} | |
}elseif( | |
$arProp['PROPERTY_TYPE'] == "G" | |
&& !empty($arProp['LINK_IBLOCK_ID']) | |
){ | |
$res_section = CIBlockSection::GetList( | |
Array("left_margin"=>"asc"), | |
array("IBLOCK_ID"=>$arProp['LINK_IBLOCK_ID'],"CODE"=>$slug,), | |
false, | |
array("ID", | |
"IBLOCK_ID", | |
"CODE", | |
"NAME" | |
), | |
false | |
); | |
if($ar_result = $res_section->Fetch()){ | |
$arReturn['=PROPERTY_'.$arProp['CODE']] = $ar_result['ID']; | |
break;// foreach | |
} | |
} | |
} | |
} | |
return $arReturn; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$slug = $_REQUEST['SLUG']; | |
$slug = explode("?",$_REQUEST['SLUG'])[0]; | |
$arSlug = explode("/",$slug); | |
$arSlug = array_filter($arSlug); | |
global $slugFilter; | |
$arFilter = getFilterBySlug($arSlug[0], IBLOCK_ID, array("DOCTOR", "SERVICE")); | |
if(!empty($arFilter)){ | |
$slugFilter = $arFilter; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die(); | |
global ${$arParams['FILTER_NAME']}; | |
$arFilter = ${$arParams['FILTER_NAME']}; | |
$arPropertiesCode = array("DOCTOR", "SERVICE"); | |
$arPropertiesResult = getAllElementsPropertiesValues( | |
$arParams['IBLOCK_ID'], | |
false, | |
$arPropertiesCode | |
); | |
$properties = \Bitrix\Iblock\PropertyTable::getList(array( | |
'filter' => array( | |
"CODE" => $arPropertiesCode, | |
"IBLOCK_ID" => $arParams['IBLOCK_ID'], | |
), | |
'cache' => [ | |
'ttl' => 86400, | |
'cache_joins' => true, | |
] | |
)); | |
while ($prop_fields = $properties->fetch()) { | |
$arProps[$prop_fields['ID']] = $prop_fields; | |
} | |
foreach($arProps as $id=>$arProp){ | |
if( | |
$arProp['PROPERTY_TYPE'] == "E" | |
&& !empty($arProp['LINK_IBLOCK_ID']) | |
){ | |
$res_elem = CIBlockElement::GetList( | |
array( | |
"NAME"=>"ASC", | |
), | |
array( | |
"IBLOCK_ID"=>$arProp['LINK_IBLOCK_ID'], | |
"ID"=>$arPropertiesResult[$arProp['CODE']], | |
"ACTIVE"=>"Y", | |
), | |
false, | |
false, | |
array("ID","IBLOCK_ID","CODE","NAME")); | |
$arValues = array(); | |
while($ar_elem = $res_elem->Fetch()){ | |
if($filter_id = $arFilter["=PROPERTY_".$arProp['CODE']]){ | |
if($filter_id == $ar_elem['ID']){ | |
$ar_elem['SELECTED'] = "Y"; | |
} | |
} | |
$ar_elem['URL'] = "/catalog/".$ar_elem['CODE']."/"; | |
$arValues[] = $ar_elem; | |
} | |
$arPropertiesResult[$arProp['CODE']] = $arValues; | |
}elseif( | |
$arProp['PROPERTY_TYPE'] == "G" | |
&& !empty($arProp['LINK_IBLOCK_ID']) | |
){ | |
$res_section = CIBlockSection::GetList( | |
Array("NAME"=>"ASC"), | |
array( | |
"IBLOCK_ID"=>$arProp['LINK_IBLOCK_ID'], | |
"ID"=>$arPropertiesResult[$arProp['CODE']] | |
), | |
false, | |
array("ID", | |
"IBLOCK_ID", | |
"CODE", | |
"NAME" | |
), | |
false | |
); | |
$arValues = array(); | |
while($ar_elem = $res_section->Fetch()){ | |
if($filter_id = $arFilter["=PROPERTY_".$arProp['CODE']]){ | |
if($filter_id == $ar_elem['ID']){ | |
$ar_elem['SELECTED'] = "Y"; | |
} | |
} | |
$ar_elem['URL'] = "/catalog/".$ar_elem['CODE']."/"; | |
$arValues[] = $ar_elem; | |
} | |
$arPropertiesResult[$arProp['CODE']] = $arValues; | |
} | |
} | |
$arResult['FILTER_DATA'] = array(); | |
foreach($arPropertiesCode as $code){ | |
$arResult['FILTER_DATA'][$code] = $arPropertiesResult[$code]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function getScroll() { | |
if (window.pageYOffset != undefined) { | |
return [pageXOffset, pageYOffset]; | |
} else { | |
var sx, sy, d = document, | |
r = d.documentElement, | |
b = d.body; | |
sx = r.scrollLeft || b.scrollLeft || 0; | |
sy = r.scrollTop || b.scrollTop || 0; | |
return [sx, sy]; | |
} | |
} | |
function setScroll(x,y) { | |
if(!x){ | |
x = 0; | |
} | |
if(!y){ | |
y = 0; | |
} | |
window.scrollTo(x, y); | |
} | |
function setScrollFormGet(){ | |
let queryString = window.location.search; | |
let urlParams = new URLSearchParams(queryString); | |
let scroll = parseFloat(urlParams.get('scroll')); | |
setScroll(0,scroll); | |
urlParams.delete("scroll"); | |
let new_params = urlParams.toString(); | |
let new_href = window.location.pathname; | |
if(new_params){ | |
new_href +="?"+new_params; | |
} | |
history.replaceState(null, '', new_href); | |
} | |
setScrollFormGet(); | |
$(document).ready(function(){ | |
$.fn.BeerSlider = function ( options ) { | |
options = options || {}; | |
return this.each(function() { | |
new BeerSlider(this, options); | |
}); | |
}; | |
$('.beer-slider').BeerSlider(); | |
$(".selectize_reload").selectize({ | |
onChange: function(value) { | |
window.location.href=value+"?scroll="+getScroll()[1]; | |
} | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<??> | |
<div class="row"> | |
<div class="filter-row"> | |
<?if($arResult['FILTER_DATA']['SERVICE']){?> | |
<div class="filter-cell"> | |
<label>Выберите направление</label> | |
<select class="selectize_reload" > | |
<option value="/raboty-vrachey/" >Все направление</option> | |
<?foreach($arResult['FILTER_DATA']['SERVICE'] as $arItem){?> | |
<option | |
<?if("Y"==$arItem['SELECTED']) echo "selected";?> | |
value="<?=$arItem['URL']?>" ><?=$arItem['NAME']?></option> | |
<?}?> | |
</select> | |
</div> | |
<?}?> | |
<?if($arResult['FILTER_DATA']['DOCTOR']){?> | |
<div class="filter-cell"> | |
<label>Выберите врачa</label> | |
<select class="selectize_reload" > | |
<option value="/raboty-vrachey/" >Все врачи</option> | |
<?foreach($arResult['FILTER_DATA']['DOCTOR'] as $arItem){?> | |
<option | |
<?if("Y"==$arItem['SELECTED']) echo "selected";?> | |
value="<?=$arItem['URL']?>" ><?=$arItem['NAME']?></option> | |
<?}?> | |
</select> | |
</div> | |
<?}?> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
array ( | |
'CONDITION' => '$^/catalog/([^\\?\\#]*)$', | |
'RULE' => 'SLUG=$1', | |
'ID' => 'bitrix:news.list', | |
'PATH' => '/catalog/index.php', | |
'SORT' => 100, | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment