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.

store translations initial setup

nciemniak0d37e9f1854c
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 0e834e0879..97835f0a96 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -1,5 +1,6 @@
module Spree
class Store < Spree::Base
+ include TranslatableResource
if defined?(Spree::Webhooks)
include Spree::Webhooks::HasWebhooks
end
@@ -7,6 +8,12 @@ module Spree
include Spree::Security::Stores
end
+ TRANSLATABLE_FIELDS = %i[name url meta_description meta_keywords seo_title default_currency
+ supported_currencies facebook twitter instagram customer_support_email
+ default_country_id description address contact_phone new_order_notifications_email
+ checkout_zone_id].freeze
+ translate(*TRANSLATABLE_FIELDS)
+
typed_store :settings, coder: ActiveRecord::TypedStore::IdentityCoder do |s|
# Spree Digital Asset Configurations
s.boolean :limit_digital_download_count, default: true, null: false
diff --git a/core/app/models/spree/taxonomy.rb b/core/app/models/spree/taxonomy.rb
index f41d598f5a..7727f0c3ef 100644
--- a/core/app/models/spree/taxonomy.rb
+++ b/core/app/models/spree/taxonomy.rb
@@ -6,7 +6,7 @@ module Spree
include Spree::Webhooks::HasWebhooks
end
- TRANSLATABLE_FIELDS = %i[name]
+ TRANSLATABLE_FIELDS = %i[name].freeze
translates(*TRANSLATABLE_FIELDS)
acts_as_list
diff --git a/core/db/migrate/20230210142732_create_store_translations.rb b/core/db/migrate/20230210142732_create_store_translations.rb
new file mode 100644
index 0000000000..27685cd618
--- /dev/null
+++ b/core/db/migrate/20230210142732_create_store_translations.rb
@@ -0,0 +1,54 @@
+class CreateStoreTranslations < ActiveRecord::Migration[6.1]
+ def change
+ if ActiveRecord::Base.connection.table_exists?('spree_store_translations')
+ # manually check for index since Rails if_exists does not always work correctly
+ if ActiveRecord::Migration.connection.index_exists?(:spree_store_translations, :spree_store_id)
+ remove_index :spree_store_translations, column: :spree_store_id, if_exists: true
+ end
+
+ add_column :spree_store_translations, :url, :string
+ add_column :spree_store_translations, :default_currency, :string
+ add_column :spree_store_translations, :supported_currencies, :string
+ add_column :spree_store_translations, :facebook, :string
+ add_column :spree_store_translations, :twitter, :string
+ add_column :spree_store_translations, :instagram, :string
+ add_column :spree_store_translations, :customer_support_email, :string
+ add_column :spree_store_translations, :default_country_id, :integer
+ add_column :spree_store_translations, :description, :text
+ add_column :spree_store_translations, :address, :text
+ add_column :spree_store_translations, :contact_phone, :string
+ add_column :spree_store_translations, :new_order_notifications_email, :string
+ add_column :spree_store_translations, :checkout_zone_id, :integer
+ else
+ create_table :spree_store_translations do |t|
+ # Translated attribute(s)
+ t.string :name
+ t.string :url
+ t.text :meta_description
+ t.text :meta_keywords
+ t.string :seo_title
+ t.string :default_currency
+ t.string :supported_currencies
+ t.string :facebook
+ t.string :twitter
+ t.string :instagram
+ t.string :customer_support_email
+ t.integer :default_country_id
+ t.text :description
+ t.text :address
+ t.string :contact_phone
+ t.string :new_order_notifications_email
+ t.integer :checkout_zone_id
+
+ t.string :locale, null: false
+ t.references :spree_store, null: false, foreign_key: true, index: false
+
+ t.timestamps null: false
+ end
+
+ add_index :spree_store_translations, :locale, name: :index_spree_store_translations_on_locale
+ end
+
+ add_index :spree_store_translations, [:spree_store_id, :locale], name: :index_spree_store_translations_on_spree_store_id_locale, unique: true
+ end
+end
diff --git a/core/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb b/core/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb
new file mode 100644
index 0000000000..b1b1807a97
--- /dev/null
+++ b/core/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb
@@ -0,0 +1,11 @@
+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
+end