Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve JS.

Matthew Kennedy2c57edae02f2
diff --git a/api/app/controllers/spree/api/v2/platform/menu_items_controller.rb b/api/app/controllers/spree/api/v2/platform/menu_items_controller.rb
index 44a7151e20..96fd8fbd82 100644
--- a/api/app/controllers/spree/api/v2/platform/menu_items_controller.rb
+++ b/api/app/controllers/spree/api/v2/platform/menu_items_controller.rb
@@ -4,8 +4,9 @@ module Spree
module Platform
class MenuItemsController < ResourceController
def reposition
+ puts "MSK: #{params[:new_parent_id]}"
@moved_item = Spree::MenuItem.find(params[:moved_item_id])
- @new_parent = if params[:new_parent_id] == 'undefined' || params[:new_parent_id].nil?
+ @new_parent = if params[:new_parent_id].nil?
nil
else
Spree::MenuItem.find(params[:new_parent_id])
diff --git a/backend/app/assets/javascripts/spree/backend/navigation/menu.es6 b/backend/app/assets/javascripts/spree/backend/navigation/menu.es6
index 0f3c82170c..98a5c58f4e 100644
--- a/backend/app/assets/javascripts/spree/backend/navigation/menu.es6
+++ b/backend/app/assets/javascripts/spree/backend/navigation/menu.es6
@@ -28,13 +28,19 @@ document.addEventListener('DOMContentLoaded', function() {
})
function handleMenuItemMove(evt, successCallback) {
- const movedItem = evt.item.dataset.itemId
- const newParentId = evt.to.dataset.parentId
- const newPosition = evt.newIndex
+ const data = {
+ moved_item_id: evt.item.dataset.itemId,
+ new_parent_id: evt.to.dataset.parentId || null,
+ new_position_idx: evt.newIndex
+ }
- fetch(Spree.routes.menus_items_api_v2 + `?moved_item_id=${movedItem}&new_parent_id=${newParentId}&new_position_idx=${newPosition}`, {
+ fetch(Spree.routes.menus_items_api_v2, {
method: 'PATCH',
- headers: Spree.apiV2Authentication()
+ headers: {
+ Authorization: 'Bearer' + OAUTH_TOKEN,
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(data)
})
.then(response => {
console.log(response);
diff --git a/core/app/models/awesome_nested_set/movable_decorator.rb b/core/app/models/awesome_nested_set/movable_decorator.rb
index 8e4387ed97..7ab731687d 100644
--- a/core/app/models/awesome_nested_set/movable_decorator.rb
+++ b/core/app/models/awesome_nested_set/movable_decorator.rb
@@ -22,7 +22,7 @@ module AwesomeNestedSet
# and we can skip moving the item to root.
move_to_root unless level == 0 && root?
- # Sort the positioninng of the item
+ # Sort the positioning of the item
# at root level based on its siblings.
my_position = siblings.to_a.index(self)
if my_position && my_position < index