Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bxtimur/444e63d8847a68283e16d1b250aaaaf3 to your computer and use it in GitHub Desktop.
Save bxtimur/444e63d8847a68283e16d1b250aaaaf3 to your computer and use it in GitHub Desktop.
// возвращает названия дерева разделов элемента через запятую
function GetParentSections ($id, $arTags) {
\Bitrix\Main\Loader::includeModule('iblock');
if (!$arTags)
$arTags = array();
$objResult = CIBlockSection::GetList(
array(), array("ID" => $id, "IBLOCK_ID" => CATALOG_IBLOCK_ID), false, array("ID", "NAME", "IBLOCK_SECTION_ID", "DEPTH_LEVEL"), false
);
$arResult = $objResult->GetNext();
$arTags[] = $arResult["NAME"];
if ($arResult["DEPTH_LEVEL"] != 1) {
return GetParentSections($arResult["IBLOCK_SECTION_ID"], $arTags);
} else {
$tags = implode(", ", $arTags);
return $tags;
}
}
// Прописывает теги элементу по названию
function SetElementTags($id, $section) {
if (!$id || !$tags)
return false;
\Bitrix\Main\Loader::includeModule('iblock');
$tags = GetParentSections($section);
$objElement = new CIBlockElement;
$result = $objElement->Update($id, array("TAGS" => $tags));
if ($result)
echo $id . "<br />";
else
echo $objElement->LAST_ERROR;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment