A
A
Anton2017-08-22 17:55:10
PHP
Anton, 2017-08-22 17:55:10

How to insert some value into the $arResult['ITEMS'] array in Bitrix?

there is a template code, the output of product elements from the catalog
catalog.section
How to insert arbitrary code every 7 elements, for example, a picture (banner + link).

<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
//echo '<!--ttt';
//print_r($arResult);
//echo '-->';
?>

<?if (!empty($arResult['UF_BANNER_LG'])){?>
    <div class="container">
        <div class="banner-with-btn_content-left">
            <img class="hidden-sm hidden-xs hidden-md" src="<?=CFile::GetPath($arResult['UF_BANNER_LG'])?>" alt="">
            <img class="hidden-lg hidden-xs" src="<?=CFile::GetPath($arResult['UF_BANNER_SM'])?>" alt="">
            <img class="hidden-lg hidden-md hidden-sm" src="<?=CFile::GetPath($arResult['UF_BANNER_XS'])?>" alt="">
            <div class="banner-with-btn_content-left__info-wrapper">
                <div class="banner-with-btn_content-left__main-title">
                    <?=$arResult['UF_BANNER_TITLE']?>
                </div>
                <div class="banner-with-btn_content-left__description">
                    <?=$arResult['UF_BANNER_DESC']?>
                </div>
                <a href="<?=($arResult['UF_BANNER_LINK'])?$arResult['UF_BANNER_LINK']:'javascript:void();'?>" class="btn-corner-grey btn-corner-grey_font-family_segoeui-regular btn-corner-grey_font-family_font-size_15px btn-corner-grey_2e2e2e"><?=($arResult['UF_BANNER_BTN_TEXT'])?$arResult['UF_BANNER_BTN_TEXT']:'Выбрать очки'?> <i class="fa fa-angle-right"></i></a>
            </div>
        </div>
    </div>

<?}?>



<?if (!empty($arResult['ITEMS'])){?>

<div class="container">
    <div class="catalog-section">
        <?if($arParams["DISPLAY_TOP_PAGER"]):?>
            <?=$arResult["NAV_STRING"]?>
        <?endif;?>

        <div class="row catalog-section__items-wrapper">
            <?foreach ($arResult['ITEMS'] as $arCurItem){?>
                <script>
                    var arLocalImpressionItem = [];
                    arLocalImpressionItem['id'] = '<?=$arCurItem['ID'];?>';
                    arLocalImpressionItem['name'] = '<?=$arCurItem['NAME'];?>';
                    arLocalImpressionItem['list'] = '<?=$arResult['NAME']?>';

                    window.arImpressionItems.push(arLocalImpressionItem);



                </script>


 <div class="col-sm-6 col-lg-4">
                <div class="item-preview-hover">
                    <div class="item-preview-hover__container">
                        <a class="item-preview-hover__url" onclick="onProductClick(<?=$arCurItem['ID']?>,'<?=$arCurItem['NAME']?>',<?=(++$i)?>,'<?=$arResult['NAME']?>','<?=$arCurItem["DETAIL_PAGE_URL"]?>');"  href="<?=$arCurItem["DETAIL_PAGE_URL"]?>" title="<?=$arCurItem["NAME"]?>">
                            <div class="item-preview-hover__img">
                                <?
                                if(is_array($arCurItem["PREVIEW_PICTURE"])) {
                                    $arImg = CFile::ResizeImageGet($arCurItem['PREVIEW_PICTURE'], array('width'=>300, 'height'=>140), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                                }elseif (!empty($arCurItem['PROPERTIES']['FOTO']['VALUE'])){
                                    if (is_array($arCurItem['PROPERTIES']['MORE_FOTO']['VALUE'])){
                                        $arImg = CFile::ResizeImageGet(reset($arCurItem['PROPERTIES']['MORE_FOTO']['VALUE']), array('width'=>300, 'height'=>140), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                                    }else{
                                        $arImg = CFile::ResizeImageGet($arCurItem['PROPERTIES']['MORE_FOTO']['VALUE'], array('width'=>300, 'height'=>140), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                                    }
                                }

                                $bBy = false;
                                $strOT = "";
                                $arPrice1 = CCatalogProduct::GetOptimalPrice($arCurItem["ID"], 100, 2);
                                $arPrice2 = CCatalogProduct::GetOptimalPrice($arCurItem["ID"], 1, 2);
                                if($arPrice1["DISCOUNT_PRICE"] != $arPrice2["DISCOUNT_PRICE"])
                                    $strOT = "от ";
                                $myPrice = FormatCurrency($arPrice1["DISCOUNT_PRICE"], $arPrice1["PRICE"]["CURRENCY"]);
                                $myPrice = $strOT.str_replace(",00", "", $myPrice);
                                if($arPrice1["DISCOUNT_PRICE"] > 10)
                                    $bBy = true;

                                ?>

                                <img src="<?=$arImg['src']?>" alt="<?=$arCurItem['NAME']?>">
                            </div>
                            <div class="item-preview-hover__name">
                                <?=$arCurItem['NAME']?>
                            </div>
                        </a>
                        <div class="item-preview-hover__price-item-type">
                            <div class="item-preview-hover__price-item-type-wrapper">
                                <div class="item-preview-hover__price item-preview-hover__price_padding-top_5px">
                                    Цена: <?=$myPrice?>
                                </div>
                                <div class="item-preview-hover__item-type">

                                </div>
                            </div>
                            <div class="item-preview-hover__like item-preview-hover__like">
                                <a data-element-id="<?=$arCurItem['ID']?>" class="btn-favourite-like" href="javascript:void(0);">
                                    <i class="fa fa-heart-o"></i>
                                </a>
                            </div>
                        </div>
           

                    </div>
                </div>
            </div>
            <?}?>
        </div>
        <?if($arParams["DISPLAY_TOP_PAGER"]):?>
            <?=$arResult["NAV_STRING"]?>
        <?endif;?>

    </div>
</div>
<?}?>

<div class="container">
    <div class="section-top-line section__bottom-section section-bottom-line">
        <h3 class="section-title">
            <?=$APPLICATION->ShowTitle();?>
        </h3>
        <div class="row">
            <?if ($arResult['UF_DESC_IMG']){?>
                <div class="col-sm-6 section-img-wrapper">
                    <img src="<?=CFile::GetPath($arResult['UF_DESC_IMG'])?>" alt=""/>
                </div>
            <?}?>
            <?=$arResult['DESCRIPTION']?>
        </div>
    </div>

</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2017-08-22
@gangstarcj

Use the counter in a loop, divide without a remainder by 7, check the result and output the desired code

N
Nikita Ermilichev, 2017-08-24
@Masas

Or check whether it is equal to 6, display the desired content and reset it to zero.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question