P
P
Pavel Sidorov2020-02-09 11:00:33
1C-Bitrix
Pavel Sidorov, 2020-02-09 11:00:33

How to display a multiple property binding to other elements of the infoblock through getlist?

Good day

Guys, the infoblock has a multiple property binding to the elements of another infoblock. The properties are stored in a separate table, but the query still returns multiple records instead of just one. How to make it return one record and it contains several values ​​of this property.

The property is called PROPERTY_ELEMENT.

CModule::IncludeModule('iblock'); 
$el = new CIBlockElement();
$ID = $arResult['ID']; 

$arProducts = $el->GetList(
   array('SORT' => 'ASC'),
   array(
      'IBLOCK_ID' => 16,
      'ACTIVE' => 'Y',
      'GLOBAL_ACTIVE' => 'Y',
      'PROPERTY_LOOKBOOK.ID' => $ID
   ),
   false,
   false,
  array('IBLOCK_ID','ID','NAME','PROPERTY_ELEMENT.NAME', 'PROPERTY_ELEMENT.CODE', 'PROPERTY_ELEMENT.PREVIEW_PICTURE')
);

while($prod = $arProducts-> GetNext()){

  if(count($prod)>0){

    echo '<pre>'; print_r($prod); echo '</pre>'; 
}
else{
  echo "Таблица пустая.";
}

}
?>


Array
(
    [IBLOCK_ID] => 16
    [~IBLOCK_ID] => 16
    [ID] => 161
    [~ID] => 161
    [NAME] => Пуховик черный и белый
    [~NAME] => Пуховик черный и белый
    [PROPERTY_ELEMENT_NAME] => Пуховик на объемной стойке (Черный)
    [~PROPERTY_ELEMENT_NAME] => Пуховик на объемной стойке (Черный)
    [PROPERTY_ELEMENT_CODE] => pukhovik-na-obemnoy-stoyke-chernyy
    [~PROPERTY_ELEMENT_CODE] => pukhovik-na-obemnoy-stoyke-chernyy
    [PROPERTY_ELEMENT_PREVIEW_PICTURE] => 
    [~PROPERTY_ELEMENT_PREVIEW_PICTURE] => 
    [SORT] => 500
    [~SORT] => 500
)


Array
(
    [IBLOCK_ID] => 16
    [~IBLOCK_ID] => 16
    [ID] => 161
    [~ID] => 161
    [NAME] => Пуховик черный и белый
    [~NAME] => Пуховик черный и белый
    [PROPERTY_ELEMENT_NAME] => Пуховик на объемной стойке (белый)
    [~PROPERTY_ELEMENT_NAME] => Пуховик на объемной стойке (белый)
    [PROPERTY_ELEMENT_CODE] => pukhovik-na-obemnoy-stoyke-belyy
    [~PROPERTY_ELEMENT_CODE] => pukhovik-na-obemnoy-stoyke-belyy
    [PROPERTY_ELEMENT_PREVIEW_PICTURE] => 
    [~PROPERTY_ELEMENT_PREVIEW_PICTURE] => 
    [SORT] => 500
    [~SORT] => 500
)


Array
(
    [IBLOCK_ID] => 16
    [~IBLOCK_ID] => 16
    [ID] => 162
    [~ID] => 162
    [NAME] => Пуховик красный
    [~NAME] => Пуховик красный
    [PROPERTY_ELEMENT_NAME] => Пуховик на объемной стойке (Красный)
    [~PROPERTY_ELEMENT_NAME] => Пуховик на объемной стойке (Красный)
    [PROPERTY_ELEMENT_CODE] => pukhovik-na-obemnoy-stoyke-krasnyy
    [~PROPERTY_ELEMENT_CODE] => pukhovik-na-obemnoy-stoyke-krasnyy
    [PROPERTY_ELEMENT_PREVIEW_PICTURE] => 
    [~PROPERTY_ELEMENT_PREVIEW_PICTURE] => 
    [SORT] => 500
    [~SORT] => 500
)


it can be seen from the output that a separate array is created for [NAME] => Down jacket is black and white, but with different properties

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2020-02-10
@gromdron

This behavior occurs when you are using InfoBlocks in version 1 (storing properties in a shared table) and requesting a multiple property.
To eliminate this point, you can change the mechanics of work (transfer them to version 2), i.e. change the arrangement of properties in a separate table.
This of course imposes certain restrictions, but duplicates of elements will disappear in getList'ah.
See documentation: https://dev.1c-bitrix.ru/learning/course/?COURSE_I...

P
Pavel Sidorov, 2020-02-09
@pavel__sidorov

I rewrote it a little, but all the records are still displayed. Properties are not grouped to the same element. Infoblocks 2.0 are used.

<?
$ID = $arResult['ID']; 
$arSelect = Array("ID", "NAME", "DATE_ACTIVE_FROM", 'PROPERTY_ELEMENT.ID', 'PROPERTY_ELEMENT.NAME', 'PROPERTY_ELEMENT.CODE',);
$arFilter = Array("IBLOCK_ID"=>16, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y", 'PROPERTY_LOOKBOOK.ID' => $ID);
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>50), $arSelect);
while($ob = $res->GetNextElement())
{
 $arFields = $ob->GetFields();
 echo '<pre>';print_r($arFields);echo '</pre>'; 
 $arRes = $ob->GetProperties(); // свойства элемента
 echo '<pre>';print_r($arRes);echo '</pre>'; 
}
?>

the output is exactly the same when accessing an array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question