Skip to content

Instantly share code, notes, and snippets.

@Pum-purum
Created August 29, 2017 12:03
Show Gist options
  • Save Pum-purum/70fa564b6d7c71a232bfe889017f0d46 to your computer and use it in GitHub Desktop.
Save Pum-purum/70fa564b6d7c71a232bfe889017f0d46 to your computer and use it in GitHub Desktop.
Умный фильтр Битрикс
if (CModule::IncludeModule("iblock"))
{
$arFilter = array(
"ACTIVE" => "Y",
"GLOBAL_ACTIVE" => "Y",
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
);
if(strlen($arResult["VARIABLES"]["SECTION_CODE"])>0)
{
$arFilter["CODE"] = $arResult["VARIABLES"]["SECTION_CODE"];
}
elseif($arResult["VARIABLES"]["SECTION_ID"]>0)
{
$arFilter["ID"] = $arResult["VARIABLES"]["SECTION_ID"];
}
$obCache = new CPHPCache;
if($obCache->InitCache(36000, serialize($arFilter), "/iblock/catalog"))
{
$arCurSection = $obCache->GetVars();
}
else
{
$arCurSection = array();
$dbRes = CIBlockSection::GetList(array(), $arFilter, false, array("ID"));
$dbRes = new CIBlockResult($dbRes);
if(defined("BX_COMP_MANAGED_CACHE"))
{
global $CACHE_MANAGER;
$CACHE_MANAGER->StartTagCache("/iblock/catalog");
if ($arCurSection = $dbRes->GetNext())
{
$CACHE_MANAGER->RegisterTag("iblock_id_".$arParams["IBLOCK_ID"]);
}
$CACHE_MANAGER->EndTagCache();
}
else
{
if(!$arCurSection = $dbRes->GetNext())
$arCurSection = array();
}
$obCache->EndDataCache($arCurSection);
}
}
@Pum-purum
Copy link
Author

В вызове умного фильтра прописать в параметре "SECTION_ID" => $arCurSection["ID"],

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