P
P
photosho2019-06-14 13:48:53
1C-Bitrix
photosho, 2019-06-14 13:48:53

Why do CIBlockSection::getList() and CIBlockElement::getList() return different number of elements?

Has anyone encountered the fact that CIBlockSection::getList and CIBlockElement::getList output a different number of elements?

CIBlockSection::getList(
    ['LEFT_MARGIN' => 'ASC'],
    [
        'IBLOCK_ID' => $iblock,
        'GLOBAL_ACTIVE' => 'Y',
        'CNT_ACTIVE' => true,
        'ELEMENT_SUBSECTIONS' => 'Y',
        'PROPERTY' => [
            'MYPROP' => 42//Свойство "Привязка к элементам"
        ]
    ]
);

Returns 21 items in the section with ID = 191. In the product catalog, there are 24 items filtered by the "MYPROP" property.
CIBlockElement::getList(
    [],
    [
        'IBLOCK_ID' => $iblock,
        'SECTION_ID' => 191,
        'ACTIVE' => 'Y',
        'INCLUDE_SUBSECTIONS' => 'Y',
        'PROPERTY_MYPROP.ID' => 42//Свойство "Привязка к элементам"
    ],
    false, false,
    ['ID', 'IBLOCK_ID', 'NAME']        
)->selectedRowsCount();

This code outputs 24, as it should. There are situations when it also gives out not the same number that the catalog shows, but they are extremely rare (we will deal with this later). What could be the problem? Perhaps I wrote something wrong in the code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-06-18
Madzhugin @Suntechnic

Because in the first case you are counting all products in the section, and in the second case only those with PROPERTY_MYPROP.ID == 42
What makes you think that

'PROPERTY' => [
            'MYPROP' => 42//Свойство "Привязка к элементам"
        ]

will filter elements when counting?
It will filter the section for you in which there is at least one element with this value of this property, and then it will count all the elements in this section.
So everything works correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question