Created
October 21, 2017 06:39
-
-
Save bxtimur/444e63d8847a68283e16d1b250aaaaf3 to your computer and use it in GitHub Desktop.
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 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