D
D
Dos7712016-11-01 12:59:32
1C-Bitrix
Dos771, 2016-11-01 12:59:32

How to display the number of comments on Bitrix?

There is a third-party review component, everything works fine, but I don't know how to display the number of comments in products.
marketplace.1c-bitrix.ru/solutions/parnas.khayrcom... - Link to the component in the marketplace.
Here is what the developer of the module wrote to me: everything is done on the basis of infoblocks, it is enough to count the number of elements associated with this product. But I don't know what code to use.
I tried to use this code:

CModule::IncludeModule('iblock'); 
$arFilter = array( 
    'IBLOCK_ID' => 123, // ID инфоблока 
    // любые другие параметры, например 'ACTIVE' => 'Y' 
); 
$res = CIBlockElement::GetList(false, $arFilter, array('IBLOCK_ID')); 
if ($el = $res->Fetch()) 
    echo 'Записей: '.$el['CNT'];

Only such code displays the entire element in the infoblock.
I will write in an example what I need: There is a product "Keyboard", I leave 2 reviews about the product, where the text reviews should appear number 2.
I hope I wrote everything in detail. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Дмитрий Королев, 2016-11-10
@Dos771

CModule::IncludeModule('iblock'); 
$arFilter = array( 
    'IBLOCK_ID' => 123, // ID инфоблока 
  'PROPERTY_PRODUCT_ID' => $id, //ID товара, для которого нужно получить количество отзывов. $arResult["ID"], если находимся в шаблоне catalog.element. PRODUCT_ID - это код свойства, в котором хранятся привязки отзывов к товарам (нужно посмотреть в настройках инфоблока, как это свойство называется у вас)
    // любые другие параметры, например 'ACTIVE' => 'Y' 
); 
$qty = CIBlockElement::GetList(array(), $arFilter, array()); //если третий параметр пустой массив, то GetList возвращает количество элементов, удовлетворяющих фильтру
echo 'Записей: '.$qty;

dev.1c-bitrix.ru/api_help/iblock/classes/ciblockel...
take.ms/I1Gzf

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question