Working with Bitrix sections and the catalog.section component
Rus
Eng
Работа с разделами Битрикс и компонентом catalog.section

All English-language materials have been translated fully automatically using the Google service

Get SECTION_PAGE_URL on d7

$parentFilter = [
	'select' => [
		'ID',
		'NAME',
		'IBLOCK_ID',
		'IBLOCK_SECTION_ID',
		'CODE',
		'SECTION_PAGE_URL_RAW' => 'IBLOCK.SECTION_PAGE_URL'
	],
	'filter' => [
		'=IBLOCK_ID' => $arParams["IBLOCK_ID"]
		'=ID' => $SECTION_ID
	],
	'cache' => array(
		'ttl' => 86400, // Время жизни кеша сутки
		//'cache_joins' => true // Кешировать ли выборки с JOIN
	)
];

$parentSection = \Bitrix\Iblock\SectionTable::getList($parentFilter)->fetch();
$parentSection['SECTION_PAGE_URL'] = \CIBlock::ReplaceDetailUrl($parentSection['SECTION_PAGE_URL_RAW'], $parentSection, true, 'S');

Getting the first level parent section

$connection = \Bitrix\Main\Application::getConnection();
$PARENT_ID = $arResult['IBLOCK_SECTION_ID'];
$FIRST_LEVEL_SECTION = $connection->query('SELECT bis.ID FROM b_iblock_section as bis LEFT JOIN b_iblock_section as bis2 ON bis2.ID = ' . $PARENT_ID . ' where bis.LEFT_MARGIN < bis2.LEFT_MARGIN AND bis.RIGHT_MARGIN > bis2.RIGHT_MARGIN AND bis.IBLOCK_ID = bis2.IBLOCK_ID  AND bis.DEPTH_LEVEL = 1')->fetch();
\Bitrix\Iblock\SectionTable::getList([
	'select' => ['ID', 'INNER_ID' => 'INNER_SECTION.ID'],
	'filter' => [
		'IBLOCK_ID' => $IBLOCK_ID,
		'ID' => [$SECTION_IDS]
	],
	'runtime' => [
		'INNER_SECTION' => [
			'data_type' => \Bitrix\Iblock\SectionTable::class,
			'reference' => [
				'<this.LEFT_MARGIN' => 'ref.LEFT_MARGIN',
				'>this.RIGHT_MARGIN' => 'ref.RIGHT_MARGIN',
				'this.IBLOCK_ID' => 'ref.IBLOCK_ID'
			],
			'join_type' => 'LEFT'
		]
	]
])->fetchAll();

Getting all subsections of a section, including nested ones

Getting section data by its code in Bitrix

$section = \Bitrix\Iblock\SectionTable::query()
	->where('IBLOCK_ID', $iblockId)
	->where('CODE', 'КОД РАЗДЕЛА')
	->where('ACTIVE', 'Y')
	->setSelect(['*'])
	->exec()
	->fetch()
;

Getting a custom section property

\Bitrix\Main\Loader::includeModule("iblock");
$entity = \Bitrix\Iblock\Model\Section::compileEntityByIblock($IBLOCK_ID);
$attendant = $entity::getList(array(
	"select" => array("UF_ATTENDANT", "ID", "NAME"),
	"filter" => array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "ID" => $intSectionID, "GLOBAL_ACTIVE" => "Y")
))->fetch();

Get all sections to which the element is attached

\Bitrix\Iblock\ElementTable::getList([
            'filter' => [
                '=ID' => $ELEMENT_ID,
            ],
            'select' => [
                'ID',
                'NAME',
                'SECTION_ELEMENT_ID' => 'SECTION_ELEMENT.IBLOCK_SECTION_ID',
            ],
            'runtime' => [
                new \Bitrix\Main\ORM\Fields\Relations\Reference(
                    'SECTION_ELEMENT',
                    \Bitrix\Iblock\SectionElementTable::class,
                    \Bitrix\Main\Entity\Query\Join::on('this.ID', 'ref.IBLOCK_ELEMENT_ID')
                )
            ],
        ])->fetchAll()

Displaying products in the catalog.section component from several sections

First of all, and reset the values of the current binding to the sections. For example like this:

$arResult["VARIABLES"]["SECTION_CODE"] = '';
$arResult["VARIABLES"]["ID"] = '';

Add the following options to the call parameters of the component:

"INCLUDE_SUBSECTIONS" => "Y",
"SHOW_ALL_WO_SECTION" => "Y",

Pass the correct values to the filter. For example like this:

global $arrFilter;

$arrFilter['SECTION_ID'] = [35, 77];

If you did everything right and there is no additional. factors (for example, filter overrides), then your component will display products from the specified sections

Bitrix. Sort products without price to the end of the list

To do this, just specify in $arParams catalog.section or catalog

$arParams["ELEMENT_SORT_ORDER"] = "asc,nulls";

Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number