A
A
Alexander2019-07-09 15:41:15
1C-Bitrix
Alexander, 2019-07-09 15:41:15

How to re-sort the properties of the Bitrix element and pass them to the array further?

There is an element, it has properties.
One of the properties is the new property sort order.
I am reordering the array in result_modifier.php

//формирую новый массив с новыми данными для сортировки
foreach ($arResult["DISPLAY_PROPERTIES"] as $key => $array_sort) {

    if($array_sort['CODE'] == 'AD_SORT_SORT') $array_sort_value = array($array_sort['VALUE']);
}

// пересортировываю массив

foreach ($array_sort_value['0'] as $key => $value) {
    $arrr = explode("=",$value);
    $sort[trim($arrr['0'])] = $arrr['1'];
}
//сортирую по возрастанию
asort($sort);
print_r($sort);

$arResult["DISPLAY_PROPERTIES"] = array_map(

    function ($itm) use ($sort) {        
        $id = $itm['ID'];
        if (isset($sort[$id])) {
            $itm['SORT'] = $sort[$id];
        }
        return $itm;
    },
    $arResult["DISPLAY_PROPERTIES"]
);?>

Everything seems to be OK, the array has been changed, but then the properties are still displayed with the default sorting.
those. this code gives the array I need: but then all the same, Bitrix displays the elements with default sorting. What could be wrong? Where to see?
Array ( [185] => 300 [173] => 350 [172] => 500 )
Array ( [172] => 500 [185] => 300 [173] => 350 )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-07-10
@kikher

added another re-sorting, and everything fell into place

usort($arResult["DISPLAY_PROPERTIES"], function ($a, $b) {
    return $a['SORT'] - $b['SORT'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question