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
Find default menu
Matthew Kennedyeef11bf71c71
diff --git a/core/app/models/spree/menu.rb b/core/app/models/spree/menu.rbindex 89154371ee..4cada59c24 100644--- a/core/app/models/spree/menu.rb+++ b/core/app/models/spree/menu.rb@@ -30,8 +30,10 @@ module Spreeself.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.rootdiff --git a/core/spec/models/spree/menu_spec.rb b/core/spec/models/spree/menu_spec.rbindex 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 docontext 'when the I18n.locale is set to a none default laguage and a menu is available' doit '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')endendcontext 'when the I18n.locale is set to a none default laguage and a menu is not available' doit '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')endendcontext 'when the I18n.locale is set to the default laguage and a menu is available' doit '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')endendenddiff --git a/frontend/app/helpers/spree/navigation_helper.rb b/frontend/app/helpers/spree/navigation_helper.rbindex 9d417377d7..aa138e8e8b 100644--- a/frontend/app/helpers/spree/navigation_helper.rb+++ b/frontend/app/helpers/spree/navigation_helper.rb@@ -57,7 +57,7 @@ module Spreemethod_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)endend