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.

Add formatter to output stores unique name in select.

Matthew Kennedy59a3dece89dd
diff --git a/backend/app/helpers/spree/admin/base_helper.rb b/backend/app/helpers/spree/admin/base_helper.rb
index 250cd0cedb..fec3072ee1 100644
--- a/backend/app/helpers/spree/admin/base_helper.rb
+++ b/backend/app/helpers/spree/admin/base_helper.rb
@@ -218,6 +218,16 @@ module Spree
end
end
+ def stores_formatted_for_select
+ formatted_stores = []
+
+ @stores.each do |store|
+ formatted_stores << ["#{store.name} (#{store.code})", store.id]
+ end
+
+ formatted_stores
+ end
+
def select2_local_fallback
stripped_locale = I18n.locale.to_s.split('-').first
diff --git a/backend/app/views/spree/admin/menus/index.html.erb b/backend/app/views/spree/admin/menus/index.html.erb
index fe35c0cdc0..f5adda1daf 100644
--- a/backend/app/views/spree/admin/menus/index.html.erb
+++ b/backend/app/views/spree/admin/menus/index.html.erb
@@ -35,7 +35,7 @@
<div class="col-12 col-lg-6">
<div class="form-group">
<%= label_tag :q_store_id_in, Spree.t(:store) %>
- <%= f.select :store_id_in, @stores.pluck(:code, :id), { include_blank: true }, class: 'select2-clear js-filterable' %>
+ <%= f.select :store_id_in, stores_formatted_for_select, { include_blank: true }, class: 'select2-clear js-filterable' %>
</div>
</div>
</div>
diff --git a/backend/spec/features/admin/menus/index_menu_spec.rb b/backend/spec/features/admin/menus/index_menu_spec.rb
index 563c9f78db..ad5ae0459d 100644
--- a/backend/spec/features/admin/menus/index_menu_spec.rb
+++ b/backend/spec/features/admin/menus/index_menu_spec.rb
@@ -90,7 +90,7 @@ describe 'Menus Index', type: :feature do
it 'is able to filter by store' do
click_on 'Filter'
- select2 store_2.code, from: 'Store'
+ select2 store_2.unique_name, from: 'Store'
click_on 'Search'
expect(page).to have_text 'MA'