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
Fixed OptionType/OptionValue `label` alias translations (#13882)
Damian Legawiecc94a083ae310
diff --git a/spree/core/app/models/spree/option_type.rb b/spree/core/app/models/spree/option_type.rbindex bcbb41aa0e..6146313d03 100644--- a/spree/core/app/models/spree/option_type.rb+++ b/spree/core/app/models/spree/option_type.rb@@ -35,7 +35,15 @@ module Spreehas_many :prototypes, through: :option_type_prototypes, class_name: 'Spree::Prototype'# 5.5 API naming bridge (DB column rename in 6.0)- alias_attribute :label, :presentation+ # NOTE: alias_attribute bypasses Mobility's locale-aware reader/writer,+ # so we define explicit delegating methods instead.+ def label(*args)+ presentation(*args)+ end++ def label=(value)+ self.presentation = value+ end## Validationsdiff --git a/spree/core/app/models/spree/option_value.rb b/spree/core/app/models/spree/option_value.rbindex b593ddad69..eecbc77727 100644--- a/spree/core/app/models/spree/option_value.rb+++ b/spree/core/app/models/spree/option_value.rb@@ -34,7 +34,15 @@ module Spreehas_many :products, through: :variants, class_name: 'Spree::Product'# 5.5 API naming bridge (DB column rename in 6.0)- alias_attribute :label, :presentation+ # NOTE: alias_attribute bypasses Mobility's locale-aware reader/writer,+ # so we define explicit delegating methods instead.+ def label(*args)+ presentation(*args)+ end++ def label=(value)+ self.presentation = value+ end## Validationsdiff --git a/spree/core/spec/models/spree/option_type_spec.rb b/spree/core/spec/models/spree/option_type_spec.rbindex c3e837fb00..e05f9fdf37 100644--- a/spree/core/spec/models/spree/option_type_spec.rb+++ b/spree/core/spec/models/spree/option_type_spec.rb@@ -37,6 +37,26 @@ describe Spree::OptionType, type: :model doexpect(option_type_pl_translation.presentation).to eq('Rozmiar')end+ describe '#label alias' do+ it 'returns the translated presentation for the current locale' do+ expect(option_type.label).to eq('Size')+ end++ it 'returns the translated presentation for a different locale' do+ Mobility.with_locale(:pl) do+ expect(option_type.label).to eq('Rozmiar')+ end+ end++ it 'sets the translated presentation via label=' do+ Mobility.with_locale(:pl) do+ option_type.label = 'Nowy Rozmiar'+ option_type.save!+ expect(option_type.presentation).to eq('Nowy Rozmiar')+ end+ end+ end+context 'with always_use_translations enabled' dobefore doSpree::Config.always_use_translations = truediff --git a/spree/core/spec/models/spree/option_value_spec.rb b/spree/core/spec/models/spree/option_value_spec.rbindex 423bdb37a2..737ba59298 100644--- a/spree/core/spec/models/spree/option_value_spec.rb+++ b/spree/core/spec/models/spree/option_value_spec.rb@@ -115,5 +115,25 @@ describe Spree::OptionValue, type: :model doexpect(option_value_pl_translation).to be_presentexpect(option_value_pl_translation.presentation).to eq('Czerwony')end++ describe '#label alias' do+ it 'returns the translated presentation for the current locale' do+ expect(option_value.label).to eq('Red')+ end++ it 'returns the translated presentation for a different locale' do+ Mobility.with_locale(:pl) do+ expect(option_value.label).to eq('Czerwony')+ end+ end++ it 'sets the translated presentation via label=' do+ Mobility.with_locale(:pl) do+ option_value.label = 'Nowy Czerwony'+ option_value.save!+ expect(option_value.presentation).to eq('Nowy Czerwony')+ end+ end+ endendend