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
Set `name` as `id` in tom select for option values (#12826)
Damian Kaczmarczyk12bce10e84e3
diff --git a/core/app/models/spree/option_value.rb b/core/app/models/spree/option_value.rbindex 7a403fe539..5a71bc7f60 100644--- a/core/app/models/spree/option_value.rb+++ b/core/app/models/spree/option_value.rb@@ -62,9 +62,9 @@ module Spreedelegate :name, :presentation, to: :option_type, prefix: true, allow_nil: truedef self.to_tom_select_json- all.pluck(:id, :presentation).map do |id, presentation|+ all.pluck(:name, :presentation).map do |name, presentation|{- id: id,+ id: name,name: presentation}enddiff --git a/core/spec/models/spree/option_value_spec.rb b/core/spec/models/spree/option_value_spec.rbindex ef40231528..8ac96d3d45 100644--- a/core/spec/models/spree/option_value_spec.rb+++ b/core/spec/models/spree/option_value_spec.rb@@ -44,6 +44,16 @@ describe Spree::OptionValue, type: :model doendend+ describe '.to_tom_select_json' do+ let!(:option_value) { create(:option_value, name: 'red', presentation: 'Red') }+ let!(:option_value2) { create(:option_value, name: 'blue', presentation: 'Blue') }+ let!(:option_value3) { create(:option_value, name: 'green', presentation: 'Green') }++ it 'returns the option values in the correct format' do+ expect(Spree::OptionValue.to_tom_select_json).to eq([{ id: 'red', name: 'Red' }, { id: 'blue', name: 'Blue' }, { id: 'green', name: 'Green' }])+ end+ end+describe 'translations' dolet!(:option_value) { create(:option_value, name: 'red', presentation: 'Red') }