spree_mobility 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b777cdcbfc008f1f81a9e2479ca000cbe2a539d0d25cbe29cf5d7953518a925b
4
- data.tar.gz: 96de26f38d9798b5fa4dc3c4cc0fc4c16b629d0a131e28011300ae6fb56c64cf
3
+ metadata.gz: 4b978eb059a4af42b54b7972c52ca54a3c05e5bf2e1a1e6c184472da2298c555
4
+ data.tar.gz: '0748c01ed29ce8e98ae2e68b707d540d4e97066fb744f679f9e86087cfe555e9'
5
5
  SHA512:
6
- metadata.gz: 65dd2abb1b6929522f03b357646fa5707341b86e3d16fdbed4d955cb9694af5c6b562848b9212e16670cc639d93678467cd41e3d772f73c6c2ba6246bb33f86c
7
- data.tar.gz: 4af8d6a15d6a2a4d9fdad20b2cdfd180d4d4ef93106e46aa904fe1e5f6a6e5c9907f153f5b02b7e668de3e42653e66dd81d12d5cd58ade80a28d46ce6cb99b21
6
+ metadata.gz: 97541ca9b86a4a59632852d1ddd9c98c51dbfa82db2818e534ea4651754f85247efa9aa04df4ace9c5680639c1cef7b466e0d6ad7350fd548251ed1ec4da9232
7
+ data.tar.gz: 4fdae65ac633438659005a07fb4d9c6f62245c4fe4b566bc2b29f01c427253fc0916a6b54db3bc6c0908218e4df95f9ec35dcd12e622869f7cec0d061ae86960
data/README.md CHANGED
@@ -34,6 +34,15 @@ Mobility.configure do
34
34
  end
35
35
  ```
36
36
 
37
+ ## Spree 4.3.x
38
+
39
+ It seems there is a bug in spree_backend v4.3.x (before v4.4), which prevents translation links working correctly.
40
+ To fix this, add to the bottom of `vendor/assets/javascripts/spree/backend/all.js`:
41
+
42
+ ```ruby
43
+ $(document).trigger('page:load');
44
+ ```
45
+
37
46
  ---
38
47
 
39
48
  ## Improvements over spree_globalize
@@ -59,7 +68,7 @@ For more localization features, see my `better_spree_localization` gem.
59
68
  This feature uses the [Mobility][3] gem to localize model data.
60
69
  So far the following models are translatable:
61
70
 
62
- Product, Promotion, OptionType, Taxonomy, Taxon, Property, Store and ShippingMethod.
71
+ Product, Promotion, OptionType, Taxonomy, Taxon, Property, Store, ShippingMethod and PaymentMethod.
63
72
 
64
73
  Start your server and you should see a TRANSLATIONS link or a flag icon on each
65
74
  admin section that supports this feature.
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ module Admin
3
+ class PaymentMethodTranslationsController < Spree::Admin::BaseController
4
+ def translate
5
+ # Need to manually update translations, otherwise Rails
6
+ # accepts_nested_attributes_for in combination with current mobility
7
+ # implementation has some problems with the subclasses used with
8
+ # PaymentMethods
9
+ payment_method = Spree::PaymentMethod.find(params[:id])
10
+
11
+ translations_params =
12
+ params.require(:payment_method).permit(
13
+ [translations_attributes: [:id, :locale, :name, :description]])
14
+
15
+ payment_method.translations.delete_all
16
+ translations_params[:translations_attributes].each_pair do |k, value|
17
+ payment_method.translations.create(value)
18
+ end
19
+
20
+ flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:payment_method))
21
+ redirect_to spree.edit_admin_payment_method_path(payment_method)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,10 +1,10 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/option_types/_option_value_fields',
3
3
  name: 'option_value_translation',
4
- insert_bottom: 'td.actions',
4
+ insert_bottom: 'td.actions > span:first',
5
5
  text: <<-HTML
6
6
  <% if f.object.persisted? %>
7
- <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('option_values', f.object.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary' %>
7
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('option_values', f.object.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
8
8
  <% end %>
9
9
  HTML
10
10
  )
@@ -1,8 +1,8 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/option_types/index',
3
3
  name: 'option_types_index_translation',
4
- insert_top: 'td.actions',
4
+ insert_top: 'td.actions > span:first',
5
5
  text: <<-HTML
6
- <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('option_types', option_type.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary' %>
6
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('option_types', option_type.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
7
7
  HTML
8
8
  )
@@ -0,0 +1,8 @@
1
+ Deface::Override.new(
2
+ virtual_path: 'spree/admin/payment_methods/index',
3
+ name: 'payment_methods_translation',
4
+ insert_bottom: 'td.actions > span:first',
5
+ text: <<-HTML
6
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('payment_methods', method.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
7
+ HTML
8
+ )
@@ -1,10 +1,10 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/product_properties/_product_property_fields',
3
3
  name: 'product_property_translation',
4
- insert_bottom: 'td.actions',
4
+ insert_bottom: 'td.actions > span:first',
5
5
  text: <<-HTML
6
6
  <% if f.object.persisted? %>
7
- <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('product_property', f.object.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary' %>
7
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('product_property', f.object.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
8
8
  <% end %>
9
9
  HTML
10
10
  )
@@ -1,8 +1,8 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/promotions/index',
3
3
  name: 'promotions_translation',
4
- insert_bottom: 'td.actions',
4
+ insert_bottom: 'td.actions > span:first',
5
5
  text: <<-HTML
6
- <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('promotions', promotion.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary' %>
6
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('promotions', promotion.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
7
7
  HTML
8
8
  )
@@ -1,8 +1,8 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/properties/index',
3
3
  name: 'properties_translation',
4
- insert_bottom: 'td.actions',
4
+ insert_bottom: 'td.actions > span:first',
5
5
  text: <<-HTML
6
- <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('properties', property.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary' %>
6
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('properties', property.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
7
7
  HTML
8
8
  )
@@ -1,8 +1,8 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/shipping_methods/index',
3
3
  name: 'shipping_methods_translation',
4
- insert_bottom: 'td.actions',
4
+ insert_bottom: 'td.actions > span:first',
5
5
  text: <<-HTML
6
- <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('shipping_methods', shipping_method.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary' %>
6
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('shipping_methods', shipping_method.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
7
7
  HTML
8
8
  )
@@ -1,8 +1,8 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/taxonomies/_list',
3
3
  name: 'taxonomies_translation',
4
- insert_bottom: 'td.actions',
4
+ insert_bottom: 'td.actions > span:first',
5
5
  text: <<-HTML
6
- <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('taxonomies', taxonomy.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary' %>
6
+ <%= link_to_with_icon 'translate', nil, spree.admin_translations_path('taxonomies', taxonomy.id), title: Spree.t(:'i18n.translations'), class: 'btn btn-sm btn-primary', no_text: true %>
7
7
  HTML
8
8
  )
@@ -1,11 +1,12 @@
1
+ <% resource_class ||= @resource.class %>
1
2
  <div class="panel panel-default fields">
2
3
  <div class="panel-heading">
3
4
  <%= Spree.t(:'i18n.fields') %>
4
5
  </div>
5
6
  <div class="list-group" id="attr_list">
6
- <% @resource.class.mobility_attributes.each_with_index do |attr, i| %>
7
+ <% resource_class.mobility_attributes.each_with_index do |attr, i| %>
7
8
  <a class="list-group-item <%= 'active' if i.zero? %>" data-attr="<%= attr %>" href="#">
8
- <%= @resource.class.human_attribute_name(attr) %>
9
+ <%= resource_class.human_attribute_name(attr) %>
9
10
  </a>
10
11
  <% end %>
11
12
  </div>
@@ -1,11 +1,12 @@
1
+ <% resource_class ||= @resource.class %>
1
2
  <div id="attr_fields">
2
3
  <% available_locales.each do |locale| %>
3
4
  <%= f.mobility_fields_for locale.to_sym do |g| %>
4
- <% @resource.class.mobility_attributes.each_with_index do |attr, i| %>
5
+ <% resource_class.mobility_attributes.each_with_index do |attr, i| %>
5
6
  <div class="panel panel-default <%= attr %> <%= locale %>" style="display:<%= i == 0 ? 'auto' : 'none' %>;">
6
7
  <div class="panel-heading">
7
8
  <% I18n.with_locale(locale) do %>
8
- <%= @resource.class.human_attribute_name(attr) %>
9
+ <%= resource_class.human_attribute_name(attr) %>
9
10
 
10
11
  <div class="pull-right text-muted">
11
12
  <small><i><%= Spree.t(:'i18n.this_file_language') %></i></small>
@@ -14,7 +15,7 @@
14
15
  </div>
15
16
 
16
17
  <div class="panel-body">
17
- <% field_type = @resource.class.translation_class.columns_hash[attr.to_s].type %>
18
+ <% field_type = resource_class.translation_class.columns_hash[attr.to_s].type %>
18
19
  <% if @resource.kind_of?(Spree::Product) && attr.to_sym == :description %>
19
20
  <%= g.text_area :description, { rows: "30", class: "form-control #{"spree-rte" if SpreeMobility.product_wysiwyg_editor_enabled? }" } %>
20
21
  <% elsif @resource.kind_of?(Spree::Taxon) && attr.to_sym == :description %>
@@ -0,0 +1,21 @@
1
+ <% content_for :page_title do %>
2
+ <%= Spree.t(:editing_resource, resource: Spree::PaymentMethod.model_name.human) %>
3
+ <% end %>
4
+
5
+ <% content_for :page_actions do %>
6
+ <%= button_link_to Spree.t(:back_to_resource_list, resource: Spree::PaymentMethod.model_name.human), spree.admin_payment_methods_path, class: 'btn-primary', :icon => 'arrow-left' %>
7
+ <% end %>
8
+
9
+ <%= render 'settings' %>
10
+
11
+ <div class="row translations">
12
+ <div class="col-md-4">
13
+ <%= render 'fields', resource_class: Spree::PaymentMethod %>
14
+ </div>
15
+ <div class="col-md-8">
16
+ <%= form_for [:admin, @resource], url: admin_translate_payment_method_path(@resource), as: :payment_method do |f| %>
17
+ <%= render 'form_fields', f: f, resource_class: Spree::PaymentMethod %>
18
+ <%= render 'spree/admin/shared/edit_resource_links' %>
19
+ <% end %>
20
+ </div>
21
+ </div>
@@ -16,10 +16,10 @@ Rails.application.config.to_prepare do
16
16
  SpreeMobility.prepend_once(::Spree::Promotion, SpreeMobility::CoreExt::Spree::PromotionDecorator)
17
17
  SpreeMobility.prepend_once(::Spree::Property, SpreeMobility::CoreExt::Spree::PropertyDecorator)
18
18
  SpreeMobility.prepend_once(::Spree::ShippingMethod, SpreeMobility::CoreExt::Spree::ShippingMethodDecorator)
19
+ SpreeMobility.prepend_once(::Spree::PaymentMethod, SpreeMobility::CoreExt::Spree::PaymentMethodDecorator)
19
20
  SpreeMobility.prepend_once(::Spree::Store, SpreeMobility::CoreExt::Spree::StoreDecorator)
20
21
  SpreeMobility.prepend_once(::Spree::Taxon, SpreeMobility::CoreExt::Spree::TaxonDecorator)
21
22
  SpreeMobility.prepend_once(::Spree::Taxonomy, SpreeMobility::CoreExt::Spree::TaxonomyDecorator)
22
23
  SpreeMobility.prepend_once(::Spree::Variant.singleton_class, SpreeMobility::CoreExt::Spree::VariantDecorator::ClassMethods)
23
24
  SpreeMobility.prepend_once(::Spree::Products::Find, SpreeMobility::CoreExt::Spree::Products::FindWithMobilityDecorator)
24
25
  end
25
-
data/config/routes.rb CHANGED
@@ -3,5 +3,6 @@ Spree::Core::Engine.add_routes do
3
3
  get '/:resource/:resource_id/translations' => 'translations#index', as: :translations
4
4
  patch '/option_values/:id' => 'option_values#update', as: :option_type_option_value
5
5
  patch 'product/:id/product_properties/:id' => "product_properties#translate", as: :translate_product_property
6
+ patch 'payment_methods/:id/translate' => "payment_method_translations#translate", as: :translate_payment_method
6
7
  end
7
8
  end
@@ -0,0 +1,54 @@
1
+ class AddTranslationsToPaymentMethod < SpreeExtension::Migration[4.2]
2
+ def up
3
+ unless table_exists?(:spree_payment_method_translations)
4
+ params = { name: :string, description: :text }
5
+ create_translation_table(:spree_payment_method, params)
6
+ migrate_data(Spree::PaymentMethod, params)
7
+ end
8
+ end
9
+
10
+ def down
11
+ drop_table :spree_payment_method_translations
12
+ end
13
+
14
+ protected
15
+
16
+ def create_translation_table(table, params)
17
+ create_table :"#{table}_translations" do |t|
18
+
19
+ # Translated attribute(s)
20
+ params.each_pair do |attr, attr_type|
21
+ t.send attr_type, attr
22
+ end
23
+
24
+ t.string :locale, null: false
25
+ t.references table, null: false, foreign_key: true, index: false
26
+
27
+ t.timestamps null: false
28
+ end
29
+
30
+ add_index :"#{table}_translations", :locale, name: :"index_#{table}_translations_on_locale"
31
+ add_index :"#{table}_translations", [:"#{table}_id", :locale], name: :"index_#{table}_translations_on_id_and_locale", unique: true
32
+ end
33
+
34
+ def migrate_data(model_klass, fields)
35
+ store = Spree::Store.unscoped.first
36
+ return unless store
37
+ default_locale = store.default_locale.to_s
38
+ field_names = fields.keys + ['created_at', 'updated_at']
39
+ translation_table = "#{model_klass.table_name.singularize}_translations"
40
+ foreign_key = "#{model_klass.table_name.singularize}_id"
41
+
42
+ # In case we are migrating from Globalize with existing translations, skip this step
43
+ return if ActiveRecord::Base.connection.execute("SELECT id FROM #{translation_table}").any?
44
+ ActiveRecord::Base.connection.execute("SELECT id, #{field_names.join(',')} FROM #{model_klass.table_name}").each do |r|
45
+ field_values =
46
+ field_names.each_with_object([]) do |field_name, a|
47
+ a << r[field_name.to_s]
48
+ end
49
+
50
+ ActiveRecord::Base.connection.execute(ActiveRecord::Base.sanitize_sql_array(["INSERT INTO #{translation_table} (locale, #{foreign_key}, #{field_names.join(',')}) VALUES (?,?,#{(['?'] * field_names.size).join(',')})",
51
+ default_locale.to_s, r['id'], *field_values]))
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,10 @@
1
+ module SpreeMobility::CoreExt::Spree::PaymentMethodDecorator
2
+ def self.prepended(base)
3
+ base.include SpreeMobility::Translatable
4
+ SpreeMobility.translates_for base, :name, :description
5
+
6
+ base.translation_class.class_eval do
7
+ validates :name, presence: true
8
+ end
9
+ end
10
+ end
@@ -9,7 +9,7 @@ module SpreeMobility
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 3
12
+ MINOR = 4
13
13
  TINY = 0
14
14
  PRE = nil # 'beta'
15
15
 
@@ -30,4 +30,8 @@ module Spree
30
30
  RSpec.describe Spree::ShippingMethod, type: :model do
31
31
  include_context 'behaves as translatable'
32
32
  end
33
+
34
+ RSpec.describe Spree::PaymentMethod, type: :model do
35
+ include_context 'behaves as translatable'
36
+ end
33
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_mobility
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Berdajs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-13 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -194,6 +194,7 @@ files:
194
194
  - app/assets/javascripts/spree/backend/translations.js
195
195
  - app/controllers/concerns/spree_mobility/controller_mobility_helper.rb
196
196
  - app/controllers/spree/admin/option_values_controller_decorator.rb
197
+ - app/controllers/spree/admin/payment_method_translations_controller.rb
197
198
  - app/controllers/spree/admin/product_properties_controller_decorator.rb
198
199
  - app/controllers/spree/admin/shipping_methods_controller_decorator.rb
199
200
  - app/controllers/spree/admin/translations_controller.rb
@@ -203,6 +204,7 @@ files:
203
204
  - app/models/concerns/spree_mobility/translatable.rb
204
205
  - app/overrides/spree/admin/option_types/_option_value_fields/add_translation.rb
205
206
  - app/overrides/spree/admin/option_types/index/add_translation.rb
207
+ - app/overrides/spree/admin/payment_methods/index/add_translation.rb
206
208
  - app/overrides/spree/admin/product_properties/_product_property_fields/add_translation.rb
207
209
  - app/overrides/spree/admin/promotions/index/add_translation_link.rb
208
210
  - app/overrides/spree/admin/properties/index/add_translation.rb
@@ -217,6 +219,7 @@ files:
217
219
  - app/views/spree/admin/translations/_settings.html.erb
218
220
  - app/views/spree/admin/translations/option_type.html.erb
219
221
  - app/views/spree/admin/translations/option_value.html.erb
222
+ - app/views/spree/admin/translations/payment_method.html.erb
220
223
  - app/views/spree/admin/translations/product.html.erb
221
224
  - app/views/spree/admin/translations/product_property.html.erb
222
225
  - app/views/spree/admin/translations/promotion.html.erb
@@ -237,6 +240,7 @@ files:
237
240
  - config/locales/ru.yml
238
241
  - config/locales/zh-TW.yml
239
242
  - config/routes.rb
243
+ - db/migrate/20220309003419_add_translations_to_payment_method.rb
240
244
  - db/migrate/20220411041407_add_translations_to_main_models.rb
241
245
  - db/migrate/20220412095648_remove_null_constraints_from_spree_tables.rb
242
246
  - db/migrate/20220413095648_migrate_translation_data.rb
@@ -248,6 +252,7 @@ files:
248
252
  - lib/spree_mobility/core_ext/mobility/backends/active_record/table/mobility_acts_as_paranoid_decorator.rb
249
253
  - lib/spree_mobility/core_ext/spree/option_type_decorator.rb
250
254
  - lib/spree_mobility/core_ext/spree/option_value_decorator.rb
255
+ - lib/spree_mobility/core_ext/spree/payment_method_decorator.rb
251
256
  - lib/spree_mobility/core_ext/spree/product_decorator.rb
252
257
  - lib/spree_mobility/core_ext/spree/product_property_decorator.rb
253
258
  - lib/spree_mobility/core_ext/spree/product_scopes_with_mobility_decorator.rb