docs/developer/upgrades/4.5-to-4.6.mdx
Run the following command to update your gems to 4.6:
bundle update
If your application used the spree_globalize extension, you can remove it from your Gemfile, as translations are now supported out-of-the-box with the Mobility gem.
We've configured Mobility to use a strategy that uses a separate table to store translations, just like how spree_globalize did. This means, you won't need to make any changes to the database structure or migrate data.
During the upgrade process, you may need to review your custom queries that rely on translations, as there are minor differences in how Mobility handles them. Spree 4.6 includes a few built-in concerns to make it easier to work with translatable models.
Run the following command to remove spree_globalize from your Gemfile:
bundle remove spree_globalize
bin/rake spree:install:migrations
bin/rails db:migrate
If you're using raw SQL queries (either in the application code, or running in external tools), you may need to review the new structure and update your queries accordingly. </Note>
This will copy some files from spree_backend to your application.
bin/rails g spree:backend:install
If you're using spree_frontend you need to run the frontend install generator as well:
bin/rails g spree:frontend:install
If you want to translate more fields in translated resources, you have to alter copied migrations or add new ones. We're using the Spree::TranslationMigrations to help with migrating data.
Each translated resource has a corresponding Translation model, see here for reference.
If you want to add some more behavior to the translation, you need to do it within the Translation.class_eval block.
If you overwrote Spree models in your application, you have to define this block yourself. Apart from that, please include these modules:
Spree::TranslatableResource - required for all translated modelsSpree::TranslatableResourceSlug - required for translated models with slugs/permalinksRead more how Spree handles resource translations.
friendly_idGenerating slugs/permalinks in Spree::Product and Spree::Taxon models is now based on the translated name. If you use the history plugin, read on how to use it with the mobility gem.
Currently, it's not possible to translate encrypted data. If you're already encrypting data that Spree translates, you need to remove that functionality.
If you use the pg_search for the full text search in translated resources, you need to move your scopes to the translated model, eg. from the Spree::Product to the Spree::Product::Translation.
If you still want to have the original scope, you need to rewrite it, from:
pg_search_scope :search_by_name, against: :name
to:
self::Translation.class_eval do
include PgSearch::Model
pg_search_scope :search_by_name, against: :name
end
scope :search_by_name, lambda { |query|
product_ids = Spree::Product::Translation.search_by_name(query).pluck(:spree_product_id)
where(id: product_ids)
}
For information about changes contained within this release, please read the Spree 4.6.0 Release Notes.