N
N
Nadezhda Golovina2021-03-20 20:13:50
PHP
Nadezhda Golovina, 2021-03-20 20:13:50

How to display selected additional fields for different sections in Bitrix?

Hello. On the site , you need to display the selected unique values ​​from the additional fields (Tags) of the sections (type - Binding to infoblock sections)

<div class="tags_cloud"><?
//$rsResult = CIBlockSection::GetList(array("SORT" => "ASC"), array("IBLOCK_ID" => "5"), false, $arSelect = array("UF_TAGI"));
$rsResult = CIBlockSection::GetList(array("SORT" => "ASC"), array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ID" =>$arResult["SECTION"]["ID"]), false, $arSelect = array("UF_TAGI")); 
if($arSection = $rsResult -> GetNext())
    { 
$uftag = $arSection["UF_TAGI"]; 
$ufcategory = $arSection["UF_CATEGORY"]; 

if($uftag) {
$arFilter = array('IBLOCK_ID' => 27,'ID' => $uftag);
$rsItems = CIBlockSection::GetList(array(),$arFilter);
echo '<div class="catalog-tags">';
while ($arItem = $rsItems->GetNext())
  { 
    echo '<div class="catalog-tags-item"><a href="'.$arItem['SECTION_PAGE_URL'].'">'.$arItem["NAME"].'</a></div>';	
  }
 echo '</div>';
  }
  
if($ufcategory) {
$arFilter = array('IBLOCK_ID' => 27,'ID' => $ufcategory);
$rsItems = CIBlockSection::GetList(array(),$arFilter);
echo '<div class="catalog-list-cat">';
while ($arItem = $rsItems->GetNext())
  { 
    echo '<div class="class="catalog-tags-item""><a href="'.$arItem['SECTION_PAGE_URL'].'">'.$arItem["NAME"].'</a></div>';	
  }
 echo '</div>';
  }

}
?></div>

The code works partially - the values ​​from the add. fields. BUT! They are the same for all sections. And they must be unique, as in the admin panel.
Below are links to sections and screenshots of additional. fields (Tags) from the admin panel. Sliding wardrobes
from the manufacturer
6056287b665d0419508800.jpeg

605628955f42a854356440.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadezhda Golovina, 2021-03-21
@Golovina90

Amendment. The solution has been found!
In catalog.section.list and clear the cache

<? //Блок вывода Доп полей в разделах
$rsResult = CIBlockSection::GetList(array("SORT" => "ASC"), array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ID" =>$arResult["SECTION"]["ID"]), false, $arSelect = array("UF_TAGI")); 
if($arSection = $rsResult -> GetNext())
    { 
$uftag = $arSection["UF_TAGI"]; 

if($uftag) {
$arFilter = array('IBLOCK_ID' => 27,'ID' => $uftag);
$rsItems = CIBlockSection::GetList(array(),$arFilter);
echo '<div class="catalog-tags">';
while ($arItem = $rsItems->GetNext())
  { 
    echo '<div class="catalog-tags-item"><a href="'.$arItem['SECTION_PAGE_URL'].'">'.$arItem["NAME"].'</a></div>';	
  }
 echo '</div>';
  }
}
?>

The first code displays from the Add. fields (type - Binding to infoblock sections) selected sections that belong to only one category (that is, it does not take into account the values ​​of the admin panel, that other items are marked in another section).
And here is the code
<?
$IBLOCK_ID = 27; // ID нужного инфоблока

//Получаем все возможные поля текущего пользователя
$rsUser = CUser::GetByID($USER->GetID());
$arUser = $rsUser->Fetch();

//Выводим если множественное
foreach ($arUser['UF_TAGI'] as $propertyUf):
    echo $propertyUf;
endforeach;

//Создаем массив фильтра
$arFilter = array('IBLOCK_ID' => $IBLOCK_ID, 'ACTIVE' => 'Y');

//Добавляем наш массив в котором перечислены ID разделов выбранные пользователем
$sect_id = $fofilter;

//Создаем массив фильтра. В конце переменная фильтра
$arFilter = array('IBLOCK_ID' => $IBLOCK_ID, 'ACTIVE' => 'Y', 'ID' => $sect_id);

//Создаем массив выводимых полей
$arSelect = array('ID', 'NAME');

//Применяем метод с фильтром и полями
$rsSection = CIBlockSection::GetTreeList($arFilter, $arSelect);

//Выводим названия разделов
while ($arSection = $rsSection->Fetch()) {
    echo $arSection['NAME'];
}

foreach ($arUser['UF_TAGI'] as $propertyUf):
    $sectionsUser .= '\'' . $propertyUf . '\',';
endforeach;

eval('$fofilter=array(' . $sectionsUser . ');');
extract($fofilter);

?>

brings everything out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question