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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix MenuItems Tree.
Matthew Kennedyb4d98c4c7e10
diff --git a/backend/app/controllers/spree/admin/menus_controller.rb b/backend/app/controllers/spree/admin/menus_controller.rbindex 4c55368d89..28ab2d169b 100644--- a/backend/app/controllers/spree/admin/menus_controller.rb+++ b/backend/app/controllers/spree/admin/menus_controller.rb@@ -2,6 +2,7 @@ module Spreemodule Adminclass MenusController < ResourceControllerbefore_action :load_data+ before_action :load_menu_items_ordered, only: :editdef index; end@@ -11,9 +12,15 @@ module Spreespree.edit_admin_menu_path(@menu)end+ private+def load_data@stores = Spree::Store.allend++ def load_menu_items_ordered+ @menu_items_in_order = @menu.menu_items.order('lft ASC')+ endendendenddiff --git a/backend/app/helpers/spree/admin/menu_helper.rb b/backend/app/helpers/spree/admin/menu_helper.rbindex 03d938144b..6829cc9a13 100644--- a/backend/app/helpers/spree/admin/menu_helper.rb+++ b/backend/app/helpers/spree/admin/menu_helper.rb@@ -19,10 +19,16 @@ module Spreeenddef menu_item_that_accepts_nested_items(menu, item)- decendents = build_menu_item(menu, item.children[0]) unless item.leaf?+ decendents = []++ unless item.leaf?+ item.children.each do |x|+ decendents << build_menu_item(menu, x) unless item.leaf?+ end+ endinfo_row = menu_item_bar(menu, item)- sub_menu_container = content_tag(:div, decendents, class: 'menu-container', data: { parent_id: item.id })+ sub_menu_container = content_tag(:div, raw(decendents.join), class: 'menu-container', data: { parent_id: item.id })content_tag(:div, info_row + sub_menu_container, class: 'menu-item menu-container-item dragable', data: { item_id: item.id })enddiff --git a/backend/app/views/spree/admin/menu_items/_form.html.erb b/backend/app/views/spree/admin/menu_items/_form.html.erbindex 67821854b2..f38ffccb26 100644--- a/backend/app/views/spree/admin/menu_items/_form.html.erb+++ b/backend/app/views/spree/admin/menu_items/_form.html.erb@@ -15,6 +15,9 @@<div class="alert alert-info mt-3 mb-0"><%= raw Spree.t('admin.navigation.menu_item_type_message') %></div>++ <hr>+ <%= f.select :parent_id, nested_set_options(Spree::MenuItem, @menu_item) {|i| "#{'-' * i.level} #{i.name}" }, {include_blank: true}, {class: 'select2-clear'} %></div></div></div>diff --git a/backend/app/views/spree/admin/menus/edit.html.erb b/backend/app/views/spree/admin/menus/edit.html.erbindex 7bd92d5f5a..655a498fb9 100644--- a/backend/app/views/spree/admin/menus/edit.html.erb+++ b/backend/app/views/spree/admin/menus/edit.html.erb@@ -38,7 +38,7 @@<div class="card-body p-0 bg-light"><div id="primaryMenuContainer" class="menu-container">- <% nested_set_options(@menu.menu_items) do |item| %>+ <% nested_set_options(@menu_items_in_order) do |item| %><% if item.root? %><%= build_menu_item(@menu, item) %><% end %>