Created
September 24, 2014 06:52
-
-
Save helloris25/0d4f7d66b80e19337367 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
<?php | |
/** | |
* ПОЛУЧАЕМ ВСЕ ПОДКАТЕГОРИИ OASIS | |
*/ | |
// ID корневой секции | |
$root_id = 82663; | |
$rsParentSection = CIBlockSection::GetByID($root_id); | |
if ($arParentSection = $rsParentSection->GetNext()) | |
{ | |
$arFilter = array('IBLOCK_ID' => $arParentSection['IBLOCK_ID'], | |
'>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'], | |
'<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'], | |
'>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']); | |
$rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'), | |
$arFilter, false, | |
Array('ID', 'NAME', 'DEPTH_LEVEL', 'IBLOCK_SECTION_ID'), | |
false ); | |
} | |
$site_sections = array(); | |
while( $ar_result = $rsSect->GetNext() ) | |
{ | |
$site_sections[] = array( | |
'ID' => $ar_result['ID'], // ID категории | |
'NAME' => $ar_result['NAME'], // Имя категории | |
'DEPTH_LEVEL' => $ar_result['DEPTH_LEVEL'], // Уровень вложенности | |
'PARENT' => $ar_result['IBLOCK_SECTION_ID'] // ID родителя | |
); | |
} | |
$CIBlockSection_obj = new CIBlockSection; | |
// Бежим по массиву с директориями XML | |
foreach ($file_sections as $file_section) { | |
// ID текущей секции | |
$curent_sect = $root_id;// Начальная папка - корневая секция | |
// Перебираем секции из файла | |
foreach ($file_section as $depth_File_section => $curent_file_section) { | |
// Т.к. мы работаем с одной из секций сайта потомки +2 | |
$depth_File_section += 2; | |
// Имя искомой секции | |
$name_File_section = $curent_file_section; | |
$num_sect = 0; | |
$count_site_sections = count($site_sections); | |
do { | |
$id_Site_section = $site_sections[$num_sect]['ID']; | |
$name_Site_section = $site_sections[$num_sect]['NAME']; | |
$depth_Site_section = $site_sections[$num_sect]['DEPTH_LEVEL']; | |
$parent_id_Site_section = $site_sections[$num_sect]['PARENT']; | |
if ( $name_File_section == $name_Site_section AND | |
$depth_File_section == $depth_Site_section AND | |
$curent_sect == $parent_id_Site_section ) | |
{ | |
$curent_sect = $id_Site_section; | |
$num_sect = 0; | |
break; | |
} | |
elseif ($num_sect == $count_site_sections) | |
{ | |
$id = $CIBlockSection_obj->Add(Array( "ACTIVE" => 'Y', | |
"IBLOCK_ID" => 7, | |
"IBLOCK_SECTION_ID" => $curent_sect, | |
"NAME" => $name_File_section)); | |
$site_sections[] = array('ID' => $id, | |
'NAME' => $name_File_section, | |
'DEPTH_LEVEL' => $depth_File_section, | |
'PARENT' => $curent_sect); | |
$curent_sect = $id; | |
$num_sect = 0; | |
break; | |
} | |
$num_sect++; | |
} while ( $num_sect <= $count_site_sections); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment