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.

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.rb
index 7a403fe539..5a71bc7f60 100644
--- a/core/app/models/spree/option_value.rb
+++ b/core/app/models/spree/option_value.rb
@@ -62,9 +62,9 @@ module Spree
delegate :name, :presentation, to: :option_type, prefix: true, allow_nil: true
def 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
}
end
diff --git a/core/spec/models/spree/option_value_spec.rb b/core/spec/models/spree/option_value_spec.rb
index 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 do
end
end
+ 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' do
let!(:option_value) { create(:option_value, name: 'red', presentation: 'Red') }