M
M
msn0y2022-03-31 10:04:42
1C-Bitrix
msn0y, 2022-03-31 10:04:42

How to display the properties of products linked by "Binding to elements" in Bitrix?

Good day!
The first thing I want to say: yes, I already googled and found like a lot of answers, but for some reason they stopped for me.

Task: Make an alternative to TP thanks to the "Binding to elements" property.
For implementation, you need to get:
1) id,
2) name,
3) link,
4) CAN_BUY parameter or at least QUANTITY
5) some property (now I'm implementing by color)
1-3 item was obtained, now the problem is with 4 and 5 points and, even if getting QUANTITY is a little easier, then with the color of an ambush.
Now the colors are implemented by the reference book and they don’t want to give out values, I tried to add 2 more different types of properties: "string" and "list" - even if I call the property by character code - I get an empty value.

Code in the product card:

<?php if (count($arResult['CATALOG_TP_COLOR']) > 0) : ?>
                <div class="offer-property-row mb-3 first last">
                    <div class="font-weight-bold">Цвет: </div>
                    <?php foreach ($arResult['CATALOG_TP_COLOR'] as $id => $product) : ?>
                        <? echo "<pre>"; print_r($product['COLOR']); echo "</pre>";?>
                        <a class="btn btn-light mb-1 <?php if ($product['ID'] == $arResult['ID']) : echo 'active'; ?><?php endif; ?>" title="<?php echo $product['NAME']; ?>" href="<?php echo $product['DETAIL_PAGE_URL']; ?>">
                            <?php echo $product['NAME']; ?> - <?php echo $product['QUANTITY']; ?>
                        </a>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>


Here I try to call the properties I need, but all in vain:
$TPcolorsList = array();
$arResult['CATALOG_TP_COLOR'] = array();
$arSelect = array("IBLOCK_ID", "ID", "NAME", "DETAIL_PAGE_URL");
$arFilter = Array("IBLOCK_ID" => 5, "ID" => $arResult['PROPERTIES']['CATALOG_TP_COLOR']['VALUE']);
$res = CIBlockElement::GetList(array(), $arFilter, false, array("nPageSize" => 10), $arSelect);
while ($ob = $res->GetNextElement()) {
    $arFields = $ob->GetFields();
    $TPcolorsList[$arFields['ID']]['NAME'] = $arFields['NAME'];
    $TPcolorsList[$arFields['ID']]['DETAIL_PAGE_URL'] = $arFields['DETAIL_PAGE_URL'];
    $TPcolorsList[$arFields['ID']]['ID'] = $arFields['ID'];
    $TPcolorsList[$arFields['ID']]['QUANTITY'] = $arResult['PRODUCT']['QUANTITY'];
    $TPcolorsList[$arFields['ID']]['COLOR'] = $arResult;
}
if (count($TPcolorsList) > 0) {
    $arResult['CATALOG_TP_COLOR'] = $TPcolorsList;
}
unset($TPcolorsList);
unset($arSelect);
unset($arFilter);
unset($res);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2022-03-31
@msn0y

When you select, you do not specify the COLOR property field, therefore it will not be there. You need to add something like "PROPERTY_COLOR" to $arSelect . Also, the main fields get $arFields = $ob->GetFields(); but there is no property, somehow it was written like this: $arProps = $ob->GetProperties();
If you answer about "quantity of goods in stock", then in the above code you don't get the quantity at all, you just assign the value from the $arResult['PRODUCT']['QUANTITY'] variable. If you want to get the information block for the selected element, then you need to load the catalog module and request data from there.
And start studying bitrix d7 already , the functions you use are out of date.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question