A
A
Artyom Suzenko2019-04-22 12:36:07
1C-Bitrix
Artyom Suzenko, 2019-04-22 12:36:07

How to display a list of products without photos from several categories?

Hello!
I do it like this:

CModule::IncludeModule("iblock");

$IBLOCK_ID=10;  //ID нужного информационного блока

$SECTION_ID = Array('861', '1496', '1543'); // 1566, 1202, 1208, 1242, 1275, 1284, 1285, 1289, 1300, 1181, 1375);

$arSelect = Array("ID", "NAME", "PREVIEW_PICTURE", "DETAIL_PICTURE", "DETAIL_PAGE_URL", "IBLOCK_SECTION_ID"); // Указываем список параметров, которые будем использовать

$arFilter = Array("IBLOCK_ID"=>$IBLOCK_ID, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y"); // Указываем параметры фильтра, по которым будем выводить элементы

$res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, false, array("nPageSize" => 10), $arSelect); // Вызов 

$res->NavStart(0);

while($ob = $res->GetNextElement())
{
  $arFields = $ob->GetFields();
  if (!isset($arFields["PREVIEW_PICTURE"]) && in_array($arFields['IBLOCK_SECTION_ID'], $SECTION_ID)) {

    //echo 'Выводим путь к изображению превью: '.CFile::GetPath($arFields["PREVIEW_PICTURE"]).'" и имя: '.$arFields["NAME"].'.<br>';
    //echo 'Выводим путь к детальному изображению: '.CFile::GetPath($arFields["DETAIL_PICTURE"]).'<br>';
    //echo 'Выводим пользовательсткое свойство инфоблока: '.$arFields["PROPERTY_YOUTUBELINK_VALUE"].' (в данном случае ссылка на ролик youtube)<br>';

    echo "<pre>";
    echo $arFields["ID"].' - <a href="'.$arFields["DETAIL_PAGE_URL"].'" target="_blank"><span>'.$arFields["NAME"].'</a></span> - '.$arFields["IBLOCK_SECTION_ID"];
    echo "</pre>";

    //print_r($arSelect);
    /* *** */

    /* *** */
  }
}
echo $res->NavPrint();

Displays products only from one section, it is not clear why.
Help pliz!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2019-04-22
@CrewGer

UPDATE:

<?
require_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("iblock");
$arSelect = Array("NAME", "ID", "DETAIL_PAGE_URL", "SECTION_ID");
$arFilter = Array("IBLOCK_ID"=>10, "SECTION_ID"=>'69, 114', "INCLUDE_SUBSECTIONS" => "Y", "PREVIEW_PICTURE" => false);
$res = CIBlockElement::GetList(Array("ID"=>"DESC"), $arFilter, false, Array("nPageSize"=>500000), $arSelect);
while($ob = $res->GetNextElement())
{
$arFields = $ob->GetFields();
{?>
<?=$arFields[ID]?> - <a href="<?=$arFields[DETAIL_PAGE_URL]?>"><?=$arFields[NAME]?></a>
 - Подраздел №<?=$arFields[IBLOCK_SECTION_ID]?></br>
<?}
}
?>

K
Kirill Proger, 2019-04-22
@freekirill

You need to specify a parameter in the filter
Also "nPageSize" => 10 - it's worth that it says to show only the first 10 elements from the array
. Also, it is desirable to add the 'INCLUDE_SUBSECTIONS'=>'Y' parameter to $arFilter so that the elements are taken from folders, not only from the root.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question