На главной странице я вывожу главные категории каталога и в них подкатегории только первого уровня, без дальнейшей вложенности. Появилась задача, если товаров в главной категории мало (< 10), то выводить заголовки товаров без подкатегорий.
Подскажите, как можно реализовать?
Вывожу категории вот так:
Код |
---|
<ul class="<? echo $arCurView['LIST']; ?>">
<?
foreach ($arResult['SECTIONS'] as &$arSection)
{
$this->AddEditAction($arSection['ID'], $arSection['EDIT_LINK'], $strSectionEdit);
$this->AddDeleteAction($arSection['ID'], $arSection['DELETE_LINK'], $strSectionDelete, $arSectionDeleteParams);
if ($intCurrentDepth < $arSection['RELATIVE_DEPTH_LEVEL'])
{
if (0 < $intCurrentDepth){
print_r($arSection['ID']);
echo "\n",str_repeat("\t", $arSection['RELATIVE_DEPTH_LEVEL']),'<ul class="'.$intCurrentDepth.'">';
}
}
elseif ($intCurrentDepth == $arSection['RELATIVE_DEPTH_LEVEL'])
{
if (!$boolFirst) {
echo '</li>';
}
}
else
{
$activeElements = CIBlockSection::GetSectionElementsCount($arSection['ID'], Array("CNT_ACTIVE"=>"Y"));
print_r($activeElements);
while ($intCurrentDepth > $arSection['RELATIVE_DEPTH_LEVEL'])
{
echo '</li>',"\n",str_repeat("\t", $intCurrentDepth),'</ul>',"\n",str_repeat("\t", $intCurrentDepth-1),($arSection['ID'] == 2 ? '<div style="clear:both"></div><a href="/kalkulyator-raschyeta/" class="btn calc-list-btn">
<sv g width="35" height="29" viewBox="0 0 35 29" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M0.835851 0C0.372608 0 0 0.37925 0 0.844463V28.1606C0 28.6258 0.372608 29 0.835851 29H34.1641C34.6274 29 35 28.6258 35 28.1606V0.844463C35 0.37925 34.6274 0 34.1641 0H0.835851ZM17.2407 13.6581V1.68387H1.67674V13.6581H17.2407ZM33.3283 1.68387H28.283H18.9124V27.3212H33.3283V1.68387ZM1.67674 15.3419V27.3212H17.2407V15.3419H1.67674Z" fill="white"></path>
<path d="M9.21443 4.80342V7.18557H6.77728C5.74091 7.18557 5.74091 8.81443 6.77728 8.81443H9.21443V11.1966C9.21443 12.2678 10.7856 12.2678 10.7856 11.1966V8.81443H13.2227C14.2591 8.81443 14.2591 7.18557 13.2227 7.18557H10.7856V4.80342C10.7856 3.73219 9.21443 3.73219 9.21443 4.80342Z" fill="white"></path>
<path d="M6.77728 22H13.2227C14.2591 22 14.2591 20 13.2227 20H6.77728C5.74091 20 5.74091 22 6.77728 22Z" fill="white"></path>
<path d="M22.8416 14H30.1584C31.2805 14 31.2805 12 30.1584 12H22.8416C21.7195 12 21.7195 14 22.8416 14Z" fill="white"></path>
<path d="M22.8416 17H30.1584C31.2805 17 31.2805 15 30.1584 15H22.8416C21.7195 15 21.7195 17 22.8416 17Z" fill="white"></path>
</svg>
калькулятор
</a>' : ' ');
$intCurrentDepth--;
}
echo str_repeat("\t", $intCurrentDepth-1),'</li>';
}
echo (!$boolFirst ? "\n" : ''),str_repeat("\t", $arSection['RELATIVE_DEPTH_LEVEL']);
?>
<li class="<?if ($APPLICATION->GetCurPage() == '/'):?>sect<?=$arSection['ID']?><?else:?> no-main-sect sect_<?=$arSection['ID']?><?endif;?> <?if ($arSection['DEPTH_LEVEL']==1):?><?if ($APPLICATION->GetCurPage() == '/'):?>col-md-4<?else:?>col-md-6<?endif;?> main-catalog-item first<?endif?>" id="<?=$this->GetEditAreaId($arSection['ID']);?>">
<span><?// if($activeElements < 5) echo $activeElements ?></span>
<h2 class="bx_sitemap_li_title <?if ($arSection['DEPTH_LEVEL']==1):?>bold<?endif?>">
<a href="<? echo $arSection["SECTION_PAGE_URL"]; ?>"><? echo $arSection["NAME"];?></a>
</h2>
<?
$arFilter = array('IBLOCK_ID' => 7,'>LEFT_MARGIN' => $arSection['LEFT_MARGIN'],'<RIGHT_MARGIN' => $arSection['RIGHT_MARGIN'],'>DEPTH_LEVEL' => $arSection['DEPTH_LEVEL']); // выберет потомков без учета активности
$rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'),$arFilter);
$arSecti = array();
while ($arSect = $rsSect->GetNext())
{
$arSecti[] = $arSect['NAME'];
//echo $arSect['NAME'];
}
if(empty($arSecti) && $arSection['DEPTH_LEVEL'] == 1){
echo '<div class="desc_section">';
echo substr($arSection['DESCRIPTION'], 0, 230);
echo '</div>';
}
?>
<?if ($arSection['DEPTH_LEVEL']==1):?>
<img class="sections_image" src="<?=$arSection['PICTURE']['SRC']?>">
<?endif?>
<?$intCurrentDepth = $arSection['RELATIVE_DEPTH_LEVEL'];
$boolFirst = false;
}
unset($arSection);
while ($intCurrentDepth > 1)
{
echo '</li>',"\n",str_repeat("\t", $intCurrentDepth),'</ul>',"\n",str_repeat("\t", $intCurrentDepth-1);
$intCurrentDepth--;
}
if ($intCurrentDepth > 0)
{
echo '</li>',"\n";
}?>
</ul>
|
Я пытаюсь получить по ID категории кол-во товара, что бы иметь возможность сделать условие.
Код |
---|
$activeElements = CIBlockSection::GetSectionElementsCount($arSection['ID'], Array("CNT_ACTIVE"=>"Y"));
|
И это странно работает. Т.к. я получаю почему-то id не следующей категории а не той которая сейчас в цикле.