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
Add code? to menu_item.rb
Matthew Kennedy1cc02afa1266
diff --git a/core/app/models/spree/menu_item.rb b/core/app/models/spree/menu_item.rbindex 1f14b79298..60f71f1c8f 100644--- a/core/app/models/spree/menu_item.rb+++ b/core/app/models/spree/menu_item.rb@@ -36,6 +36,14 @@ module Spreeitem_type == 'Container'end+ def code?(item_code = nil)+ if item_code+ code == item_code+ else+ code.present?+ end+ end+privatedef build_pathdiff --git a/core/spec/models/spree/menu_item_spec.rb b/core/spec/models/spree/menu_item_spec.rbindex 74493a9df7..fbd0acaa19 100644--- a/core/spec/models/spree/menu_item_spec.rb+++ b/core/spec/models/spree/menu_item_spec.rb@@ -36,7 +36,7 @@ describe Spree::MenuItem, type: :model doendend- describe '.reset_link_attributes from URL to Taxon' do+ describe '#reset_link_attributes from URL to Taxon' dolet(:i_a) docreate(:menu_item, name: 'Home', item_type: 'Link', menu: menu,parent: menu.root, linked_resource_type: 'URL', destination: 'http://somewhere.com', new_window: true, linked_resource_id: 5)@@ -68,7 +68,32 @@ describe Spree::MenuItem, type: :model doendend- describe '.reset_link_attributes from URL to Home Page' do+ describe '#code?' do+ let(:coded_item){ create(:menu_item, name: 'Link 1', item_type: 'Container', menu: menu, code: 'some-code') }+ let(:not_coded_item) { create(:menu_item, name: 'Home', item_type: 'Link', menu: menu) }++ it 'returns true when the menu item has a matching code' do+ expect(coded_item.code?('some-code')).to be true+ end++ it 'returns false when the menu item has a code but the code does not match' do+ expect(coded_item.code?('Some-code')).to be false+ end++ it 'returns false when the menu item has no code' do+ expect(not_coded_item.code?('some-code')).to be false+ end++ it 'returns true if no args are passed, and the item has a code' do+ expect(coded_item.code?).to be true+ end++ it 'returns false if no args are passed, and the item has no code' do+ expect(not_coded_item.code?).to be false+ end+ end++ describe '#reset_link_attributes from URL to Home Page' dolet(:i_b) docreate(:menu_item, name: 'Home', item_type: 'Link', menu: menu,parent: menu.root, linked_resource_type: 'URL', destination: 'http://somewhere.com', new_window: true, linked_resource_id: 5)@@ -83,7 +108,7 @@ describe Spree::MenuItem, type: :model doendend- describe '.reset_link_attributes from Link to Container' do+ describe '#reset_link_attributes from Link to Container' dolet(:i_c) docreate(:menu_item, name: 'Home', item_type: 'Link', menu: menu,parent: menu.root, linked_resource_type: 'URL', destination: 'http://somewhere.com', new_window: true, linked_resource_id: 5)@@ -141,7 +166,7 @@ describe Spree::MenuItem, type: :model doendend- describe '.paremeterize_code' do+ describe '#paremeterize_code' dolet(:item) { create(:menu_item, name: 'URL', item_type: 'Link', menu: menu, parent: menu.root, linked_resource_type: 'URL', code: 'My Fantastic Code') }it 'paramatizes a code when one is given' do@@ -149,7 +174,7 @@ describe Spree::MenuItem, type: :model doendend- describe '.ensure_item_belongs_to_root' do+ describe '#ensure_item_belongs_to_root' dolet(:item_x) { create(:menu_item, name: 'URL', item_type: 'Link', menu: menu, linked_resource_type: 'URL', code: 'My Fantastic Code') }it 'Sets new items parent_id to root.id' dodiff --git a/frontend/app/views/spree/shared/_main_nav_bar.html.erb b/frontend/app/views/spree/shared/_main_nav_bar.html.erbindex 2f33c1f410..a58f390f98 100644--- a/frontend/app/views/spree/shared/_main_nav_bar.html.erb+++ b/frontend/app/views/spree/shared/_main_nav_bar.html.erb@@ -1,7 +1,4 @@<% if spree_menu.present? %>- <% category = 'category' %>- <% promo = 'promo' %>-<div class="h-100" role="navigation" aria-label="<%= Spree.t('nav_bar.desktop') %>"><ul class="nav h-100 main-nav-bar"><% spree_menu.children.each do |parent| %>@@ -23,7 +20,7 @@<% parent.children.each do |child| %><!-- Categories -->- <% if child.container? && child.code == category %>+ <% if child.container? && child.code?('category') %><div class="category-links my-4 mx-2"><div class="category-links-header text-uppercase"><%= child.name %>@@ -41,7 +38,7 @@<% end %><!-- Promos -->- <% if child.container? && child.code == promo %>+ <% if child.container? && child.code?('promo') %><% if child.children.present? %><% child.children.each do |promo_banner| %><%= spree_nav_link_tag(promo_banner, { class: "dropdown-item" }) do %>diff --git a/frontend/app/views/spree/shared/_mobile_navigation.html.erb b/frontend/app/views/spree/shared/_mobile_navigation.html.erbindex 80ac1af841..07ea1b9088 100644--- a/frontend/app/views/spree/shared/_mobile_navigation.html.erb+++ b/frontend/app/views/spree/shared/_mobile_navigation.html.erb@@ -39,7 +39,7 @@</li><% parent.children.each do |child| %>- <% if child.code == 'category' && child.item_type == 'Container' %>+ <% if child.container? && child.code?('category') %><li class="text-muted mt-2"><%= child.name %></li><% if child.children.present? %><% child.children.each do |category_link| %>