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
Cleanup/fix how we translate option types/values/properties
Damian Legawiecf1f1fb966239
diff --git a/admin/app/controllers/spree/admin/products_controller.rb b/admin/app/controllers/spree/admin/products_controller.rbindex 5a48fecf3b..e410f98ccc 100644--- a/admin/app/controllers/spree/admin/products_controller.rb+++ b/admin/app/controllers/spree/admin/products_controller.rb@@ -173,17 +173,17 @@ module Spreejoins(option_type: :product_option_types).includes(option_type: :option_values).merge(@product.product_option_types).- reorder('spree_product_option_types.position').+ reorder("#{Spree::ProductOptionType.table_name}.position").uniq.group_by(&:option_type).each_with_index do |option, index|option_type, option_values = option@product_options[option_type.id.to_s] = {name: option_type.presentation,position: index + 1,- values: option_values.pluck(:name, :presentation).uniq.map { |name, presentation| { value: name, text: presentation } }+ values: option_values.map { |ov| { value: ov.name, text: ov.presentation } }.uniq}- @product_available_options[option_type.id.to_s] = option_type.option_values.pluck(:name, :presentation).uniq.map { |name, presentation| { id: name, name: presentation } }+ @product_available_options[option_type.id.to_s] = option_type.option_values.map { |ov| { id: ov.name, name: ov.presentation } }.uniqend@product_stock = {}diff --git a/core/app/models/concerns/spree/parameterizable_name.rb b/core/app/models/concerns/spree/parameterizable_name.rbindex 1aa24e36cc..9464758d5a 100644--- a/core/app/models/concerns/spree/parameterizable_name.rb+++ b/core/app/models/concerns/spree/parameterizable_name.rb@@ -3,6 +3,8 @@ module Spreeextend ActiveSupport::Concernincluded do+ auto_strip_attributes :name, :presentation+## Callbacks#diff --git a/core/app/models/spree/option_type.rb b/core/app/models/spree/option_type.rbindex c6ee3a2879..2a43ae729c 100644--- a/core/app/models/spree/option_type.rb+++ b/core/app/models/spree/option_type.rb@@ -10,12 +10,11 @@ module Spreeinclude Spree::Webhooks::HasWebhooksend- if Spree.always_use_translations?- TRANSLATABLE_FIELDS = %i[name presentation].freeze- translates(*TRANSLATABLE_FIELDS)- else- TRANSLATABLE_FIELDS = %i[presentation].freeze- translates(*TRANSLATABLE_FIELDS, column_fallback: true)+ TRANSLATABLE_FIELDS = %i[presentation].freeze+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)++ self::Translation.class_eval do+ auto_strip_attributes :presentationend#@@ -23,7 +22,6 @@ module Spree#self.whitelisted_ransackable_scopes = %w[search_by_name]acts_as_list- auto_strip_attributes :name, :presentation## Associationsdiff --git a/core/app/models/spree/option_value.rb b/core/app/models/spree/option_value.rbindex fb9607579e..692a6af6d4 100644--- a/core/app/models/spree/option_value.rb+++ b/core/app/models/spree/option_value.rb@@ -7,19 +7,17 @@ module Spreeinclude Spree::Webhooks::HasWebhooksend- if Spree.always_use_translations?- TRANSLATABLE_FIELDS = %i[name presentation].freeze- translates(*TRANSLATABLE_FIELDS)- else- TRANSLATABLE_FIELDS = %i[presentation].freeze- translates(*TRANSLATABLE_FIELDS, column_fallback: true)+ TRANSLATABLE_FIELDS = %i[presentation].freeze+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)++ self::Translation.class_eval do+ auto_strip_attributes :presentationend## Magic methods#acts_as_list scope: :option_type- auto_strip_attributes :name, :presentationself.whitelisted_ransackable_attributes = ['presentation']#@@ -61,11 +59,12 @@ module Spreedelegate :name, :presentation, to: :option_type, prefix: true, allow_nil: true+ # Using map here instead of pluck, as these values are translatable via Mobility gemdef self.to_tom_select_json- all.pluck(:name, :presentation).map do |name, presentation|+ all.map do |ov|{- id: name,- name: presentation+ id: ov.name,+ name: ov.presentation}endenddiff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rbindex e9d6424b07..5d06fa7f13 100644--- a/core/app/models/spree/property.rb+++ b/core/app/models/spree/property.rb@@ -9,19 +9,13 @@ module Spreeinclude Spree::Webhooks::HasWebhooksend- if Spree.always_use_translations?- TRANSLATABLE_FIELDS = %i[name presentation].freeze- translates(*TRANSLATABLE_FIELDS)- else- TRANSLATABLE_FIELDS = %i[presentation].freeze- translates(*TRANSLATABLE_FIELDS, column_fallback: true)- end+ TRANSLATABLE_FIELDS = %i[presentation].freeze+ translates(*TRANSLATABLE_FIELDS, column_fallback: !Spree.always_use_translations?)self::Translation.class_eval doauto_strip_attributes :presentationend- auto_strip_attributes :name, :presentationacts_as_listhas_many :property_prototypes, class_name: 'Spree::PropertyPrototype'diff --git a/core/app/services/spree/products/prepare_nested_attributes.rb b/core/app/services/spree/products/prepare_nested_attributes.rbindex 03a8d4abee..df788942ea 100644--- a/core/app/services/spree/products/prepare_nested_attributes.rb+++ b/core/app/services/spree/products/prepare_nested_attributes.rb@@ -141,10 +141,10 @@ module Spreeopt[:option_value_name]elseopt[:option_value_presentation].parameterize- end+ end.stripoption_value = option_type.option_values.where(name: option_value_identificator).first_or_initialize do |o|- o.name = o.presentation = opt[:option_value_presentation]+ o.presentation = opt[:option_value_presentation]o.save!end