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.

Update menu item to allow or disallow nesting.

Matthew Kennedybaffdcb6b38d
diff --git a/backend/app/views/spree/admin/menu_items/_form.html.erb b/backend/app/views/spree/admin/menu_items/_form.html.erb
index e7a4ce07b2..19c96695c1 100644
--- a/backend/app/views/spree/admin/menu_items/_form.html.erb
+++ b/backend/app/views/spree/admin/menu_items/_form.html.erb
@@ -11,11 +11,19 @@
<%= f.select(:item_type, Spree::MenuItem::ITEM_TYPE, {include_blank: false}, { class: 'select2' }) %>
<%= f.error_message_on :item_type %>
<% end %>
- </div>
- <div class="alert alert-info mx-3 mt-0">
+ <%= f.field_container :container do %>
+ <div class="custom-control custom-checkbox">
+ <%= f.check_box :container, class: 'custom-control-input' %>
+ <%= f.label :container, Spree.t('admin.navigation.allow_this_menu_item_to_contain_nested_menu_items'), class: 'custom-control-label' %>
+ <%= f.error_message_on :container %>
+ </div>
+ <% end %>
+
+ <div class="alert alert-info mt-3 mb-0">
<%= raw Spree.t('admin.navigation.menu_item_type_message') %>
</div>
+ </div>
</div>
</div>
@@ -37,7 +45,18 @@
<%= f.error_message_on :subtitle %>
<% end %>
- <!-- TODO: ADD LINK TO UPLOAD IMAGE / ICON HERE -->
+ <%= f.field_container :image_asset, class: ['form-group'] do %>
+ <% if @menu_item.image_asset.attached? && @menu_item.image_asset.variable? %>
+ <%= image_tag main_app.url_for(@menu_item.image_asset.variant(resize: '244x104>')) %>
+ <% elsif @menu_item.image_asset.attached? && @store.image_asset.image? %>
+ <%= image_tag main_app.url_for(@menu_item.image_asset) %>
+ <% end %>
+ <%= f.field_container :image_asset, class: ['form-group'] do %>
+ <%= f.label :image_asset, Spree.t(:image_asset) %><br>
+ <%= f.file_field :image_asset %>
+ <%= f.error_message_on :image_asset %>
+ <% end %>
+ <% end %>
</div>
</div>
</div>
diff --git a/backend/app/views/spree/admin/menu_items/_link_input.html.erb b/backend/app/views/spree/admin/menu_items/_link_input.html.erb
index d204511a17..af537053a5 100644
--- a/backend/app/views/spree/admin/menu_items/_link_input.html.erb
+++ b/backend/app/views/spree/admin/menu_items/_link_input.html.erb
@@ -4,5 +4,6 @@
<% elsif linked_resource == 'Home Page' %>
<%= render 'spree/admin/menu_items/link_inputs/home_page', f: f %>
<% else %>
-<% end %>
+ <%= render 'spree/admin/menu_items/link_inputs/search', linked_resource: linked_resource, f: f %>
+ <% end %>
</div>
diff --git a/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erb b/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erb
index 49b0261cac..9437dd56e8 100644
--- a/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erb
+++ b/backend/app/views/spree/admin/menu_items/link_inputs/_home_page.html.erb
@@ -1,3 +1,3 @@
<div class="alert alert-info mt-3">
- This link takes you to your stores home page.
+ <%= Spree.t('admin.navigation.this_link_takes_you_to_your_stores_home_page') %>
</div>
diff --git a/backend/app/views/spree/admin/menu_items/link_inputs/_search.html.erb b/backend/app/views/spree/admin/menu_items/link_inputs/_search.html.erb
new file mode 100644
index 0000000000..78e0b24cd1
--- /dev/null
+++ b/backend/app/views/spree/admin/menu_items/link_inputs/_search.html.erb
@@ -0,0 +1,5 @@
+ <%= f.field_container :url, class: ['form-group'] do %>
+ <%= f.label :url, Spree.t('seach') + ': ' +linked_resource %>
+ <%= f.text_field :url, class: 'form-control' %>
+ <%= f.error_message_on :url %>
+ <% end %>
diff --git a/core/app/models/spree/menu_item.rb b/core/app/models/spree/menu_item.rb
index 00b83266d7..23b7dfa284 100644
--- a/core/app/models/spree/menu_item.rb
+++ b/core/app/models/spree/menu_item.rb
@@ -4,6 +4,8 @@ module Spree
acts_as_nested_set
+ has_one_attached :image_asset
+
# Not frozen so they can be added to
ITEM_TYPE = %w[Link Promotion]
LINKED_RESOURCE_TYPE = []
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 97ec5cd4c2..2dd5beb2b6 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -575,6 +575,7 @@ en:
available_store_credit: User has %{amount} in Store Credit available.
navigation:
add_new_item: 'Add New Item'
+ allow_this_menu_item_to_contain_nested_menu_items: Allow this Menu Item to contain nested Menu Items
back_to_all_menus: Back To All Menus
menu_item_type: Menu Item Type
menu_item_basic_details: Basic Details
@@ -584,11 +585,12 @@ en:
new_menu_item: New Menu Item
item_type: Item Type
open_link_in_new_window: Open this link in a new window
- menu_item_type_message: "Set your <b>Menu Item Type</b>, for more information about using existing Types or adding custom Types
- <a href='https://guides.spreecommerce.org/user/configuration/configuring_geography.html#zones' target='_blank' class='alert-link'>click here</a> to see the documentation"
+ menu_item_type_message: "For more information about Menu Item Types and nesting Menu Items, visit the documentation by
+ <a href='https://guides.spreecommerce.org/user/configuration/configuring_geography.html#zones' target='_blank' class='alert-link'>clicking here</a>."
menus: Menus
menu_items: Menu Items
subtitle: Subtitle
+ this_link_takes_you_to_your_stores_home_page: This link takes you to your stores home page.
administration: Administration
advertise: Advertise
agree_to_privacy_policy: Agree to Privacy Policy
diff --git a/core/db/migrate/20210408092939_create_spree_menu_items.rb b/core/db/migrate/20210408092939_create_spree_menu_items.rb
index 424af8a55f..759b08b95d 100644
--- a/core/db/migrate/20210408092939_create_spree_menu_items.rb
+++ b/core/db/migrate/20210408092939_create_spree_menu_items.rb
@@ -6,6 +6,7 @@ class CreateSpreeMenuItems < ActiveRecord::Migration[6.0]
t.column :url, :string
t.column :new_window, :boolean, default: false
t.column :item_type, :string
+ t.column :container, :boolean, default: false
t.column :linked_resource_type, :string, default: 'URL'
t.column :linked_resource_id, :integer
t.column :parent_id, :integer
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 8f355e3401..b6afcd1141 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -7,6 +7,7 @@ module Spree
:image_attributes,
:inventory_unit_attributes,
:line_item_attributes,
+ :menu_item_attributes,
:option_type_attributes,
:option_value_attributes,
:payment_attributes,
@@ -51,6 +52,10 @@ module Spree
@@line_item_attributes = [:id, :variant_id, :quantity]
+ @@menu_attributes = [:name, stores: []]
+
+ @@menu_item_attributes = [:name, :url, :image_asset]
+
@@option_type_attributes = [:name, :presentation, :option_values_attributes]
@@option_value_attributes = [:name, :presentation]