R
R
Ruslan Absalyamov2018-07-31 13:21:36
1C-Bitrix
Ruslan Absalyamov, 2018-07-31 13:21:36

How to sort the data in the shopping cart alphabetically?

I don't understand where the sale.basket.basket component gets its data from. It seems that I am changing the array and I see that the data has changed, but in appearance they have not changed, and here I have big questions, how to sort
in the js-templates/basket-item.php file.
So I sorted in result_modifer.php

$product = array();
foreach ($arResult["BASKET_ITEM_RENDER_DATA"] as $key => $value){
    $product[$key] = $value["NAME"];
}
array_multisort($product, SORT_ASC, $arResult["BASKET_ITEM_RENDER_DATA"]);

I also tried to change both ITEMS and [GRID][ROWS], the arResult array itself changes, but in the template it is not clear why they are not erased

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kudis, 2018-08-02
@rusline18

In the basket-item.php file, goods most often come in the $arResult['GRID']['ROWS'] array,
so your result_modifer.php should contain something like this

class Kudis
{
    public static function sortByNameAsc($arrA, $arrB)
    {
        $a = $arrA['NAME'];
        $b = $arrB['NAME'];

        if ($a == $b) {
            return 0;
        }
        return ($a < $b) ? -1 : 1;
    }
}

uasort($arResult['GRID']['ROWS'], ['Kudis', 'sortByNameAsc']);

well, or, you can sort through multisort. Whoever likes it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question