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.

Find default menu

Matthew Kennedyeef11bf71c71
diff --git a/core/app/models/spree/menu.rb b/core/app/models/spree/menu.rb
index 89154371ee..4cada59c24 100644
--- a/core/app/models/spree/menu.rb
+++ b/core/app/models/spree/menu.rb
@@ -30,8 +30,10 @@ module Spree
self.whitelisted_ransackable_attributes = %w[name location locale store_id]
MENU_LOCATIONS_PARAMETERIZED.each do |location_name|
- define_singleton_method("for_#{location_name}") do |locale, store|
- menu = find_by(location: location_name, locale: locale.to_s) || store.default_menu(location_name)
+ define_singleton_method("for_#{location_name}") do |locale, default_locale|
+ menu = find_by(location: location_name, locale: locale.to_s) ||
+ find_by(location: location_name, locale: default_locale.to_s) ||
+ find_by(location: location_name)
if menu.present?
menu.root
diff --git a/core/spec/models/spree/menu_spec.rb b/core/spec/models/spree/menu_spec.rb
index e35f50aa9a..ba48aa9d88 100644
--- a/core/spec/models/spree/menu_spec.rb
+++ b/core/spec/models/spree/menu_spec.rb
@@ -38,19 +38,19 @@ describe Spree::Menu, type: :model do
context 'when the I18n.locale is set to a none default laguage and a menu is available' do
it 'returns a menu in the correct locale' do
- expect(described_class.for_header('en', fr_store).name).to eql('Main Menu EN')
+ expect(described_class.for_header('en', fr_store.default_locale).name).to eql('Main Menu EN')
end
end
context 'when the I18n.locale is set to a none default laguage and a menu is not available' do
it 'returns a menu in the current stores default locale if one is available' do
- expect(described_class.for_header('de',fr_store).name).to eql('Main Menu FR')
+ expect(described_class.for_header('de',fr_store.default_locale).name).to eql('Main Menu FR')
end
end
context 'when the I18n.locale is set to the default laguage and a menu is available' do
it 'returns a the default menu' do
- expect(described_class.for_header('fr', fr_store).name).to eql('Main Menu FR')
+ expect(described_class.for_header('fr', fr_store.default_locale).name).to eql('Main Menu FR')
end
end
end
diff --git a/frontend/app/helpers/spree/navigation_helper.rb b/frontend/app/helpers/spree/navigation_helper.rb
index 9d417377d7..aa138e8e8b 100644
--- a/frontend/app/helpers/spree/navigation_helper.rb
+++ b/frontend/app/helpers/spree/navigation_helper.rb
@@ -57,7 +57,7 @@ module Spree
method_name = "for_#{location}"
if available_menus.respond_to?(method_name) && Spree::Menu::MENU_LOCATIONS_PARAMETERIZED.include?(location)
- available_menus.send(method_name, I18n.locale, current_store)
+ available_menus.send(method_name, I18n.locale, store_locale)
end
end