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
Use column_fallback plugin for storing default locale's translations in original columns (#12040)
Łukasz Adamczykdd13bebbed2d
diff --git a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rbindex 3d36b83591..2b5e0d875a 100644--- a/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb+++ b/api/spec/models/concerns/spree/webhooks/has_webhooks_spec.rb@@ -88,10 +88,7 @@ describe Spree::Webhooks::HasWebhooks docontext 'when only timestamps change' dolet(:event_name) { 'product.update' }- before {- product.save- product.translations.first.save- }+ before { product.save! }context 'on created_at change' doit do@@ -104,7 +101,7 @@ describe Spree::Webhooks::HasWebhooks docontext 'on updated_at change' doit doexpect do- product.update(updated_at: Date.yesterday)+ product.update!(updated_at: Date.yesterday)end.not_to emit_webhook_event(event_name)endenddiff --git a/api/spec/requests/spree/api/v2/storefront/products_spec.rb b/api/spec/requests/spree/api/v2/storefront/products_spec.rbindex 4e51dd9851..6e3e2b9548 100644--- a/api/spec/requests/spree/api/v2/storefront/products_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/products_spec.rb@@ -24,8 +24,13 @@ describe 'API V2 Storefront Products Spec', type: :request dolet!(:product_property) { create(:product_property, property: new_property, product: product_with_property, value: 'Some Value') }let!(:product_property2) { create(:product_property, property: property, product: product_with_property, value: 'Some Value 2') }+ # We need to make sure that the default locale is reset before and after every test case+ before do+ I18n.default_locale = :en+ Spree::Api::Config[:api_v2_per_page_limit] = 4+ end- before { Spree::Api::Config[:api_v2_per_page_limit] = 4 }+ after { I18n.locale = :en }describe 'products#index' docontext 'with no params' do@@ -170,7 +175,8 @@ describe 'API V2 Storefront Products Spec', type: :request do# generate translations for default storelet!(:store) dodefault_store = Spree::Store.default- default_store.default_locale = 'pl'+ default_store.default_locale = 'en'+ default_store.supported_locales = 'en,pl'Mobility.with_locale(:pl) dodefault_store.name = 'Spree Sklep Testowy'@@ -179,23 +185,55 @@ describe 'API V2 Storefront Products Spec', type: :request dodefault_store.new_order_notifications_email = '[email protected]'end+ default_store.savedefault_storeend+# generate translated resources- let!(:option_type_pl_locale) { Mobility.with_locale(:pl) { create(:option_type) } }- let!(:option_value_pl_locale) { Mobility.with_locale(:pl) { create(:option_value, option_type: option_type_pl_locale) } }- let!(:product_pl_locale) { Mobility.with_locale(:pl) { create(:product, name: 'Produkt Superowy', option_types: [option_type_pl_locale], stores: [store]) } }- let!(:variant_pl_locale) { Mobility.with_locale(:pl) { create(:variant, product: product_pl_locale, option_values: [option_value_pl_locale]) } }+ let!(:option_type_localized) do+ option_type = create(:option_type)+ presentation = option_type.presentation++ Mobility.with_locale(:pl) { option_type.update!(presentation: "#{presentation} PL") }++ option_type+ end++ let!(:option_value_localized) do+ option_value = create(:option_value, option_type: option_type_localized)+ presentation = option_value.presentation++ Mobility.with_locale(:pl) { option_value.update!(presentation: "#{presentation} PL") }++ option_value+ end++ let!(:product_localized) do+ product = create(:product, option_types: [option_type_localized], stores: [store])+ Mobility.with_locale(:pl) { product.update!(name: 'Produkt Superowy') }++ product+ end++ let!(:variant_localized) { create(:variant, product: product_localized, option_values: [option_value_localized]) }before do- store.update_column(:supported_locales, 'en,pl')- get "/api/v2/storefront/products?filter[options][#{option_type_pl_locale.name(locale: :pl)}]=#{option_value_pl_locale.name(locale: :pl)}&include=option_types,variants.option_values&locale=pl"+ get "/api/v2/storefront/products?filter[options][#{option_type_localized.name}]=#{option_value_localized.name}&include=option_types,variants.option_values&locale=pl"endit 'returns products with specified options in polish' do- expect(json_response['data'].first).to have_id(product_pl_locale.id.to_s)- expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:name).with_value(option_type_pl_locale.name(locale: :pl))))- expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:name).with_value(option_value_pl_locale.name(locale: :pl))))+ expect(json_response['data'].first).to have_id(product_localized.id.to_s)+ expect(json_response['data'].first).to have_attribute(:name).with_value('Produkt Superowy')+ expect(json_response['data'].first).to have_attribute(:localized_slugs).with_value(+ 'en' => product_localized.slug_en,+ 'pl' => product_localized.slug_pl+ )++ expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:name).with_value(option_type_localized.name)))+ expect(json_response['included']).to include(have_type('option_type').and(have_attribute(:presentation).with_value(option_type_localized.presentation_pl)))++ expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:name).with_value(option_value_localized.name)))+ expect(json_response['included']).to include(have_type('option_value').and(have_attribute(:presentation).with_value(option_value_localized.presentation_pl)))endendend@@ -396,29 +434,58 @@ describe 'API V2 Storefront Products Spec', type: :request doendcontext 'sorting by name' do+ before { store.update_column(:supported_locales, 'en,pl') }+ after { I18n.locale = :en }+context 'A-Z' do- before { get '/api/v2/storefront/products?sort=name' }+ let(:request_path) { '/api/v2/storefront/products?sort=name' }++ before { get request_path }it_behaves_like 'returns 200 HTTP status'it 'returns products sorted by name' doexpect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.i18n.available- .select("#{Spree::Product.table_name}.*, #{Spree::Product::Translation.table_name}_en.name")- .order(:name).map(&:id).map(&:to_s)+ expect(json_response['data'].pluck(:id)).to eq store.products.i18n.available.order(:name).map(&:id).map(&:to_s)+ end++ context 'when using another locale' do+ let(:request_path) { '/api/v2/storefront/products?sort=name&locale=pl' }++ it_behaves_like 'returns 200 HTTP status'++ it 'returns products sorted by name' do+ expect(json_response['data'].count).to eq store.products.available.count+ expect(json_response['data'].pluck(:id)).to eq store.products.i18n.available+ .select("#{Spree::Product.table_name}.*, #{Spree::Product::Translation.table_name}_pl.name")+ .order(:name).map(&:id).map(&:to_s)+ endendendcontext 'Z-A' do- before { get '/api/v2/storefront/products?sort=-name' }+ let(:request_path) { '/api/v2/storefront/products?sort=-name' }++ before { get request_path }it_behaves_like 'returns 200 HTTP status'it 'returns products sorted by name with descending order' doexpect(json_response['data'].count).to eq store.products.available.count- expect(json_response['data'].pluck(:id)).to eq store.products.available- .select("#{Spree::Product.table_name}.*, #{Spree::Product::Translation.table_name}_en.name")- .order(name: :desc).map(&:id).map(&:to_s)+ expect(json_response['data'].pluck(:id)).to eq store.products.available.order(name: :desc).map(&:id).map(&:to_s)+ end++ context 'when using another locale' do+ let(:request_path) { '/api/v2/storefront/products?sort=-name&locale=pl' }++ it_behaves_like 'returns 200 HTTP status'++ it 'returns products sorted by name' do+ expect(json_response['data'].count).to eq store.products.available.count+ expect(json_response['data'].pluck(:id)).to eq store.products.available+ .select("#{Spree::Product.table_name}.*, #{Spree::Product::Translation.table_name}_pl.name")+ .order(name: :desc).map(&:id).map(&:to_s)+ endendendenddiff --git a/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb b/api/spec/requests/spree/api/v2/storefront/taxons_spec.rbindex ed2e618292..5b299f5982 100644--- a/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb+++ b/api/spec/requests/spree/api/v2/storefront/taxons_spec.rb@@ -8,7 +8,12 @@ describe 'Taxons Spec', type: :request dolet(:store2) { create(:store)}let!(:taxonomy2) { create(:taxonomy, store: store2) }- before { Spree::Api::Config[:api_v2_per_page_limit] = 2 }+ before do+ default_store.update_column(:supported_locales, 'en,pl,es')+ Spree::Api::Config[:api_v2_per_page_limit] = 2+ end++ after { I18n.locale = :en }shared_examples 'returns valid taxon resource JSON' doit 'returns a valid taxon resource JSON response' do@@ -69,7 +74,21 @@ describe 'Taxons Spec', type: :request dolet!(:taxonomy_3) { create(:taxonomy, store: taxonomy.store) }let!(:taxon_3) { create(:taxon, taxonomy: taxonomy_3, parent: taxonomy_3.root) }- before { get "/api/v2/storefront/taxons?filter[parent_permalink]=#{taxonomy.root.permalink}" }+ let(:request_path) { "/api/v2/storefront/taxons?filter[parent_permalink]=#{taxonomy.root.permalink}" }++ before do+ taxonomy_root_name = taxonomy.root.name+ taxon_1_name = taxons[0].name+ taxon_2_name = taxons[1].name++ Mobility.with_locale(:pl) do+ taxonomy.root.update!(name: "#{taxonomy_root_name}_pl")+ taxons[0].update!(name: "#{taxon_1_name}_pl")+ taxons[1].update!(name: "#{taxon_2_name}_pl")+ end++ get request_path+ endit_behaves_like 'returns 200 HTTP status'@@ -78,6 +97,22 @@ describe 'Taxons Spec', type: :request doexpect(json_response['data'][0]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')expect(json_response['data'][1]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')end++ context 'with another locale' do+ let(:request_path) { "/api/v2/storefront/taxons?filter[parent_permalink]=#{taxonomy.root.permalink_pl}&locale=pl" }++ it_behaves_like 'returns 200 HTTP status'++ it 'returns children taxons by parent' do+ expect(json_response['data'].size).to eq(2)++ expect(json_response['data'][0]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')+ expect(json_response['data'][1]).to have_relationship(:parent).with_data('id' => taxonomy.root.id.to_s, 'type' => 'taxon')++ expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:name).with_value(taxons[0].name_pl)))+ expect(json_response['data']).to include(have_type('taxon').and(have_attribute(:name).with_value(taxons[1].name_pl)))+ end+ endendcontext 'by taxonomy' dodiff --git a/core/app/finders/spree/taxons/find.rb b/core/app/finders/spree/taxons/find.rbindex b13da11820..fd4335aab7 100644--- a/core/app/finders/spree/taxons/find.rb+++ b/core/app/finders/spree/taxons/find.rb@@ -65,9 +65,13 @@ module Spreedef by_parent_permalink(taxons)return taxons unless parent_permalink?- taxons.joins(:parent).- join_translation_table(Taxon, 'parents_spree_taxons').- where(["#{Taxon.translation_table_alias}.permalink = ?", parent_permalink])+ if Spree.use_translations?+ taxons.joins(:parent).+ join_translation_table(Taxon, 'parents_spree_taxons').+ where(["#{Taxon.translation_table_alias}.permalink = ?", parent_permalink])+ else+ taxons.joins(:parent).where(parent: { permalink: parent_permalink })+ endenddef by_taxonomy(taxons)diff --git a/core/app/models/concerns/spree/product_scopes.rb b/core/app/models/concerns/spree/product_scopes.rbindex effe62f8ca..a4e852b6cc 100644--- a/core/app/models/concerns/spree/product_scopes.rb+++ b/core/app/models/concerns/spree/product_scopes.rb@@ -33,15 +33,15 @@ module Spreedef self.property_conditions(property)properties_table = Property.table_name- property_translations_table = Property.translation_table_alias+case propertywhen Property then { "#{properties_table}.id" => property.id }when Integer then { "#{properties_table}.id" => property }elseif Property.column_for_attribute('id').type == :uuid- ["#{property_translations_table.name} = ? OR #{properties_table.id} = ?", property, property]+ ["#{properties_table}.name = ? OR #{properties_table}.id = ?", property, property]else- { "#{property_translations_table}.name" => property }+ { "#{properties_table}.name" => property }endendend@@ -127,25 +127,29 @@ module Spree# a scope that finds all products having property specified by name, object or idadd_search_scope :with_property do |property|- joins(:properties).join_translation_table(Property).where(property_conditions(property))+ joins(:properties).where(property_conditions(property))end# a simple test for product with a certain property-value pairing# note that it can test for properties with NULL values, but not for absent valuesadd_search_scope :with_property_value do |property, value|- joins(:properties).- join_translation_table(Property).- join_translation_table(ProductProperty).- where("#{ProductProperty.translation_table_alias}.value = ?", value).- where(property_conditions(property))+ if Spree.use_translations?+ joins(:properties).+ join_translation_table(Property).+ join_translation_table(ProductProperty).+ where("#{ProductProperty.translation_table_alias}.value = ?", value).+ where(property_conditions(property))+ else+ joins(:properties).+ where("#{ProductProperty.table_name}.value = ?", value).+ where(property_conditions(property))+ endendadd_search_scope :with_property_values do |property_filter_param, property_values|joins(product_properties: :property).- join_translation_table(Property).- join_translation_table(ProductProperty).- where(Property.translation_table_alias => { filter_param: property_filter_param }).- where(ProductProperty.translation_table_alias => { filter_param: property_values.map(&:parameterize) })+ where(Property.table_name => { filter_param: property_filter_param }).+ where(ProductProperty.table_name => { filter_param: property_values.map(&:parameterize) })endadd_search_scope :with_option do |option|@@ -156,9 +160,7 @@ module Spreeelsif OptionType.column_for_attribute('id').type == :uuidjoins(:option_types).where(spree_option_types: { name: option }).or(Product.joins(:option_types).where(spree_option_types: { id: option }))else- joins(:option_types).- join_translation_table(OptionType).- where(OptionType.translation_table_alias => { name: option })+ joins(:option_types).where(OptionType.table_name => { name: option })endend@@ -179,9 +181,7 @@ module Spreegroup("#{Spree::Product.table_name}.id").joins(variants_including_master: :option_values).- join_translation_table(Spree::OptionValue).- where(Spree::OptionValue.translation_table_alias => { name: value },- Spree::OptionValue.table_name => { option_type_id: option_type_id })+ where(Spree::OptionValue.table_name => { name: value, option_type_id: option_type_id })end# Finds all products which have either:diff --git a/core/app/models/spree/option_type.rb b/core/app/models/spree/option_type.rbindex 58d5de11ef..09b20857c5 100644--- a/core/app/models/spree/option_type.rb+++ b/core/app/models/spree/option_type.rb@@ -7,8 +7,8 @@ module Spreeinclude Spree::Webhooks::HasWebhooksend- TRANSLATABLE_FIELDS = %i[name presentation].freeze- translates(*TRANSLATABLE_FIELDS)+ TRANSLATABLE_FIELDS = %i[presentation].freeze+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)acts_as_listauto_strip_attributes :name, :presentationdiff --git a/core/app/models/spree/option_value.rb b/core/app/models/spree/option_value.rbindex 0e363ff7b7..d01b46d2e4 100644--- a/core/app/models/spree/option_value.rb+++ b/core/app/models/spree/option_value.rb@@ -6,8 +6,8 @@ module Spreeinclude Spree::Webhooks::HasWebhooksend- TRANSLATABLE_FIELDS = %i[name presentation].freeze- translates(*TRANSLATABLE_FIELDS)+ TRANSLATABLE_FIELDS = %i[presentation].freeze+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)belongs_to :option_type, class_name: 'Spree::OptionType', touch: true, inverse_of: :option_valuesdiff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rbindex 79c36c2523..b2cd1a6ff6 100644--- a/core/app/models/spree/product.rb+++ b/core/app/models/spree/product.rb@@ -39,7 +39,7 @@ module Spreepurchasable? in_stock? backorderable?]TRANSLATABLE_FIELDS = %i[name description slug meta_description meta_keywords meta_title].freeze- translates(*TRANSLATABLE_FIELDS)+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)self::Translation.class_eval dobefore_save :set_slug@@ -332,16 +332,17 @@ module Spreeenddef property(property_name)- product_properties.joins(:property).- join_translation_table(Property).- find_by(Property.translation_table_alias => { name: property_name }).try(:value)+ product_properties.joins(:property).find_by(Property.table_name => { name: property_name }).try(:value)enddef set_property(property_name, property_value, property_presentation = property_name)ApplicationRecord.transaction do# Manual first_or_create to work around Mobility bugproperty = if Property.where(name: property_name).exists?- Property.where(name: property_name).first+ existing_property = Property.where(name: property_name).first+ existing_property.presentation ||= property_presentation+ existing_property.save+ existing_propertyelseProperty.create(name: property_name, presentation: property_presentation)end@@ -375,16 +376,24 @@ module Spreeenddef brand- @brand ||= taxons.joins(:taxonomy).- join_translation_table(Taxonomy).- find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_brands_name) })+ @brand ||= if Spree.use_translations?+ taxons.joins(:taxonomy).+ join_translation_table(Taxonomy).+ find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_brands_name) })+ else+ taxons.joins(:taxonomy).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_brands_name) })+ endenddef category- @category ||= taxons.joins(:taxonomy).- join_translation_table(Taxonomy).- order(depth: :desc).- find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_categories_name) })+ @category ||= if Spree.use_translations?+ taxons.joins(:taxonomy).+ join_translation_table(Taxonomy).+ order(depth: :desc).+ find_by(Taxonomy.translation_table_alias => { name: Spree.t(:taxonomy_categories_name) })+ else+ taxons.joins(:taxonomy).order(depth: :desc).find_by(Taxonomy.table_name => { name: Spree.t(:taxonomy_categories_name) })+ endenddef taxons_for_store(store)@@ -460,6 +469,8 @@ module Spree# punch slug with date prefix to allow reuse of originalreturn if frozen?+ update_column(:slug, "#{Time.current.to_i}_#{slug}"[0..254])+translations.with_deleted.each do |t|t.update_column :slug, "#{Time.current.to_i}_#{t.slug}"[0..254]enddiff --git a/core/app/models/spree/product_property.rb b/core/app/models/spree/product_property.rbindex 09e9e189bd..23c69d3721 100644--- a/core/app/models/spree/product_property.rb+++ b/core/app/models/spree/product_property.rb@@ -3,13 +3,15 @@ module Spreeinclude Spree::FilterParaminclude Spree::TranslatableResource- TRANSLATABLE_FIELDS = %i[value filter_param].freeze- translates(*TRANSLATABLE_FIELDS)+ TRANSLATABLE_FIELDS = %i[value].freeze+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)self::Translation.class_eval doauto_strip_attributes :valueend+ auto_strip_attributes :value+acts_as_list scope: :productwith_options inverse_of: :product_properties dodiff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rbindex 12338a5481..91ac2c8952 100644--- a/core/app/models/spree/property.rb+++ b/core/app/models/spree/property.rb@@ -7,13 +7,15 @@ module Spreeinclude Spree::Webhooks::HasWebhooksend- TRANSLATABLE_FIELDS = %i[name presentation filter_param].freeze- translates(*TRANSLATABLE_FIELDS)+ TRANSLATABLE_FIELDS = %i[presentation].freeze+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)self::Translation.class_eval do- auto_strip_attributes :name, :presentation+ auto_strip_attributes :presentationend+ auto_strip_attributes :name, :presentation+has_many :property_prototypes, class_name: 'Spree::PropertyPrototype'has_many :prototypes, through: :property_prototypes, class_name: 'Spree::Prototype'diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex 1de6157c16..e9e1681af7 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -11,7 +11,7 @@ module SpreeTRANSLATABLE_FIELDS = %i[name meta_description meta_keywords seo_title facebooktwitter instagram customer_support_email descriptionaddress contact_phone new_order_notifications_email].freeze- translates(*TRANSLATABLE_FIELDS)+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)self::Translation.class_eval doacts_as_paranoiddiff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rbindex 8524c1034f..9cdb89f9db 100644--- a/core/app/models/spree/taxon.rb+++ b/core/app/models/spree/taxon.rb@@ -48,6 +48,8 @@ module Spreeafter_update :sync_taxonomy_nameafter_touch :touch_ancestors_and_taxonomy+ has_one :store, through: :taxonomy+has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::TaxonImage'scope :for_store, ->(store) { joins(:taxonomy).where(spree_taxonomies: { store_id: store.id }) }@@ -58,7 +60,7 @@ module Spreescope :for_stores, ->(stores) { joins(:taxonomy).where(spree_taxonomies: { store_id: stores.ids }) }TRANSLATABLE_FIELDS = %i[name description permalink].freeze- translates(*TRANSLATABLE_FIELDS)+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)self::Translation.class_eval doalias_attribute :slug, :permalink@@ -117,7 +119,21 @@ module Spree# Creates permalink base for friendly_iddef set_permalink- translations.each(&:set_permalink)+ if Spree.use_translations?+ translations.each(&:set_permalink)+ else+ self.permalink = generate_slug+ end+ end++ def generate_slug+ if parent.present?+ [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last.to_url)].join('/')+ elsif permalink.blank?+ name.to_url+ else+ permalink.to_url+ endenddef active_products@@ -150,7 +166,7 @@ module Spreeprivatedef sync_taxonomy_name- if saved_change_to_name? && root?+ if saved_changes.key?(:name) && root?return if taxonomy.name.to_s == name.to_staxonomy.update(name: name)diff --git a/core/app/models/spree/taxonomy.rb b/core/app/models/spree/taxonomy.rbindex 067281d136..4e48c46d49 100644--- a/core/app/models/spree/taxonomy.rb+++ b/core/app/models/spree/taxonomy.rb@@ -7,7 +7,7 @@ module SpreeendTRANSLATABLE_FIELDS = %i[name].freeze- translates(*TRANSLATABLE_FIELDS)+ translates(*TRANSLATABLE_FIELDS, column_fallback: true)acts_as_list@@ -32,7 +32,7 @@ module Spreeenddef set_root_taxon_name- return unless saved_change_to_name?+ return unless saved_changes.key?(:name)return if name.to_s == root.name.to_sroot.update(name: name)diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rbindex abac51d04e..b7dee21b67 100644--- a/core/app/models/spree/variant.rb+++ b/core/app/models/spree/variant.rb@@ -122,9 +122,14 @@ module Spreeself.whitelisted_ransackable_scopes = %i(product_name_or_sku_cont search_by_product_name_or_sku)def self.product_name_or_sku_cont(query)- joins(:product).join_translation_table(Product).- where("LOWER(#{Product.translation_table_alias}.name) LIKE LOWER(:query)- OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")+ if Spree.use_translations?+ joins(:product).+ join_translation_table(Product).+ where("LOWER(#{Product.translation_table_alias}.name) LIKE LOWER(:query)+ OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")+ else+ joins(:product).where("LOWER(#{Product.table_name}.name) LIKE LOWER(:query) OR LOWER(sku) LIKE LOWER(:query)", query: "%#{query}%")+ endenddef self.search_by_product_name_or_sku(query)diff --git a/core/app/sorters/spree/products/sort.rb b/core/app/sorters/spree/products/sort.rbindex 511dabd869..e5a74224da 100644--- a/core/app/sorters/spree/products/sort.rb+++ b/core/app/sorters/spree/products/sort.rb@@ -11,7 +11,7 @@ module Spreeproducts = by_price(products)products = by_sku(products)- products = select_translatable_fields(products)+ products = select_translatable_fields(products) if Spree.use_translations?products.distinctenddiff --git a/core/config/initializers/mobility.rb b/core/config/initializers/mobility.rbindex cae9e4d9b1..4e4265af1f 100644--- a/core/config/initializers/mobility.rb+++ b/core/config/initializers/mobility.rb@@ -12,5 +12,6 @@ Mobility.configure do |config|locale_accessorspresencedirty+ column_fallbackendenddiff --git a/core/db/migrate/20220715120222_change_product_name_null_to_true.rb b/core/db/migrate/20220715120222_change_product_name_null_to_true.rbdeleted file mode 100644index 007da64c9b..0000000000--- a/core/db/migrate/20220715120222_change_product_name_null_to_true.rb+++ /dev/null@@ -1,5 +0,0 @@-class ChangeProductNameNullToTrue < ActiveRecord::Migration[6.1]- def change- change_column_null :spree_products, :name, true- end-enddiff --git a/core/db/migrate/20220718100948_change_taxon_name_null_to_true.rb b/core/db/migrate/20220718100948_change_taxon_name_null_to_true.rbdeleted file mode 100644index 0133915630..0000000000--- a/core/db/migrate/20220718100948_change_taxon_name_null_to_true.rb+++ /dev/null@@ -1,5 +0,0 @@-class ChangeTaxonNameNullToTrue < ActiveRecord::Migration[6.1]- def change- change_column_null :spree_taxons, :name, true- end-enddiff --git a/core/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb b/core/db/migrate/20220804073928_transfer_data_to_translatable_tables.rbdeleted file mode 100644index e5aac575e6..0000000000--- a/core/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb+++ /dev/null@@ -1,66 +0,0 @@-class TransferDataToTranslatableTables < ActiveRecord::Migration[6.1]- DEFAULT_LOCALE = 'en'- PRODUCTS_TABLE = 'spree_products'- PRODUCT_TRANSLATIONS_TABLE = 'spree_product_translations'- TAXONS_TABLE = 'spree_taxons'- TAXON_TRANSLATIONS_TABLE = 'spree_taxon_translations'-- def up- # Products- ActiveRecord::Base.connection.execute("- INSERT INTO #{PRODUCT_TRANSLATIONS_TABLE} (name, description, locale, spree_product_id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug)- SELECT name, description, '#{DEFAULT_LOCALE}' as locale, id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug FROM #{PRODUCTS_TABLE}- ")- ActiveRecord::Base.connection.execute("- UPDATE #{PRODUCTS_TABLE}- SET name=null, description=null, meta_description=null, meta_keywords=null, meta_title=null, slug=null;- ")- #Taxons- ActiveRecord::Base.connection.execute("- INSERT INTO #{TAXON_TRANSLATIONS_TABLE} (name, description, locale, spree_taxon_id, created_at, updated_at)- SELECT name, description, '#{DEFAULT_LOCALE}' as locale, id, created_at, updated_at FROM #{TAXONS_TABLE}- ")- ActiveRecord::Base.connection.execute("- UPDATE #{TAXONS_TABLE}- SET name=null, description=null- ")- end-- def down- ActiveRecord::Base.connection.execute("- UPDATE #{PRODUCTS_TABLE} as products- SET (name,- description,- meta_description,- meta_keywords,- meta_title,- slug) =- (t_products.name,- t_products.description,- t_products.meta_description,- t_products.meta_keywords,- t_products.meta_title,- t_products.slug)- FROM #{PRODUCT_TRANSLATIONS_TABLE} AS t_products- WHERE t_products.spree_product_id = products.id- ")-- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE #{PRODUCT_TRANSLATIONS_TABLE}- ")-- ActiveRecord::Base.connection.execute("- UPDATE #{TAXONS_TABLE} as taxons- SET (name,- description) =- (t_taxons.name,- t_taxons.description)- FROM #{TAXON_TRANSLATIONS_TABLE} AS t_taxons- WHERE t_taxons.spree_taxon_id = taxons.id- ")-- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE #{TAXON_TRANSLATIONS_TABLE}- ")- end-enddiff --git a/core/db/migrate/20230103144439_create_option_type_translations.rb b/core/db/migrate/20230103144439_create_option_type_translations.rbindex 5f798dc909..cc552e7342 100644--- a/core/db/migrate/20230103144439_create_option_type_translations.rb+++ b/core/db/migrate/20230103144439_create_option_type_translations.rb@@ -9,7 +9,6 @@ class CreateOptionTypeTranslations < ActiveRecord::Migration[6.1]create_table :spree_option_type_translations do |t|# Translated attribute(s)- t.string :namet.string :presentationt.string :locale, null: falsediff --git a/core/db/migrate/20230103151034_create_option_value_translations.rb b/core/db/migrate/20230103151034_create_option_value_translations.rbindex b04a264de7..6a3b937ef7 100644--- a/core/db/migrate/20230103151034_create_option_value_translations.rb+++ b/core/db/migrate/20230103151034_create_option_value_translations.rb@@ -9,7 +9,6 @@ class CreateOptionValueTranslations < ActiveRecord::Migration[6.1]create_table :spree_option_value_translations do |t|# Translated attribute(s)- t.string :namet.string :presentationt.string :locale, null: falsediff --git a/core/db/migrate/20230109084253_create_product_property_translations.rb b/core/db/migrate/20230109084253_create_product_property_translations.rbindex 511ee40328..7d929c9fdd 100644--- a/core/db/migrate/20230109084253_create_product_property_translations.rb+++ b/core/db/migrate/20230109084253_create_product_property_translations.rb@@ -9,7 +9,6 @@ class CreateProductPropertyTranslations < ActiveRecord::Migration[6.1]create_table :spree_product_property_translations do |t|# Translated attribute(s)t.string :value- t.string :filter_paramt.string :locale, null: falset.references :spree_product_property, null: false, foreign_key: true, index: falsediff --git a/core/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb b/core/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rbdeleted file mode 100644index ff7eb328fe..0000000000--- a/core/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb+++ /dev/null@@ -1,58 +0,0 @@-class TransferOptionsDataToTranslatableTables < ActiveRecord::Migration[6.1]- DEFAULT_LOCALE = 'en'-- def up- # Only transfer data if translation tables are being newly created / no translations exist- # Otherwise, assume translation data is already in place from spree_globalize-- # Option Types- if not Spree::OptionType::Translation.exists?- ActiveRecord::Base.connection.execute("- INSERT INTO spree_option_type_translations (name, presentation, locale, spree_option_type_id, created_at, updated_at)- SELECT name, presentation, '#{DEFAULT_LOCALE}', id, created_at, updated_at- FROM spree_option_types;- ")- ActiveRecord::Base.connection.execute("- UPDATE spree_option_types- SET name=null, presentation=null;- ")- end-- # Option Values- if not Spree::OptionValue::Translation.exists?- ActiveRecord::Base.connection.execute("- INSERT INTO spree_option_value_translations (name, presentation, locale, spree_option_value_id, created_at, updated_at)- SELECT name, presentation, '#{DEFAULT_LOCALE}', id, created_at, updated_at- FROM spree_option_values;- ")- ActiveRecord::Base.connection.execute("- UPDATE spree_option_values- SET name=null, presentation=null;- ")- end- end-- def down- # Option Types- ActiveRecord::Base.connection.execute("- UPDATE spree_option_types as option_types- SET (name, presentation) = (t_option_types.name, t_option_types.presentation)- FROM spree_option_type_translations AS t_option_types- WHERE t_option_types.spree_option_type_id = option_types.id;- ")- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE spree_option_type_translations;- ")-- # Option Values- ActiveRecord::Base.connection.execute("- UPDATE spree_option_values as option_values- SET (name, presentation) = (t_option_values.name, t_option_values.presentation)- FROM spree_option_value_translations AS t_option_values- WHERE t_option_values.spree_option_value_id = option_values.id;- ")- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE spree_option_value_translations;- ")- end-enddiff --git a/core/db/migrate/20230109105943_create_property_translations.rb b/core/db/migrate/20230109105943_create_property_translations.rbindex 8dde187338..ea1b95de37 100644--- a/core/db/migrate/20230109105943_create_property_translations.rb+++ b/core/db/migrate/20230109105943_create_property_translations.rb@@ -8,9 +8,7 @@ class CreatePropertyTranslations < ActiveRecord::Migration[6.1]elsecreate_table :spree_property_translations do |t|# Translated attribute(s)- t.string :namet.string :presentation- t.string :filter_paramt.string :locale, null: falset.references :spree_property, null: false, foreign_key: true, index: falsediff --git a/core/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb b/core/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rbdeleted file mode 100644index 5fb7814dc0..0000000000--- a/core/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb+++ /dev/null@@ -1,59 +0,0 @@-class TransferPropertyDataToTranslatableTables < ActiveRecord::Migration[6.1]- DEFAULT_LOCALE = 'en'-- def up- # Properties- change_column_null :spree_properties, :presentation, true-- if not Spree::Property::Translation.exists?- ActiveRecord::Base.connection.execute("- INSERT INTO spree_property_translations (name, presentation, filter_param, locale, spree_property_id, created_at, updated_at)- SELECT name, presentation, filter_param, '#{DEFAULT_LOCALE}', id, created_at, updated_at- FROM spree_properties;- ")- ActiveRecord::Base.connection.execute("- UPDATE spree_properties- SET name=null, presentation=null, filter_param=null;- ")- end-- # Product Properties- if not Spree::ProductProperty::Translation.exists?- ActiveRecord::Base.connection.execute("- INSERT INTO spree_product_property_translations (value, filter_param, locale, spree_product_property_id, created_at, updated_at)- SELECT value, filter_param, '#{DEFAULT_LOCALE}', id, created_at, updated_at- FROM spree_product_properties;- ")- ActiveRecord::Base.connection.execute("- UPDATE spree_product_properties- SET value=null, filter_param=null;- ")- end- end-- def down- # Properties- change_column_null :spree_properties, :presentation, false-- ActiveRecord::Base.connection.execute("- UPDATE spree_properties AS properties- SET (name, presentation, filter_param) = (t_properties.name, t_properties.presentation, t_properties.filter_param)- FROM spree_property_translations AS t_properties- WHERE t_properties.spree_property_id = properties.id;- ")- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE spree_property_translations;- ")-- # Product Properties- ActiveRecord::Base.connection.execute("- UPDATE spree_product_properties AS product_properties- SET (value, filter_param) = (t_product_properties.value, t_product_properties.filter_param)- FROM spree_product_property_translations AS t_product_properties- WHERE t_product_properties.spree_product_property_id = product_properties.id;- ")- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE spree_product_property_translations;- ")- end-enddiff --git a/core/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb b/core/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rbindex c2c168d94c..fe3426a32e 100644--- a/core/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb+++ b/core/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb@@ -1,15 +1,9 @@class BackfillFriendlyIdSlugLocale < ActiveRecord::Migration[6.1]- DEFAULT_LOCALE = 'en'-def up- ActiveRecord::Base.connection.execute("- UPDATE friendly_id_slugs SET locale = '#{DEFAULT_LOCALE}'- ")+ FriendlyId::Slug.unscoped.update_all(locale: Spree::Store.default.default_locale)enddef down- ActiveRecord::Base.connection.execute("- UPDATE friendly_id_slugs SET locale = NULL- ")+ FriendlyId::Slug.unscoped.update_all(locale: nil)endenddiff --git a/core/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb b/core/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rbdeleted file mode 100644index 8c5b024769..0000000000--- a/core/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb+++ /dev/null@@ -1,82 +0,0 @@-class TransferProductAndTaxonDataToTranslatableTables < ActiveRecord::Migration[6.1]- DEFAULT_LOCALE = 'en'- PRODUCTS_TABLE = 'spree_products'- PRODUCT_TRANSLATIONS_TABLE = 'spree_product_translations'- TAXONS_TABLE = 'spree_taxons'- TAXON_TRANSLATIONS_TABLE = 'spree_taxon_translations'-- def up- # Only transfer data if translation tables are being newly created / no translations exist- # Otherwise, assume translation data is already in place from spree_globalize-- # Products- if not Spree::Product::Translation.exists?- ActiveRecord::Base.connection.execute("- INSERT INTO #{PRODUCT_TRANSLATIONS_TABLE} (name, description, locale, spree_product_id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug)- SELECT name, description, '#{DEFAULT_LOCALE}' as locale, id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug FROM #{PRODUCTS_TABLE};- ")- ActiveRecord::Base.connection.execute("- UPDATE #{PRODUCTS_TABLE}- SET name=null, description=null, meta_description=null, meta_keywords=null, meta_title=null, slug=null;- ")- end-- # Taxons- if not Spree::Taxon::Translation.exists?- ActiveRecord::Base.connection.execute("- INSERT INTO #{TAXON_TRANSLATIONS_TABLE} (name, description, meta_title, meta_description, meta_keywords, permalink, locale, spree_taxon_id, created_at, updated_at)- SELECT name, description, meta_title, meta_description, meta_keywords, permalink, '#{DEFAULT_LOCALE}' as locale, id, created_at, updated_at FROM #{TAXONS_TABLE};- ")- ActiveRecord::Base.connection.execute("- UPDATE #{TAXONS_TABLE}- SET name=null, description=null, meta_title=null, meta_description=null, meta_keywords=null, permalink=null;- ")- end- end-- def down- ActiveRecord::Base.connection.execute("- UPDATE #{PRODUCTS_TABLE} as products- SET (name,- description,- meta_description,- meta_keywords,- meta_title,- slug) =- (t_products.name,- t_products.description,- t_products.meta_description,- t_products.meta_keywords,- t_products.meta_title,- t_products.slug)- FROM #{PRODUCT_TRANSLATIONS_TABLE} AS t_products- WHERE t_products.spree_product_id = products.id- ")-- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE #{PRODUCT_TRANSLATIONS_TABLE}- ")-- ActiveRecord::Base.connection.execute("- UPDATE #{TAXONS_TABLE} as taxons- SET (name,- description,- meta_title,- meta_description,- meta_keywords,- permalink) =- (t_taxons.name,- t_taxons.description,- t_taxons.meta_title,- t_taxons.meta_description,- t_taxons.meta_keywords,- t_taxons.permalink)- FROM #{TAXON_TRANSLATIONS_TABLE} AS t_taxons- WHERE t_taxons.spree_taxon_id = taxons.id- ")-- ActiveRecord::Base.connection.execute("- TRUNCATE TABLE #{TAXON_TRANSLATIONS_TABLE}- ")- end-enddiff --git a/core/db/migrate/20230117120430_allow_null_taxonomy_name.rb b/core/db/migrate/20230117120430_allow_null_taxonomy_name.rbdeleted file mode 100644index 743d40de42..0000000000--- a/core/db/migrate/20230117120430_allow_null_taxonomy_name.rb+++ /dev/null@@ -1,5 +0,0 @@-class AllowNullTaxonomyName < ActiveRecord::Migration[6.1]- def change- change_column_null :spree_taxonomies, :name, true- end-enddiff --git a/core/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb b/core/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rbdeleted file mode 100644index a3ef237123..0000000000--- a/core/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb+++ /dev/null@@ -1,11 +0,0 @@-class TransferTaxonomyDataToTranslatableTables < ActiveRecord::Migration[6.1]- TRANSLATION_MIGRATION = Spree::TranslationMigrations.new(Spree::Taxonomy, 'en')-- def up- TRANSLATION_MIGRATION.transfer_translation_data- end-- def down- TRANSLATION_MIGRATION.revert_translation_data_transfer- end-enddiff --git a/core/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb b/core/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rbdeleted file mode 100644index b1b1807a97..0000000000--- a/core/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb+++ /dev/null@@ -1,11 +0,0 @@-class TransferStoreDataToTranslatableTables < ActiveRecord::Migration[6.1]- TRANSLATION_MIGRATION = Spree::TranslationMigrations.new(Spree::Store, 'en')-- def up- TRANSLATION_MIGRATION.transfer_translation_data- end-- def down- TRANSLATION_MIGRATION.revert_translation_data_transfer- end-enddiff --git a/core/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb b/core/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rbdeleted file mode 100644index b352b8ad16..0000000000--- a/core/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb+++ /dev/null@@ -1,5 +0,0 @@-class AddIndexOnLocaleAndPermalinkToSpreeTaxons < ActiveRecord::Migration[6.1]- def change- add_index :spree_taxon_translations, [:locale, :permalink], unique: true, name: 'unique_permalink_per_locale', if_not_exists: true- end-enddiff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rbindex 485937c957..c817a4b7bf 100644--- a/core/lib/spree/core.rb+++ b/core/lib/spree/core.rb@@ -76,6 +76,10 @@ module Spreeendend+ def self.use_translations?+ Spree::RuntimeConfig.always_use_translations || I18n.default_locale != I18n.locale+ end+# Used to configure Spree.## Example:diff --git a/core/lib/spree/core/controller_helpers/locale.rb b/core/lib/spree/core/controller_helpers/locale.rbindex 4b4b493e44..f0388145b4 100644--- a/core/lib/spree/core/controller_helpers/locale.rb+++ b/core/lib/spree/core/controller_helpers/locale.rb@@ -28,6 +28,10 @@ module SpreeSpree::Locales::SetFallbackLocaleForStore.new.call(store: current_store)end+ def default_locale+ @default_locale ||= current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale+ end+def current_locale@current_locale ||= if user_locale?try_spree_current_user.selected_locale@@ -36,7 +40,7 @@ module Spreeelsif config_locale?config_localeelse- current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale+ default_localeendenddiff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rbindex fe47adbb1d..d9ff47b639 100644--- a/core/lib/spree/core/engine.rb+++ b/core/lib/spree/core/engine.rb@@ -1,11 +1,13 @@require_relative 'dependencies'require_relative 'configuration'+require_relative 'runtime_configuration'module Spreemodule Coreclass Engine < ::Rails::EngineEnvironment = Struct.new(:calculators,:preferences,+ :runtime_preferences,:dependencies,:payment_methods,:adjusters,@@ -23,9 +25,10 @@ module Spreeendinitializer 'spree.environment', before: :load_config_initializers do |app|- app.config.spree = Environment.new(SpreeCalculators.new, Spree::Core::Configuration.new, Spree::Core::Dependencies.new)+ app.config.spree = Environment.new(SpreeCalculators.new, Spree::Core::Configuration.new, Spree::Core::RuntimeConfiguration.new, Spree::Core::Dependencies.new)app.config.active_record.yaml_column_permitted_classes = [Symbol, BigDecimal]Spree::Config = app.config.spree.preferences+ Spree::RuntimeConfig = app.config.spree.runtime_preferencesSpree::Dependencies = app.config.spree.dependenciesSpree::Deprecation = ActiveSupport::Deprecation.newenddiff --git a/core/lib/spree/core/product_duplicator.rb b/core/lib/spree/core/product_duplicator.rbindex e24c2695b4..59e078e1b3 100644--- a/core/lib/spree/core/product_duplicator.rb+++ b/core/lib/spree/core/product_duplicator.rb@@ -30,6 +30,8 @@ module Spreet.name = "COPY OF #{t.name}"t.slug = nilend++ new_product.name = "COPY OF #{product.name}"new_product.taxons = product.taxonsnew_product.stores = product.storesnew_product.created_at = nildiff --git a/core/lib/spree/core/product_filters.rb b/core/lib/spree/core/product_filters.rbindex 2c586c4c85..2799b4004e 100644--- a/core/lib/spree/core/product_filters.rb+++ b/core/lib/spree/core/product_filters.rb@@ -98,7 +98,12 @@ module Spreeconds.each do |new_scope|scope = scope.or(new_scope)end- Product.with_property('brand').join_translation_table(ProductProperty).where(scope)++ if Spree.use_translations?+ Product.with_property('brand').join_translation_table(ProductProperty).where(scope)+ else+ Product.with_property('brand').where(scope)+ endenddef self.brand_filter@@ -106,7 +111,9 @@ module Spreebrands = brand_property ? Spree::ProductProperty.where(property_id: brand_property.id).pluck(:value).uniq.map(&:to_s) : []conditions = brands.map do |brand|- [brand, { ProductProperty.translation_table_alias => { value: brand } }]+ table_name = Spree.use_translations? ? ProductProperty.translation_table_alias : ProductProperty.table_name++ [brand, { table_name.to_s => { value: brand } }]end.to_h{diff --git a/core/lib/spree/core/runtime_configuration.rb b/core/lib/spree/core/runtime_configuration.rbnew file mode 100644index 0000000000..72c898fb03--- /dev/null+++ b/core/lib/spree/core/runtime_configuration.rb@@ -0,0 +1,9 @@+require 'spree/core/preferences/runtime_configuration'++module Spree+ module Core+ class RuntimeConfiguration < Preferences::RuntimeConfiguration+ preference :always_use_translations, :boolean, default: false+ end+ end+enddiff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rbindex c09c772a81..9e731bafcb 100644--- a/core/spec/models/spree/product_spec.rb+++ b/core/spec/models/spree/product_spec.rb@@ -62,8 +62,9 @@ describe Spree::Product, type: :model doit 'duplicates product' doclone = product.duplicate- expect(clone.name).to eq('COPY OF ' + product.name)- expect(clone.master.sku).to eq('COPY OF ' + product.master.sku)+ expect(clone.name).to eq("COPY OF #{product.name}")+ expect(clone.slug).to eq("copy-of-#{product.slug}")+ expect(clone.master.sku).to eq("COPY OF #{product.master.sku}")expect(clone.taxons).to eq(product.taxons)expect(clone.stores).to eq(product.stores)expect(clone.images.size).to eq(product.images.size)@@ -249,7 +250,7 @@ describe Spree::Product, type: :model docontext 'when product destroyed' doit 'renames slug' doproduct.destroy- expect(product.translations.with_deleted.where(locale: :en).first.slug).to match(/[0-9]+_product-[0-9]+/)+ expect(product.slug).to match(/[0-9]+_product-[0-9]+/)endcontext 'when more than one translation exists' do@@ -260,7 +261,7 @@ describe Spree::Product, type: :model doit 'renames slug for all translations' doproduct.destroy- expect(product.translations.with_deleted.where(locale: :en).first.slug).to match(/[0-9]+_product-[0-9]+/)+ expect(product.slug).to match(/[0-9]+_product-[0-9]+/)expect(product.translations.with_deleted.where(locale: :fr).first.slug).to match(/[0-9]+_french-slug/)endend@@ -401,6 +402,18 @@ describe Spree::Product, type: :model doproduct.set_property('the_prop', 'value2')expect(product.property('the_prop')).to eq('value2')++ I18n.with_locale(:pl) do+ product.set_property('the_prop', 'translated-value1', 'the_translated_prop')+ expect(product.property('the_prop')).to eq('translated-value1')++ product.set_property('the_prop', 'translated-value2')+ expect(product.property('the_prop')).to eq('translated-value2')++ expect(product.properties[0].presentation).to eq('the_translated_prop')+ end++ expect(product.properties[0].presentation).to eq('the_prop')endit 'does not create duplicate properties when set_property is called' do@@ -921,7 +934,7 @@ describe Spree::Product, type: :model dodescribe '#localized_slugs_for_store' dolet(:store) { create(:store, default_locale: 'fr', supported_locales: 'en,pl,fr') }- let(:product) { create(:product, stores: [store], name: 'Test product', slug: 'test_slug_en') }+ let(:product) { create(:product, stores: [store], name: 'Test product', slug: 'test-slug-en') }let!(:product_translation_fr) { product.translations.create(slug: 'test_slug_fr', locale: 'fr') }before { Spree::Locales::SetFallbackLocaleForStore.new.call(store: store) }diff --git a/core/spec/models/spree/property_spec.rb b/core/spec/models/spree/property_spec.rbindex ed837dc3fb..7edffe1509 100644--- a/core/spec/models/spree/property_spec.rb+++ b/core/spec/models/spree/property_spec.rb@@ -84,10 +84,8 @@ describe Spree::Property, type: :model dolet(:product_property_2) { create(:product_property, property: property, product: product_2, value: 'Test Test') }before do- product_property.translations.each do |t|- t.update_column(:filter_param, nil)- t.update_column(:value, 'some_value')- end+ product_property.update_column(:filter_param, nil)+ product_property.update_column(:value, 'some_value')endcontext 'filterable property' dodiff --git a/core/spec/models/spree/taxon_spec.rb b/core/spec/models/spree/taxon_spec.rbindex e3ef36edd9..d97164f66a 100644--- a/core/spec/models/spree/taxon_spec.rb+++ b/core/spec/models/spree/taxon_spec.rb@@ -122,7 +122,7 @@ describe Spree::Taxon, type: :model dolet(:taxon) { build(:taxon, parent: parent, taxonomy: nil) }it { expect(taxon.valid?).to eq(true) }- it { expect { taxon.save }.to change(taxon, :taxonomy).to(taxonomy) }+ it { expect { taxon.save! }.to change(taxon, :taxonomy).to(taxonomy) }enddescribe '#sync_taxonomy_name' do@@ -131,8 +131,7 @@ describe Spree::Taxon, type: :model docontext 'when none root taxon name is updated' doit 'does not update the taxonomy name' do- taxon.update(name: 'Shoes')- taxon.save!+ taxon.update!(name: 'Shoes')taxonomy.reloadexpect(taxonomy.name).not_to eql taxon.name@@ -144,8 +143,7 @@ describe Spree::Taxon, type: :model doit 'updates the taxonomy name' doroot_taxon = described_class.find_by(name: 'Soft Goods')- root_taxon.update(name: 'Hard Goods')- root_taxon.save!+ root_taxon.update!(name: 'Hard Goods')taxonomy.reloadexpect(taxonomy.name).not_to eql 'Soft Goods'@@ -157,8 +155,7 @@ describe Spree::Taxon, type: :model doit 'updates the taxonomy name' doroot_taxon = described_class.find_by(name: 'Soft Goods')- root_taxon.update(name: 'spÉcial Numérique ƒ ˙ ¨ πø∆©')- root_taxon.save!+ root_taxon.update!(name: 'spÉcial Numérique ƒ ˙ ¨ πø∆©')taxonomy.reloadexpect(taxonomy.name).not_to eql 'Soft Goods'@@ -172,8 +169,7 @@ describe Spree::Taxon, type: :model dotaxonomy_updated_at = taxonomy.updated_at.to_sexpect {- root_taxon.update(permalink: 'something-else')- root_taxon.save!+ root_taxon.update!(permalink: 'something-else')root_taxon.reloadtaxonomy.reload}.not_to change { taxonomy.updated_at.to_s }.from(taxonomy_updated_at)@@ -227,11 +223,12 @@ describe Spree::Taxon, type: :model docontext 'when setting the slug translations for taxonomy' dolet!(:root_taxon_translation_pl) { root_taxon.translations.create(slug: 'slug with space', locale: 'pl') }+ let!(:root_taxon_translation_fr) { root_taxon.translations.create(slug: 'categories-fr', locale: 'fr') }let(:expected_slugs) do{'en' => 'categories',- 'fr' => 'categories',+ 'fr' => 'categories-fr','pl' => 'slug-with-space'}enddiff --git a/core/spec/models/spree/taxonomy_spec.rb b/core/spec/models/spree/taxonomy_spec.rbindex b9f720889a..5df0e14607 100644--- a/core/spec/models/spree/taxonomy_spec.rb+++ b/core/spec/models/spree/taxonomy_spec.rb@@ -31,18 +31,16 @@ describe Spree::Taxonomy, type: :model docontext 'when Taxonomy name is updated' doit 'changes the root Taxon name to match' do- @taxonomy.update(name: 'Soft Goods')- @taxonomy.save!+ @taxonomy.update!(name: 'Soft Goods')@taxonomy.reload- expect(@taxonomy.root.name).to eq('Soft Goods')+ expect(@taxonomy.root.reload.name).to eq('Soft Goods')endendcontext 'when Taxonomy position is updated' doit 'does not change the root Taxon name' do- @taxonomy.update(position: 2)- @taxonomy.save!+ @taxonomy.update!(position: 2)@taxonomy.reloadexpect(@taxonomy.root.name).to eq('Clothing')diff --git a/emails/spec/mailers/spree/order_mailer_spec.rb b/emails/spec/mailers/spree/order_mailer_spec.rbindex d0e330473b..a7077b37de 100644--- a/emails/spec/mailers/spree/order_mailer_spec.rb+++ b/emails/spec/mailers/spree/order_mailer_spec.rb@@ -8,6 +8,13 @@ describe Spree::OrderMailer, type: :mailer dolet(:first_store) { create(:store, name: 'First Store', default: true) }let(:second_store) { create(:store, name: 'Second Store', url: 'other.example.com') }+ before do+ # Make sure we always start with the default locale+ I18n.locale = :en+ first_store.update!(default_locale: 'en')+ second_store.update!(default_locale: 'en')+ end+let(:order) doorder = create(:completed_order_with_totals, email: '[email protected]')product = create(:product, name: %{The "BEST" product})@@ -196,6 +203,10 @@ describe Spree::OrderMailer, type: :mailer docontext 'via I18n' dobefore do+ # We need to create the order record before changing locales for translations+ # Since I18n.default_locale is "en" in specs+ order+I18n.locale = :'pt-BR'first_store.update(default_locale: 'pt-BR')end@@ -208,7 +219,10 @@ describe Spree::OrderMailer, type: :mailer doendcontext 'via Store locale' do- before { order.store.update!(default_locale: 'pt-BR') }+ before do+ order+ order.store.update!(default_locale: 'pt-BR')+ endit_behaves_like 'translates emails'enddiff --git a/emails/spec/mailers/spree/reimbursement_mailer_spec.rb b/emails/spec/mailers/spree/reimbursement_mailer_spec.rbindex 8815cf9d28..d57a2c85f7 100644--- a/emails/spec/mailers/spree/reimbursement_mailer_spec.rb+++ b/emails/spec/mailers/spree/reimbursement_mailer_spec.rb@@ -7,6 +7,12 @@ describe Spree::ReimbursementMailer, type: :mailer dolet(:reimbursement) { create(:reimbursement) }+ before do+ # Make sure we always start with the default locale+ I18n.locale = :en+ Spree::Store.default.update(default_locale: 'en')+ end+context ':from not set explicitly' doit 'uses store mail from address' domessage = Spree::ReimbursementMailer.reimbursement_email(reimbursement)@@ -51,6 +57,7 @@ describe Spree::ReimbursementMailer, type: :mailer docontext 'reimbursement_email' docontext 'pt-BR locale' dobefore do+ reimbursementI18n.enforce_available_locales = falsept_br_shipped_email = { spree: { reimbursement_mailer: { reimbursement_email: { dear_customer: 'Caro Cliente,' } } } }I18n.backend.store_translations :'pt-BR', pt_br_shipped_emaildiff --git a/emails/spec/mailers/spree/shipment_mailer_spec.rb b/emails/spec/mailers/spree/shipment_mailer_spec.rbindex 686d17fe67..4cbeb2df5d 100644--- a/emails/spec/mailers/spree/shipment_mailer_spec.rb+++ b/emails/spec/mailers/spree/shipment_mailer_spec.rb@@ -5,13 +5,16 @@ describe Spree::ShipmentMailer, type: :mailer doinclude EmailSpec::Helpersinclude EmailSpec::Matchers- let!(:store) { create(:store) }+ let(:store) { create(:store) }let(:order) { create(:shipped_order, store: store, email: '[email protected]', user: nil) }let(:shipment) { order.shipments.first }let(:shipping_method) { shipment.shipping_method }before do+ # Make sure we always start with the default locale+ I18n.locale = :en+shipping_method.update(tracking_url: 'http://example.com/tracking')end@@ -53,6 +56,8 @@ describe Spree::ShipmentMailer, type: :mailer doafter doI18n.enforce_available_locales = true+ I18n.locale = :en+ store.update(default_locale: 'en')endspecify do