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.

Give vendor translations somewhere to live

Damian Legawiec756f1aeca550
diff --git a/spree/core/app/models/spree/vendor.rb b/spree/core/app/models/spree/vendor.rb
index ad740bff31..a873961de4 100644
--- a/spree/core/app/models/spree/vendor.rb
+++ b/spree/core/app/models/spree/vendor.rb
@@ -46,6 +46,11 @@ module Spree
self::Translation.class_eval do
include Spree::SanitizableRichText
sanitizes_rich_text :about
+
+ acts_as_paranoid
+ # A deleted vendor's translations still have to render — its storefront
+ # profile outlives the row for as long as anything links to it.
+ default_scope { unscope(where: :deleted_at) }
end
#
diff --git a/spree/core/db/migrate/20260816000001_create_spree_vendors.rb b/spree/core/db/migrate/20260816000001_create_spree_vendors.rb
index 85e9eb39aa..8c862f0601 100644
--- a/spree/core/db/migrate/20260816000001_create_spree_vendors.rb
+++ b/spree/core/db/migrate/20260816000001_create_spree_vendors.rb
@@ -39,5 +39,20 @@ class CreateSpreeVendors < ActiveRecord::Migration[8.1]
add_index :spree_vendors, [:store_id, :slug], unique: true
add_index :spree_vendors, [:store_id, :status]
add_index :spree_vendors, :deleted_at
+
+ # Mobility table-backend translations, mirroring spree_collection_translations.
+ create_table :spree_vendor_translations do |t|
+ t.string :name
+ t.text :about
+ t.string :locale, null: false
+ t.references :spree_vendor, null: false, index: false
+
+ t.timestamps null: false
+ t.datetime :deleted_at
+ end
+
+ add_index :spree_vendor_translations, :locale, name: 'index_spree_vendor_translations_on_locale'
+ add_index :spree_vendor_translations, [:spree_vendor_id, :locale], unique: true,
+ name: 'index_vendor_translations_on_vendor_and_locale'
end
end
diff --git a/spree/core/spec/models/spree/vendor_spec.rb b/spree/core/spec/models/spree/vendor_spec.rb
index 343cff654c..f00f92465a 100644
--- a/spree/core/spec/models/spree/vendor_spec.rb
+++ b/spree/core/spec/models/spree/vendor_spec.rb
@@ -116,6 +116,23 @@ describe Spree::Vendor do
end
end
+ describe 'translations' do
+ it 'stores a translated name and about per locale' do
+ vendor = create(:vendor, name: 'Bright Sparks', about: '<p>We make lamps.</p>')
+
+ Mobility.with_locale(:fr) do
+ vendor.update!(name: 'Étincelles', about: '<p>Nous fabriquons des lampes.</p>')
+ end
+
+ expect(vendor.reload.name).to eq('Bright Sparks')
+ expect(Mobility.with_locale(:fr) { vendor.reload.name }).to eq('Étincelles')
+ end
+
+ it 'is registered as a translatable resource' do
+ expect(Spree.translatable_resources).to include(described_class)
+ end
+ end
+
describe 'settlement configuration' do
it 'defaults to the vendor remitting its own tax' do
expect(create(:vendor).tax_remittance).to eq('vendor')