Skip to content

Instantly share code, notes, and snippets.

@di7spider
Last active October 8, 2015 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save di7spider/613b8e406ce3811624fc to your computer and use it in GitHub Desktop.
Save di7spider/613b8e406ce3811624fc to your computer and use it in GitHub Desktop.
1C-Bitrix :: Создает зеркальную копию из разделов каталога товаров в инфоблок меню и прописывает связь разделов по полю UF_LINK_CATALOG
<?php
include $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php';
define('DEF_IB_CATALOG', 1); /** ИБ каталога товаров */
define('DEF_IB_MENU_CATALOG', 2); /** ИБ каталога меню */
$arListAdd = Array();
$db = new CIBlockSection;
$addSection = function($catalogSID, $parentSID, $code, $name, $sort) use($db, &$arListAdd){
$arListAdd[$catalogSID] = $db-> add(
Array(
"ACTIVE" => 'Y',
"IBLOCK_SECTION_ID" => (int) $parentSID,
"IBLOCK_ID" => DEF_IB_MENU_CATALOG,
"CODE" => (string) $code,
"NAME" => (string) $name,
"SORT" => (int) $sort <= 0 ? 500 : (int) $sort,
"UF_LINK_CATALOG" => (int) $catalogSID
)
);
};
$addSection(0, 0, 'catalog', 'Каталог');
$dbSection = \Bitrix\Iblock\SectionTable::getList(
Array(
'order' => Array(
'DEPTH_LEVEL' => 'ASC',
'SORT' => 'ASC'
),
'filter' => Array(
'ACTIVE' => 'Y',
'GLOBAL_ACTIVE' => 'Y',
'IBLOCK_ID' => DEF_IB_CATALOG
),
'select' => Array(
'ID',
'IBLOCK_SECTION_ID',
'NAME',
'CODE',
'SORT'
)
)
);
while( $arSection = $dbSection-> fetch() ){
$addSection(
$arSection['ID'],
$arListAdd[
(int) $arSection['IBLOCK_SECTION_ID']
],
$arSection['CODE'],
$arSection['NAME'],
$arSection['SORT']
);
}
echo 'Y';
?>
@di7spider
Copy link
Author

Пример созданных разделов в инфоблоке "Меню каталога товаров":

Пример меню

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment