A
A
Anya Ivanova2020-07-27 13:11:19
1C-Bitrix
Anya Ivanova, 2020-07-27 13:11:19

How to output a custom property "binding to elements"?

Good day to all!
I want related products to be displayed for each section on the product detail page.
For example, the footwear section, on det.str. any product must have related products (socks, laces).
And in the pants section there should be (a belt and something else).

I found something like this on the Internet, but it does not display goods.

<?
$db_list = CIBlockElement::GetList(Array(), $arFilter = Array("IBLOCK_ID"=>8, "ID"=>$arResult["ID"]), true, Array("UF_RECOMMEND")); 
$props_array = $db_list->GetNext();

if (!empty($props_array["UF_RECOMMEND"])) {
    $rsSections = CIBlockElement::GetList(
        array("SORT" => "ASC"),
        array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "ID" => $props_array["UF_RECOMMEND"]),
        false,
        array("NAME", "DETAIL_PICTURE", "PICTURE", "SECTION_PAGE_URL"),
        false
    );
    ?>
    <section class="recomend">
        <h2 class="recomend-title">Сопутствующие товары:</h2>
        <div class="recomend-wrap">
            <?
            while ($arSections = $rsSections->GetNext()) {
                ?>
                <div class="recomend-item" oncl ick="location.href='<?= $arSections['SECTION_PAGE_URL'] ?>';">
                    <div class="recomend-img">
                        <img src="<?= CFile::GetPath($arSections['PICTURE'])?>" class="recomend-img-art" alt="<?= $arSections['NAME'] ?>" title="<?= $arSections['NAME'] ?>">
                    </div>
                    <div class="recomend-name">
                        <h3><?= $arSections['NAME'] ?></h3>
                    </div>
                </div>
                <?
            }
            ?>
        </div>
    </section>
    <?
}
?>

The "recommended products" component displays a set of my related products for all sections. And I need for each section its related products.
I would also like to buy a button and display the price, in general it would be great.
Tell me what's wrong here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivashjke, 2020-07-27
@saharok13

$db_list = CIBlockElement::GetList(Array(), $arFilter = Array("IBLOCK_ID"=>8, "ID"=>$arResult["ID"]), true, Array("UF_RECOMMEND"));

in the query true is $arGroupBy - there should be an array by which properties to group
and Array("UF_RECOMMEND") is arNavStartParams
arSelect you don't have
$props_array = $db_list->GetNext(); - here props_array is an object, so if (!empty($props_array["UF_RECOMMEND"])) { here the fatality will be
first you need to do this
$props_array = CIBlockElement::GetList(Array(), $arFilter = Array("IBLOCK_ID"=>8, "ID"=>$arResult["ID"]), false, false Array('ID', 'IBLOCK_ID',"UF_RECOMMEND"))->Fetch();

and here
$rsSections = CIBlockElement::GetList(array("SORT" => "ASC"),
        array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "ID" => $props_array["UF_RECOMMEND"]),
        false,
        array("NAME", "DETAIL_PICTURE", "PICTURE", "SECTION_PAGE_URL"),
        false

same error - array("NAME", "DETAIL_PICTURE", "PICTURE", "SECTION_PAGE_URL"), and swap the last false
and this while ($arSections = $rsSections->GetNext()) {
replace with $arSections = $ rsSections->Fetch()
since GetNext() will have an object in $arSections and you will need to select fields via $fields = $arSections->GetFields()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question