From cd5d72e272f8ae12b7f543520fc11510e96923c6 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 13 Feb 2026 05:42:54 +0100 Subject: [PATCH] fix: make drag-and-drop on category tree persist correctly Two issues prevented the shelf tree reordering from working: - The JS used ``onDragStop`` (only fires for drags outside the tree) instead of the ``tree.move`` event to send the AJAX request. Moved the POST into the ``tree.move`` handler. - The ``inside`` case used ``appendNode`` (last child), but jqTree sends ``inside`` when dropping before the first child. Switched to ``prependNode`` so the node lands first. - Added missing ``before`` case with ``insertBeforeNode``. --- app/Repositories/Core/Categories.php | 12 ++--- .../Shop/Categories/partials/tree.blade.php | 51 +++++-------------- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/app/Repositories/Core/Categories.php b/app/Repositories/Core/Categories.php index 5b654413..e508ae2c 100644 --- a/app/Repositories/Core/Categories.php +++ b/app/Repositories/Core/Categories.php @@ -67,17 +67,15 @@ class Categories $category_target = self::getNode($target_id); switch ($type) { + case 'before': + return $category->insertBeforeNode($category_target); case 'after': - $category->afterNode($category_target); - break; + return $category->insertAfterNode($category_target); case 'inside': - $category_target->appendNode($category); - break; + return $category_target->prependNode($category); default: - $category->afterNode($category_target); + return $category->insertAfterNode($category_target); } - - return $category->save(); } public static function create($data) diff --git a/resources/views/Admin/Shop/Categories/partials/tree.blade.php b/resources/views/Admin/Shop/Categories/partials/tree.blade.php index 915c69f7..a68d4757 100644 --- a/resources/views/Admin/Shop/Categories/partials/tree.blade.php +++ b/resources/views/Admin/Shop/Categories/partials/tree.blade.php @@ -14,57 +14,30 @@ @push('js') @endpush