M
M
Maxim Gribov2020-09-28 17:14:05
1C-Bitrix
Maxim Gribov, 2020-09-28 17:14:05

How to make a filter only at the last level of the product catalog in 1s Bitrix?

Help, please, to solve the problem. It is necessary that in the product catalog the filter is shown only at the last level. The level of nesting in the catalog is different in different subgroups. Here is the part of the section.php file that is responsible for the output of the filter (in my opinion).

spoiler
// set offer type & smartfilter view
    $typeTmpSKU = $viewTmpFilter = 0;
    if($section['UF_OFFERS_TYPE']){
        $typeTmpSKU = $section['UF_OFFERS_TYPE'];
    }
    if($section['UF_FILTER_VIEW']){
        $viewTmpFilter = $section['UF_FILTER_VIEW'];
    }
    if(!$typeTmpSKU || !$viewTmpFilter){
        if($section['DEPTH_LEVEL'] > 1){
            $sectionParent = CNextCache::CIBlockSection_GetList(array('CACHE' => array("MULTI" =>"N", "TAG" => CNextCache::GetIBlockCacheTag($arParams["IBLOCK_ID"]))), array('GLOBAL_ACTIVE' => 'Y', "ID" => $section["IBLOCK_SECTION_ID"], "IBLOCK_ID" => $arParams["IBLOCK_ID"]), false, array("ID", "IBLOCK_ID", "NAME", "UF_OFFERS_TYPE", 'UF_FILTER_VIEW'));
            if($sectionParent['UF_OFFERS_TYPE'] && !$typeTmpSKU){
                $typeTmpSKU = $sectionParent['UF_OFFERS_TYPE'];
            }
            if($sectionParent['UF_FILTER_VIEW'] && !$viewTmpFilter){
                $viewTmpFilter = $sectionParent['UF_FILTER_VIEW'];
            }

            if($section['DEPTH_LEVEL'] > 2){
                if(!$typeTmpSKU || !$viewTmpFilter){
                    $sectionRoot = CNextCache::CIBlockSection_GetList(array('CACHE' => array("MULTI" =>"N", "TAG" => CNextCache::GetIBlockCacheTag($arParams["IBLOCK_ID"]))), array('GLOBAL_ACTIVE' => 'Y', "<=LEFT_BORDER" => $section["LEFT_MARGIN"], ">=RIGHT_BORDER" => $section["RIGHT_MARGIN"], "DEPTH_LEVEL" => 1, "IBLOCK_ID" => $arParams["IBLOCK_ID"]), false, array("ID", "IBLOCK_ID", "NAME", "UF_OFFERS_TYPE", 'UF_FILTER_VIEW'));
                    if($sectionRoot['UF_OFFERS_TYPE'] && !$typeTmpSKU){
                        $typeTmpSKU = $sectionRoot['UF_OFFERS_TYPE'];
                    }
                    if($sectionRoot['UF_FILTER_VIEW'] && !$viewTmpFilter){
                        $viewTmpFilter = $sectionRoot['UF_FILTER_VIEW'];
                    }
                }
            }
        }
    }

Endless monitoring of Google and Yandex did not answer my question. php in 1s-bitrix is ​​just starting to master.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-09-29
@cordmax

It is necessary to wrap the call of the filter component in a condition.

if($section['RIGHT_MARGIN'] - $section['LEFT_MARGIN'] == 1)  {
    // компонент фильтра
}

According to Bitrix logic, such a condition will always tell you that the subsection of the last nesting level

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question