A
A
alexwprof2019-08-25 12:32:20
1C-Bitrix
alexwprof, 2019-08-25 12:32:20

Is it possible to get an error in getting Bitrix GetList data?

It is necessary to obtain the properties of related elements, including their price. This is what happens in the code below. There is a property SERVICE_PROD, respectively, through it there is a connection with the elements of another infoblock. Everything would be fine, only the output is an array that cannot be used correctly and it is not possible to substitute values ​​from it.
I would like advice on whether the array is formed correctly and how correctly to use two loops in this case, if not, then how to make one selection that will receive both the price and the name of the product, and so on .... I've been fiddling around for a long time, I can't find a solution

<?if(CModule::IncludeModule("iblock")) {
//Получение цены
    $service_price = $arResult["PROPERTIES"]["SERVICE_PROD"]["VALUE"];
    $rsPrices = CPrice::GetList(
        array(),
        array("PRODUCT_ID" => $service_price,
            "CATALOG_GROUP_ID" => 1,)
    );

    while ($arPriceType = $rsPrices->Fetch())
    {    $arPrice[] = $arPriceType;
        $arResult["PRICE_CART"] =  $arPrice ;
         //debug($arResult["PRICE_CART"]);
    }

//Получение других параметров связанного элемента.
    $arSelect = Array(
        "DATE_ACTIVE_FROM",
        "PROPERTY_SERVICE_PROD.PREVIEW_TEXT",
        "PROPERTY_SERVICE_PROD.NAME",
        "PROPERTY_SERVICE_PROD.ID",
    );

    $arFilter = Array("IBLOCK_ID" => array(2),
        "ACTIVE_DATE" => "Y",
        "ACTIVE" => "Y",
        "ID" => $arResult["ID"]


    );

    $res = CIBlockElement::GetList(
        Array(),
        $arFilter,
        false,
        Array("nPageSize" => 20),
        $arSelect

    );

    while ($ob = $res->GetNextElement()) {
        $arFields[] = $ob->GetFields();
        $arResult["SERV"] = $arFields ;

    }
}

?>

I output as follows, there is a duplication of the results of the array:
<div id="product-services" class="product-services">
   <ul class="list product-services__list">
     <?php foreach($arResult["SERV"] as $arServ):?>
       <?foreach($arResult["PRICE_CART"] as $arPrice):?>
                                
<li class="product-services__item">
  <div class="product-service">
 <div class="product-service__left">
  <div class="product-service__head">

 <div class="product-service__title">
 <?=$arServ['PROPERTY_SERVICE_PROD_NAME']?>
          </div>
   <div class="product-service__price">
    <?/*Подставляем цену*/?>
       <?=$arPrice["PRICE"] ?>
                                                     </div>
                                            </div>
                                            
  <div class="product-service__description">
      <?=$arServ['PROPERTY_SERVICE_PROD_PREVIEW_TEXT'] ?>
      </div>
 </div>
   <div class="product-service__right">
     <a href="#" class="button product-service__button"><i
    class="fas fa-cart-plus button__icon"></i>Добавить
    услугу</a>
    </div>
 </div>
 </li>
<?endforeach?>
   <?endforeach;?>
  </ul>
  </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