R
R
redesupar2021-10-06 17:45:59
PHP
redesupar, 2021-10-06 17:45:59

How to form the desired array on Bitrix?

There was a task to display the necessary data from another infoblock, I made it, of course, crooked and askew, and I had to put it inside one cycle, i.e. It turns out a cycle within a cycle. They say to make an array and just output the data in a loop?

<?
      $arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM","PROPERTY_*");
    $promocat = $arParams["PRODUCT_CATEGORY_VALUE"];
        $promomag = $onlineShop["ID"];
  $arFilter = Array("IBLOCK_ID"=>140, "PROPERTY_PRODUCTS_CATEGORY"=>$promocat, "PROPERTY_MAGAZINE"=>$promomag, "ACTIVE"=>"Y");
      $res = CIBlockElement::GetList(Array(), $arFilter, $arSelect);
    while($ob = $res->GetNextElement()){
  $arProps = $ob->GetProperties();
        echo $arProps["TEXT_PROMOCODE"]["VALUE"];
                                                            }
                                                            ?>


but it is necessary to do something like this in the cycle itself, how to do it?

<? if (!empty($onlineShop["LINK_TO_SITE"])) : ?>
                  <a href="<?= $onlineShop["LINK_TO_SITE"]?>" class="btn btn-blue-border btn-small" target="_blank">В магазин</a>
                <? endif; ?>


UPD

<div class="tab-pane active" id="tab_online">
      <div class="detail-shops-list">
        <? foreach ($arResult["ONLINE_SHOP"] as $onlineShop) : ?>

          <?if(empty($onlineShop["LINK_TO_SITE"])){continue;}?>
          <div class="shop-row">

            <div class="shop-left">
              <div class="shop-logo">
                <img src="<?= $onlineShop["PREVIEW_PICTURE"]["SRC"] ?>" alt="<?= $onlineShop["PREVIEW_PICTURE"]["ALT"] ?>" title="<?= $onlineShop["PREVIEW_PICTURE"]["TITLE"] ?>" />
              </div>
              <div class="shop-title"><?=$onlineShop["NAME"];?></div>
            </div>
            <div class="shop-right">
              <div class="shop-price">
                <?if(!empty($arParams["PRODUCT_PRICE"])):?>
                  Цена: <?=$arParams["PRODUCT_PRICE"]?>
                <?endif;?>
              </div>

              <div class="shop-btns">

      <div id="openModal-<?=$onlineShop["ID"];?>" class="modal">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                 <a href="#close" title="Close" class="close">×</a>
                                                </div>
                                                <div class="modal-body">
                                                    <center>

                                                        <p>Нажмите на промокод ниже, чтобы скопировался</p>
                                                        <div class="text_copy_link">

                                                            <?
                                                            $arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM","PROPERTY_*");
                                                            $promocat = $arParams["PRODUCT_CATEGORY_VALUE"];
                                                            $promomag = $onlineShop["ID"];
                                                            $arFilter = Array("IBLOCK_ID"=>140, "PROPERTY_PRODUCTS_CATEGORY"=>$promocat, "PROPERTY_MAGAZINE"=>$promomag, "ACTIVE"=>"Y");
                                                            $res = CIBlockElement::GetList(Array(), $arFilter, $arSelect);
                                                            while($ob = $res->GetNextElement()){
                                                                $arProps = $ob->GetProperties();
                                                                echo $arProps["TEXT_PROMOCODE"]["VALUE"];
                                                            }
                                                            ?>


                                                        </div>
                                                    </center>

                                                    <div class="copy_link_mess">Скопировано в буфер обмена</div>

                                                </div>
                                            </div>
                                        </div>
                                    </div>


                                <a href="#openModal-<?=$onlineShop["ID"];?>" class="btn btn-small btn-blue-border" >Промокод</a>

                                <? if (!empty($onlineShop["LINK_TO_SITE"])) : ?>
                  <a href="<?= $onlineShop["LINK_TO_SITE"]?>" class="btn btn-blue-border btn-small" target="_blank">В магазин</a>
                <? endif; ?>
              </div>
            </div>
          </div>
        <? endforeach; ?>
      </div>
    </div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question