public function sortAccessoriesList()
    {
        $oxidRelationId = Registry::getConfig()->getRequestEscapedParameter('oxid');
        $selectedIdForSort = Registry::getConfig()->getRequestEscapedParameter('sortoxid');
        $sortDirection = Registry::getConfig()->getRequestEscapedParameter('direction');

        $accessoriesList = oxNew(ListModel::class);
        $accessoriesList->init("oxbase", "oxaccessoire2article");
        $sortQuery = "select * from  oxaccessoire2article where OXARTICLENID= " . DatabaseProvider::getDb()->quote($oxidRelationId) . " order by oxsort,oxid";
        $accessoriesList->selectString($sortQuery);


        $rebuildList = $this->rebuildAccessoriesSortIndexes($accessoriesList);

        if (($selectedPosition = array_search($selectedIdForSort, $rebuildList)) !== false) {
            $selectedSortRecord = $accessoriesList->offsetGet($rebuildList[$selectedPosition]);
            $currentPosition = $selectedSortRecord->oxaccessoire2article__oxsort->value;

            // get current selected row sort position

            if (($sortDirection == 'up' && $currentPosition > 0) || ($sortDirection == 'down' && $currentPosition < count($rebuildList) - 1)) {
                $newPosition = ($sortDirection == 'up') ? ($currentPosition - 1) : ($currentPosition + 1);

                // exchanging indexes
                $currentRecord = $accessoriesList->offsetGet($rebuildList[$currentPosition]);
                $newRecord = $accessoriesList->offsetGet($rebuildList[$newPosition]);

                $currentRecord->oxaccessoire2article__oxsort = new Field($newPosition);
                $newRecord->oxaccessoire2article__oxsort = new Field($currentPosition);
                $currentRecord->save();
                $newRecord->save();
            }
        }

        $outputQuery = $this->_getQuery();

        $normalQuery = 'select ' . $this->_getQueryCols() . $outputQuery;
        $countQuery = 'select count( * ) ' . $outputQuery;

        $this->_outputResponse($this->_getData($countQuery, $normalQuery));
    }