A
A
Andrey Eskov2020-08-03 13:43:24
1C-Bitrix
Andrey Eskov, 2020-08-03 13:43:24

How to create more complex filters in getList?

Good afternoon.

Tell me how to create more complex filters in getList. For example, connections.

Here is an example.
Task: find out how many products are in the category with the test code
My solution:
My knowledge is only enough for such a solution

//ID категории
$sectionId = '';

// Получаем id категории по коду
$dbSection = \Bitrix\Iblock\SectionTable::getList([
    'filter' => ['CODE' => 'test']
]);

while ($arSection = $dbSection->fetchAll()){
    $sectionId = $arSection[0]['ID'];
}

//Получаем количество товаров
$dbItems = ElementTable::getCount([
    'IBLOCK_ID' => $arParams['IBLOCK_ID'],
    'IBLOCK_SECTION_ID' => $sectionId
]);

//Получили количество
var_dump($dbItems);


But it seems to me that there is too much code to check the number of goods, and in theory there are 2 calls to the database, which is not good. Tell me how to solve this in 1 getList

In theory, they (the element of the infoblock and the section) should have a connection, maybe through this connection, something like this

$dbItems = ElementTable::getCount([
    'filter' => [
        'IBLOCK_ID' => $arParams['IBLOCK_ID'],
        'SECTION.CODE' => 'test'
    ]
]);


Where it is possible to filter at once through communication.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Edward, 2020-08-08
@Drayde

5f2de73177208324009292.jpeg
Bingo.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question