N
N
Nadezhda Golovina2021-04-25 11:27:33
1C-Bitrix
Nadezhda Golovina, 2021-04-25 11:27:33

How to display properties of another element in a section through a UF box?

Hello.
There is a block "Bestsellers". Already output IMG, NAME and DETAIL_PAGE_URL, and buttons.
How can I display the "Number" and "String" properties - Price and Dimensions - from the infoblock elements? To the category.

<?
$rsResult = CIBlockSection::GetList(array("SORT" => "ASC"), array("IBLOCK_ID" => "27", 'ID' => $arResult["SECTION"]["ID"]), true, Array("UF_HITS"));
  while ($arResult = $rsResult -> GetNext())
  {
  if (!empty($arResult["UF_HITS"])) 
  {
  $iter = $arResult["UF_HITS"];
  }
  }
$arFilter = array('IBLOCK_ID' => 27,'ID' => $iter);
  $rsItems = CIBlockElement::GetList(array(),$arFilter);
  while ($arItem = $rsItems->GetNext())
  {
  if (!empty($iter))
  {
  $resizer = $arItem['PREVIEW_PICTURE'];
  $file = CFile::ResizeImageGet($resizer, array('width'=>180, 'height'=>290), BX_RESIZE_IMAGE_PROPORTIONAL , true);
  $img = $file['src'];
  echo 
      '<div class="hits-smallcard">
        <img src="'.$img.'" />
        <p><a href="'.$arItem["DETAIL_PAGE_URL"].'">'.$arItem["NAME"].'</a></p>
        <p><a href="#modal1" class="popup-content">Заказать</a></p>
        <p><a href="'.$arItem["DETAIL_PAGE_URL"].'">Подробнее</a></p>
        <p>'.$arItem["CASH"].'</p> //не выводит, число
        <p>'.$arItem["ATT_PRICE"].'</p> //не выводит, строка
      </div>'; 
  }
  }
  ?>

I understand that through GetList it is necessary to do. But I don't know how to spell it correctly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2021-04-26
@winer

In order for the IB element to have property values ​​in $arItem, they must be added to the arSelectFields parameter in CIblockElement::GetList

$rsItems = CIBlockElement::GetList(array(),$arFilter, false, false, ["*", "PROPERTY_CASH", "PROPERTY_ATT_PRICE"]);

It is also worth paying attention to the flaw in the code. You are not checking for elements in the $iter array. If, for one reason or another, $iter is empty, then GetList will select all elements from the infoblock.
<?
<?
$rsResult = CIBlockSection::GetList(array("SORT" => "ASC"), array("IBLOCK_ID" => "27", 'ID' => $arResult["SECTION"]["ID"]), true, Array("UF_HITS"));
while ($arResult = $rsResult -> GetNext())
{
  if (!empty($arResult["UF_HITS"])) 
  {
    $iter = $arResult["UF_HITS"];
  }
}

if (!empty($iter))
{
  $arFilter = array('IBLOCK_ID' => 27,'ID' => $iter);
  $rsItems = CIBlockElement::GetList(array(),$arFilter);
  while ($arItem = $rsItems->GetNext())
  {

    $resizer = $arItem['PREVIEW_PICTURE'];
    $file = CFile::ResizeImageGet($resizer, array('width'=>180, 'height'=>290), BX_RESIZE_IMAGE_PROPORTIONAL , true);
    $img = $file['src'];
    echo 
    '<div class="hits-smallcard">
      <img src="'.$img.'" />
      <p><a href="'.$arItem["DETAIL_PAGE_URL"].'">'.$arItem["NAME"].'</a></p>
      <p><a href="#modal1" class="popup-content">Заказать</a></p>
      <p><a href="'.$arItem["DETAIL_PAGE_URL"].'">Подробнее</a></p>
      <p>'.$arItem["CASH"].'</p> //не выводит, число
      <p>'.$arItem["ATT_PRICE"].'</p> //не выводит, строка
    </div>'; 
  }
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question