spree_core 4.5.0 → 4.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/finders/spree/countries/find.rb +1 -1
- data/app/finders/spree/option_values/find_available.rb +1 -1
- data/app/finders/spree/product_properties/find_available.rb +1 -1
- data/app/finders/spree/products/find.rb +21 -13
- data/app/finders/spree/taxons/find.rb +7 -10
- data/app/helpers/spree/base_helper.rb +3 -7
- data/app/helpers/spree/products_helper.rb +3 -3
- data/app/models/concerns/spree/metadata.rb +7 -2
- data/app/models/concerns/spree/named_type.rb +1 -1
- data/app/models/concerns/spree/product_scopes.rb +27 -23
- data/app/models/concerns/spree/translatable_resource.rb +25 -0
- data/app/models/concerns/spree/translatable_resource_scopes.rb +24 -0
- data/app/models/concerns/spree/translatable_resource_slug.rb +15 -0
- data/app/models/concerns/spree/user_roles.rb +3 -3
- data/app/models/spree/address.rb +6 -4
- data/app/models/spree/asset.rb +1 -1
- data/app/models/spree/base.rb +6 -1
- data/app/models/spree/calculator/default_tax.rb +1 -1
- data/app/models/spree/cms/sections/image_gallery.rb +1 -7
- data/app/models/spree/cms/sections/side_by_side_images.rb +1 -7
- data/app/models/spree/cms_page.rb +2 -2
- data/app/models/spree/cms_section.rb +1 -1
- data/app/models/spree/country.rb +2 -2
- data/app/models/spree/credit_card.rb +1 -1
- data/app/models/spree/customer_return.rb +2 -2
- data/app/models/spree/data_feed/google.rb +15 -0
- data/app/models/spree/data_feed.rb +40 -0
- data/app/models/spree/digital_link.rb +5 -1
- data/app/models/spree/image.rb +2 -2
- data/app/models/spree/legacy_user.rb +3 -3
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/log_entry.rb +5 -1
- data/app/models/spree/menu.rb +1 -1
- data/app/models/spree/option_type.rb +6 -2
- data/app/models/spree/option_value.rb +5 -1
- data/app/models/spree/order/store_credit.rb +8 -0
- data/app/models/spree/order.rb +9 -9
- data/app/models/spree/order_contents.rb +31 -0
- data/app/models/spree/payment.rb +7 -15
- data/app/models/spree/payment_method.rb +1 -1
- data/app/models/spree/payment_source.rb +1 -1
- data/app/models/spree/preference.rb +5 -1
- data/app/models/spree/price.rb +1 -1
- data/app/models/spree/product.rb +64 -25
- data/app/models/spree/product_property.rb +13 -4
- data/app/models/spree/promotion.rb +2 -2
- data/app/models/spree/property.rb +8 -2
- data/app/models/spree/prototype.rb +1 -1
- data/app/models/spree/refund.rb +1 -1
- data/app/models/spree/reimbursement.rb +1 -1
- data/app/models/spree/return_authorization.rb +1 -1
- data/app/models/spree/return_item.rb +5 -1
- data/app/models/spree/role.rb +1 -1
- data/app/models/spree/shipment.rb +5 -5
- data/app/models/spree/shipping_category.rb +1 -1
- data/app/models/spree/shipping_method.rb +1 -1
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock/splitter/weight.rb +1 -1
- data/app/models/spree/stock_item.rb +1 -1
- data/app/models/spree/stock_location.rb +1 -1
- data/app/models/spree/stock_transfer.rb +3 -3
- data/app/models/spree/store.rb +22 -3
- data/app/models/spree/store_credit.rb +2 -2
- data/app/models/spree/taxon.rb +47 -7
- data/app/models/spree/taxon_image.rb +2 -2
- data/app/models/spree/taxonomy.rb +5 -1
- data/app/models/spree/variant.rb +6 -9
- data/app/models/spree/wishlist.rb +6 -2
- data/app/models/spree/zone.rb +2 -2
- data/app/services/spree/data_feeds/google/optional_attributes.rb +23 -0
- data/app/services/spree/data_feeds/google/optional_sub_attributes.rb +21 -0
- data/app/services/spree/data_feeds/google/products_list.rb +14 -0
- data/app/services/spree/data_feeds/google/required_attributes.rb +67 -0
- data/app/services/spree/data_feeds/google/rss.rb +107 -0
- data/app/services/spree/locales/set_fallback_locale_for_store.rb +16 -0
- data/app/services/spree/seeds/countries.rb +12 -27
- data/app/services/spree/seeds/states.rb +8 -17
- data/app/services/spree/stock_locations/stock_items/create.rb +12 -18
- data/app/sorters/spree/products/sort.rb +23 -0
- data/app/validators/db_maximum_length_validator.rb +2 -6
- data/brakeman.ignore +326 -18
- data/config/initializers/friendly_id.rb +2 -0
- data/config/initializers/mobility.rb +16 -0
- data/config/initializers/rails61_fixes.rb +1 -3
- data/config/locales/en.yml +7 -0
- data/db/migrate/20220706112554_create_product_name_and_description_translations_for_mobility_table_backend.rb +27 -0
- data/db/migrate/20220715083542_create_spree_product_translations_for_mobility.rb +7 -0
- data/db/migrate/20220715120222_change_product_name_null_to_true.rb +5 -0
- data/db/migrate/20220718100743_create_spree_taxon_name_and_description_translations_for_mobility_table_backend.rb +27 -0
- data/db/migrate/20220718100948_change_taxon_name_null_to_true.rb +5 -0
- data/db/migrate/20220802070609_add_locale_to_friendly_id_slugs.rb +11 -0
- data/db/migrate/20220802073225_create_spree_product_slug_translations_for_mobility_table_backend.rb +5 -0
- data/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb +66 -0
- data/db/migrate/20221215151408_add_selected_locale_to_spree_users.rb +8 -0
- data/db/migrate/20221219123957_add_deleted_at_to_product_translations.rb +6 -0
- data/db/migrate/20221220133432_add_uniqueness_constraint_to_product_translations.rb +5 -0
- data/db/migrate/20221229132350_create_spree_data_feed_settings.rb +14 -0
- data/db/migrate/20230103144439_create_option_type_translations.rb +26 -0
- data/db/migrate/20230103151034_create_option_value_translations.rb +26 -0
- data/db/migrate/20230109084253_create_product_property_translations.rb +25 -0
- data/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb +58 -0
- data/db/migrate/20230109105943_create_property_translations.rb +26 -0
- data/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb +59 -0
- data/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb +15 -0
- data/db/migrate/20230111121534_add_additional_taxon_translation_fields.rb +8 -0
- data/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb +82 -0
- data/db/migrate/20230117115531_create_taxonomy_translations.rb +24 -0
- data/db/migrate/20230117120430_allow_null_taxonomy_name.rb +5 -0
- data/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb +11 -0
- data/db/migrate/20230210142732_create_store_translations.rb +50 -0
- data/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb +11 -0
- data/db/migrate/20230210230434_add_deleted_at_to_store_translations.rb +6 -0
- data/db/migrate/20230415155958_rename_data_feed_settings_table.rb +5 -0
- data/db/migrate/20230415160828_rename_data_feed_table_columns.rb +7 -0
- data/db/migrate/20230415161226_add_indexes_to_data_feeds_table.rb +5 -0
- data/db/migrate/20230512094803_rename_data_feeds_column_provider_to_type.rb +5 -0
- data/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb +5 -0
- data/lib/mobility/plugins/store_based_fallbacks.rb +55 -0
- data/lib/spree/core/configuration.rb +2 -1
- data/lib/spree/core/controller_helpers/auth.rb +1 -1
- data/lib/spree/core/controller_helpers/common.rb +5 -5
- data/lib/spree/core/controller_helpers/locale.rb +33 -2
- data/lib/spree/core/dependencies.rb +70 -94
- data/lib/spree/core/dependencies_helper.rb +19 -0
- data/lib/spree/core/engine.rb +7 -1
- data/lib/spree/core/preferences/preferable_class_methods.rb +1 -1
- data/lib/spree/core/product_duplicator.rb +4 -1
- data/lib/spree/core/product_filters.rb +7 -4
- data/lib/spree/core/search/base.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +2 -0
- data/lib/spree/permitted_attributes.rb +1 -1
- data/lib/spree/testing_support/controller_requests.rb +10 -10
- data/lib/spree/testing_support/factories/google_data_feed_factory.rb +8 -0
- data/lib/spree/testing_support/factories/product_factory.rb +6 -0
- data/lib/spree/testing_support/factories/product_translation_factory.rb +6 -0
- data/lib/spree/testing_support/factories/store_factory.rb +3 -0
- data/lib/spree/testing_support/factories/variant_factory.rb +4 -0
- data/lib/spree/translation_migrations.rb +40 -0
- data/lib/spree_core.rb +1 -0
- data/spree_core.gemspec +6 -3
- metadata +147 -14
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSpreeDataFeedSettings < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :spree_data_feed_settings do |t|
|
4
|
+
t.references :spree_store
|
5
|
+
|
6
|
+
t.string :name
|
7
|
+
t.string :provider
|
8
|
+
t.string :uuid, unique: true
|
9
|
+
t.boolean :enabled, default: true
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateOptionTypeTranslations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
if ActiveRecord::Base.connection.table_exists? 'spree_option_type_translations'
|
4
|
+
# manually check for index since Rails if_exists does not always work correctly
|
5
|
+
if ActiveRecord::Migration.connection.index_exists?(:spree_option_type_translations, :spree_option_type_id)
|
6
|
+
remove_index :spree_option_type_translations, name: "index_spree_option_type_translations_on_spree_option_type_id", if_exists: true
|
7
|
+
end
|
8
|
+
else
|
9
|
+
create_table :spree_option_type_translations do |t|
|
10
|
+
|
11
|
+
# Translated attribute(s)
|
12
|
+
t.string :name
|
13
|
+
t.string :presentation
|
14
|
+
|
15
|
+
t.string :locale, null: false
|
16
|
+
t.references :spree_option_type, null: false, foreign_key: true, index: false
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :spree_option_type_translations, :locale, name: :index_spree_option_type_translations_on_locale
|
22
|
+
end
|
23
|
+
|
24
|
+
add_index :spree_option_type_translations, [:spree_option_type_id, :locale], name: :unique_option_type_id_per_locale, unique: true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateOptionValueTranslations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
if ActiveRecord::Base.connection.table_exists? 'spree_option_value_translations'
|
4
|
+
# manually check for index since Rails if_exists does not always work correctly
|
5
|
+
if ActiveRecord::Migration.connection.index_exists?(:spree_option_value_translations, :spree_option_value_id)
|
6
|
+
remove_index :spree_option_value_translations, column: :spree_option_value_id, if_exists: true
|
7
|
+
end
|
8
|
+
else
|
9
|
+
create_table :spree_option_value_translations do |t|
|
10
|
+
|
11
|
+
# Translated attribute(s)
|
12
|
+
t.string :name
|
13
|
+
t.string :presentation
|
14
|
+
|
15
|
+
t.string :locale, null: false
|
16
|
+
t.references :spree_option_value, null: false, foreign_key: true, index: false
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :spree_option_value_translations, :locale, name: :index_spree_option_value_translations_on_locale
|
22
|
+
end
|
23
|
+
|
24
|
+
add_index :spree_option_value_translations, [:spree_option_value_id, :locale], name: :unique_option_value_id_per_locale, unique: true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class CreateProductPropertyTranslations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
if ActiveRecord::Base.connection.table_exists? 'spree_product_property_translations'
|
4
|
+
# manually check for index since Rails if_exists does not always work correctly
|
5
|
+
if ActiveRecord::Migration.connection.index_exists?(:spree_product_property_translations, :spree_product_property_id)
|
6
|
+
remove_index :spree_product_property_translations, column: :spree_product_property_id, if_exists: true
|
7
|
+
end
|
8
|
+
else
|
9
|
+
create_table :spree_product_property_translations do |t|
|
10
|
+
# Translated attribute(s)
|
11
|
+
t.string :value
|
12
|
+
t.string :filter_param
|
13
|
+
|
14
|
+
t.string :locale, null: false
|
15
|
+
t.references :spree_product_property, null: false, foreign_key: true, index: false
|
16
|
+
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
|
20
|
+
add_index :spree_product_property_translations, :locale, name: :index_spree_product_property_translations_on_locale
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index :spree_product_property_translations, [:spree_product_property_id, :locale], name: :unique_product_property_id_per_locale, unique: true
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class TransferOptionsDataToTranslatableTables < ActiveRecord::Migration[6.1]
|
2
|
+
DEFAULT_LOCALE = 'en'
|
3
|
+
|
4
|
+
def up
|
5
|
+
# Only transfer data if translation tables are being newly created / no translations exist
|
6
|
+
# Otherwise, assume translation data is already in place from spree_globalize
|
7
|
+
|
8
|
+
# Option Types
|
9
|
+
if not Spree::OptionType::Translation.exists?
|
10
|
+
ActiveRecord::Base.connection.execute("
|
11
|
+
INSERT INTO spree_option_type_translations (name, presentation, locale, spree_option_type_id, created_at, updated_at)
|
12
|
+
SELECT name, presentation, '#{DEFAULT_LOCALE}', id, created_at, updated_at
|
13
|
+
FROM spree_option_types;
|
14
|
+
")
|
15
|
+
ActiveRecord::Base.connection.execute("
|
16
|
+
UPDATE spree_option_types
|
17
|
+
SET name=null, presentation=null;
|
18
|
+
")
|
19
|
+
end
|
20
|
+
|
21
|
+
# Option Values
|
22
|
+
if not Spree::OptionValue::Translation.exists?
|
23
|
+
ActiveRecord::Base.connection.execute("
|
24
|
+
INSERT INTO spree_option_value_translations (name, presentation, locale, spree_option_value_id, created_at, updated_at)
|
25
|
+
SELECT name, presentation, '#{DEFAULT_LOCALE}', id, created_at, updated_at
|
26
|
+
FROM spree_option_values;
|
27
|
+
")
|
28
|
+
ActiveRecord::Base.connection.execute("
|
29
|
+
UPDATE spree_option_values
|
30
|
+
SET name=null, presentation=null;
|
31
|
+
")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def down
|
36
|
+
# Option Types
|
37
|
+
ActiveRecord::Base.connection.execute("
|
38
|
+
UPDATE spree_option_types as option_types
|
39
|
+
SET (name, presentation) = (t_option_types.name, t_option_types.presentation)
|
40
|
+
FROM spree_option_type_translations AS t_option_types
|
41
|
+
WHERE t_option_types.spree_option_type_id = option_types.id;
|
42
|
+
")
|
43
|
+
ActiveRecord::Base.connection.execute("
|
44
|
+
TRUNCATE TABLE spree_option_type_translations;
|
45
|
+
")
|
46
|
+
|
47
|
+
# Option Values
|
48
|
+
ActiveRecord::Base.connection.execute("
|
49
|
+
UPDATE spree_option_values as option_values
|
50
|
+
SET (name, presentation) = (t_option_values.name, t_option_values.presentation)
|
51
|
+
FROM spree_option_value_translations AS t_option_values
|
52
|
+
WHERE t_option_values.spree_option_value_id = option_values.id;
|
53
|
+
")
|
54
|
+
ActiveRecord::Base.connection.execute("
|
55
|
+
TRUNCATE TABLE spree_option_value_translations;
|
56
|
+
")
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreatePropertyTranslations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
if ActiveRecord::Base.connection.table_exists?('spree_property_translations')
|
4
|
+
# manually check for index since Rails if_exists does not always work correctly
|
5
|
+
if ActiveRecord::Migration.connection.index_exists?(:spree_property_translations, :spree_property_id)
|
6
|
+
remove_index :spree_property_translations, column: :spree_property_id, if_exists: true
|
7
|
+
end
|
8
|
+
else
|
9
|
+
create_table :spree_property_translations do |t|
|
10
|
+
# Translated attribute(s)
|
11
|
+
t.string :name
|
12
|
+
t.string :presentation
|
13
|
+
t.string :filter_param
|
14
|
+
|
15
|
+
t.string :locale, null: false
|
16
|
+
t.references :spree_property, null: false, foreign_key: true, index: false
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index :spree_property_translations, :locale, name: :index_spree_property_translations_on_locale
|
22
|
+
end
|
23
|
+
|
24
|
+
add_index :spree_property_translations, [:spree_property_id, :locale], name: :unique_property_id_per_locale, unique: true
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class TransferPropertyDataToTranslatableTables < ActiveRecord::Migration[6.1]
|
2
|
+
DEFAULT_LOCALE = 'en'
|
3
|
+
|
4
|
+
def up
|
5
|
+
# Properties
|
6
|
+
change_column_null :spree_properties, :presentation, true
|
7
|
+
|
8
|
+
if not Spree::Property::Translation.exists?
|
9
|
+
ActiveRecord::Base.connection.execute("
|
10
|
+
INSERT INTO spree_property_translations (name, presentation, filter_param, locale, spree_property_id, created_at, updated_at)
|
11
|
+
SELECT name, presentation, filter_param, '#{DEFAULT_LOCALE}', id, created_at, updated_at
|
12
|
+
FROM spree_properties;
|
13
|
+
")
|
14
|
+
ActiveRecord::Base.connection.execute("
|
15
|
+
UPDATE spree_properties
|
16
|
+
SET name=null, presentation=null, filter_param=null;
|
17
|
+
")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Product Properties
|
21
|
+
if not Spree::ProductProperty::Translation.exists?
|
22
|
+
ActiveRecord::Base.connection.execute("
|
23
|
+
INSERT INTO spree_product_property_translations (value, filter_param, locale, spree_product_property_id, created_at, updated_at)
|
24
|
+
SELECT value, filter_param, '#{DEFAULT_LOCALE}', id, created_at, updated_at
|
25
|
+
FROM spree_product_properties;
|
26
|
+
")
|
27
|
+
ActiveRecord::Base.connection.execute("
|
28
|
+
UPDATE spree_product_properties
|
29
|
+
SET value=null, filter_param=null;
|
30
|
+
")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def down
|
35
|
+
# Properties
|
36
|
+
change_column_null :spree_properties, :presentation, false
|
37
|
+
|
38
|
+
ActiveRecord::Base.connection.execute("
|
39
|
+
UPDATE spree_properties AS properties
|
40
|
+
SET (name, presentation, filter_param) = (t_properties.name, t_properties.presentation, t_properties.filter_param)
|
41
|
+
FROM spree_property_translations AS t_properties
|
42
|
+
WHERE t_properties.spree_property_id = properties.id;
|
43
|
+
")
|
44
|
+
ActiveRecord::Base.connection.execute("
|
45
|
+
TRUNCATE TABLE spree_property_translations;
|
46
|
+
")
|
47
|
+
|
48
|
+
# Product Properties
|
49
|
+
ActiveRecord::Base.connection.execute("
|
50
|
+
UPDATE spree_product_properties AS product_properties
|
51
|
+
SET (value, filter_param) = (t_product_properties.value, t_product_properties.filter_param)
|
52
|
+
FROM spree_product_property_translations AS t_product_properties
|
53
|
+
WHERE t_product_properties.spree_product_property_id = product_properties.id;
|
54
|
+
")
|
55
|
+
ActiveRecord::Base.connection.execute("
|
56
|
+
TRUNCATE TABLE spree_product_property_translations;
|
57
|
+
")
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class BackfillFriendlyIdSlugLocale < ActiveRecord::Migration[6.1]
|
2
|
+
DEFAULT_LOCALE = 'en'
|
3
|
+
|
4
|
+
def up
|
5
|
+
ActiveRecord::Base.connection.execute("
|
6
|
+
UPDATE friendly_id_slugs SET locale = '#{DEFAULT_LOCALE}'
|
7
|
+
")
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
ActiveRecord::Base.connection.execute("
|
12
|
+
UPDATE friendly_id_slugs SET locale = NULL
|
13
|
+
")
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddAdditionalTaxonTranslationFields < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
add_column :spree_taxon_translations, :meta_title, :string, if_not_exists: true
|
4
|
+
add_column :spree_taxon_translations, :meta_description, :string, if_not_exists: true
|
5
|
+
add_column :spree_taxon_translations, :meta_keywords, :string, if_not_exists: true
|
6
|
+
add_column :spree_taxon_translations, :permalink, :string, if_not_exists: true
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
class TransferProductAndTaxonDataToTranslatableTables < ActiveRecord::Migration[6.1]
|
2
|
+
DEFAULT_LOCALE = 'en'
|
3
|
+
PRODUCTS_TABLE = 'spree_products'
|
4
|
+
PRODUCT_TRANSLATIONS_TABLE = 'spree_product_translations'
|
5
|
+
TAXONS_TABLE = 'spree_taxons'
|
6
|
+
TAXON_TRANSLATIONS_TABLE = 'spree_taxon_translations'
|
7
|
+
|
8
|
+
def up
|
9
|
+
# Only transfer data if translation tables are being newly created / no translations exist
|
10
|
+
# Otherwise, assume translation data is already in place from spree_globalize
|
11
|
+
|
12
|
+
# Products
|
13
|
+
if not Spree::Product::Translation.exists?
|
14
|
+
ActiveRecord::Base.connection.execute("
|
15
|
+
INSERT INTO #{PRODUCT_TRANSLATIONS_TABLE} (name, description, locale, spree_product_id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug)
|
16
|
+
SELECT name, description, '#{DEFAULT_LOCALE}' as locale, id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug FROM #{PRODUCTS_TABLE};
|
17
|
+
")
|
18
|
+
ActiveRecord::Base.connection.execute("
|
19
|
+
UPDATE #{PRODUCTS_TABLE}
|
20
|
+
SET name=null, description=null, meta_description=null, meta_keywords=null, meta_title=null, slug=null;
|
21
|
+
")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Taxons
|
25
|
+
if not Spree::Taxon::Translation.exists?
|
26
|
+
ActiveRecord::Base.connection.execute("
|
27
|
+
INSERT INTO #{TAXON_TRANSLATIONS_TABLE} (name, description, meta_title, meta_description, meta_keywords, permalink, locale, spree_taxon_id, created_at, updated_at)
|
28
|
+
SELECT name, description, meta_title, meta_description, meta_keywords, permalink, '#{DEFAULT_LOCALE}' as locale, id, created_at, updated_at FROM #{TAXONS_TABLE};
|
29
|
+
")
|
30
|
+
ActiveRecord::Base.connection.execute("
|
31
|
+
UPDATE #{TAXONS_TABLE}
|
32
|
+
SET name=null, description=null, meta_title=null, meta_description=null, meta_keywords=null, permalink=null;
|
33
|
+
")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def down
|
38
|
+
ActiveRecord::Base.connection.execute("
|
39
|
+
UPDATE #{PRODUCTS_TABLE} as products
|
40
|
+
SET (name,
|
41
|
+
description,
|
42
|
+
meta_description,
|
43
|
+
meta_keywords,
|
44
|
+
meta_title,
|
45
|
+
slug) =
|
46
|
+
(t_products.name,
|
47
|
+
t_products.description,
|
48
|
+
t_products.meta_description,
|
49
|
+
t_products.meta_keywords,
|
50
|
+
t_products.meta_title,
|
51
|
+
t_products.slug)
|
52
|
+
FROM #{PRODUCT_TRANSLATIONS_TABLE} AS t_products
|
53
|
+
WHERE t_products.spree_product_id = products.id
|
54
|
+
")
|
55
|
+
|
56
|
+
ActiveRecord::Base.connection.execute("
|
57
|
+
TRUNCATE TABLE #{PRODUCT_TRANSLATIONS_TABLE}
|
58
|
+
")
|
59
|
+
|
60
|
+
ActiveRecord::Base.connection.execute("
|
61
|
+
UPDATE #{TAXONS_TABLE} as taxons
|
62
|
+
SET (name,
|
63
|
+
description,
|
64
|
+
meta_title,
|
65
|
+
meta_description,
|
66
|
+
meta_keywords,
|
67
|
+
permalink) =
|
68
|
+
(t_taxons.name,
|
69
|
+
t_taxons.description,
|
70
|
+
t_taxons.meta_title,
|
71
|
+
t_taxons.meta_description,
|
72
|
+
t_taxons.meta_keywords,
|
73
|
+
t_taxons.permalink)
|
74
|
+
FROM #{TAXON_TRANSLATIONS_TABLE} AS t_taxons
|
75
|
+
WHERE t_taxons.spree_taxon_id = taxons.id
|
76
|
+
")
|
77
|
+
|
78
|
+
ActiveRecord::Base.connection.execute("
|
79
|
+
TRUNCATE TABLE #{TAXON_TRANSLATIONS_TABLE}
|
80
|
+
")
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateTaxonomyTranslations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
if ActiveRecord::Base.connection.table_exists?('spree_taxonomy_translations')
|
4
|
+
# manually check for index since Rails if_exists does not always work correctly
|
5
|
+
if ActiveRecord::Migration.connection.index_exists?(:spree_taxonomy_translations, :spree_taxonomy_id)
|
6
|
+
remove_index :spree_taxonomy_translations, column: :spree_taxonomy_id, if_exists: true
|
7
|
+
end
|
8
|
+
else
|
9
|
+
create_table :spree_taxonomy_translations do |t|
|
10
|
+
# Translated attribute(s)
|
11
|
+
t.string :name
|
12
|
+
|
13
|
+
t.string :locale, null: false
|
14
|
+
t.references :spree_taxonomy, null: false, foreign_key: true, index: false
|
15
|
+
|
16
|
+
t.timestamps null: false
|
17
|
+
end
|
18
|
+
|
19
|
+
add_index :spree_taxonomy_translations, :locale, name: :index_spree_taxonomy_translations_on_locale
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :spree_taxonomy_translations, [:spree_taxonomy_id, :locale], name: :index_spree_taxonomy_translations_on_spree_taxonomy_id_locale, unique: true
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class TransferTaxonomyDataToTranslatableTables < ActiveRecord::Migration[6.1]
|
2
|
+
TRANSLATION_MIGRATION = Spree::TranslationMigrations.new(Spree::Taxonomy, 'en')
|
3
|
+
|
4
|
+
def up
|
5
|
+
TRANSLATION_MIGRATION.transfer_translation_data
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
TRANSLATION_MIGRATION.revert_translation_data_transfer
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class CreateStoreTranslations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
if ActiveRecord::Base.connection.table_exists?('spree_store_translations')
|
4
|
+
add_new_translation_columns_to_globalize_table
|
5
|
+
else
|
6
|
+
create_table :spree_store_translations do |t|
|
7
|
+
# Translated attribute(s)
|
8
|
+
t.string :name
|
9
|
+
t.text :meta_description
|
10
|
+
t.text :meta_keywords
|
11
|
+
t.string :seo_title
|
12
|
+
t.string :facebook
|
13
|
+
t.string :twitter
|
14
|
+
t.string :instagram
|
15
|
+
t.string :customer_support_email
|
16
|
+
t.text :description
|
17
|
+
t.text :address
|
18
|
+
t.string :contact_phone
|
19
|
+
t.string :new_order_notifications_email
|
20
|
+
|
21
|
+
t.string :locale, null: false
|
22
|
+
t.references :spree_store, null: false, foreign_key: true, index: false
|
23
|
+
|
24
|
+
t.timestamps null: false
|
25
|
+
end
|
26
|
+
|
27
|
+
add_index :spree_store_translations, :locale, name: :index_spree_store_translations_on_locale
|
28
|
+
end
|
29
|
+
|
30
|
+
add_index :spree_store_translations, [:spree_store_id, :locale], name: :index_spree_store_translations_on_spree_store_id_locale, unique: true
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def add_new_translation_columns_to_globalize_table
|
36
|
+
# manually check for index since Rails if_exists does not always work correctly
|
37
|
+
if ActiveRecord::Migration.connection.index_exists?(:spree_store_translations, :spree_store_id)
|
38
|
+
remove_index :spree_store_translations, column: :spree_store_id, if_exists: true
|
39
|
+
end
|
40
|
+
|
41
|
+
add_column :spree_store_translations, :facebook, :string
|
42
|
+
add_column :spree_store_translations, :twitter, :string
|
43
|
+
add_column :spree_store_translations, :instagram, :string
|
44
|
+
add_column :spree_store_translations, :customer_support_email, :string
|
45
|
+
add_column :spree_store_translations, :description, :text
|
46
|
+
add_column :spree_store_translations, :address, :text
|
47
|
+
add_column :spree_store_translations, :contact_phone, :string
|
48
|
+
add_column :spree_store_translations, :new_order_notifications_email, :string
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class TransferStoreDataToTranslatableTables < ActiveRecord::Migration[6.1]
|
2
|
+
TRANSLATION_MIGRATION = Spree::TranslationMigrations.new(Spree::Store, 'en')
|
3
|
+
|
4
|
+
def up
|
5
|
+
TRANSLATION_MIGRATION.transfer_translation_data
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
TRANSLATION_MIGRATION.revert_translation_data_transfer
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'concurrent'
|
4
|
+
require 'mobility'
|
5
|
+
|
6
|
+
# The default implementation in the Mobility gem requires fallbacks to be defined when booting the application.
|
7
|
+
# This patch allows to dynamically reconfigure translations fallbacks, by setting Mobility.store_based_fallbacks attribute.
|
8
|
+
# The implementation is based on the default fallbacks plugin, with some changes around fetching the list of fallbacks to be used.
|
9
|
+
# https://github.com/shioyama/mobility/blob/master/lib/mobility/plugins/fallbacks.rb
|
10
|
+
module Mobility
|
11
|
+
@store_based_fallbacks = Concurrent::ThreadLocalVar.new(I18n::Locale::Fallbacks.new)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def store_based_fallbacks
|
15
|
+
@store_based_fallbacks.value
|
16
|
+
end
|
17
|
+
|
18
|
+
def store_based_fallbacks=(value)
|
19
|
+
@store_based_fallbacks.value = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Plugins
|
24
|
+
module StoreBasedFallbacks
|
25
|
+
extend ::Mobility::Plugin
|
26
|
+
|
27
|
+
default true
|
28
|
+
requires :backend, include: :before
|
29
|
+
|
30
|
+
# Applies fallbacks plugin to attributes. Completely disables fallbacks
|
31
|
+
# on model if option is +false+.
|
32
|
+
included_hook do |_, backend_class|
|
33
|
+
unless options[:fallbacks] == false
|
34
|
+
backend_class.include(BackendInstanceMethods)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module BackendInstanceMethods
|
39
|
+
def read(locale, fallback: true, **kwargs)
|
40
|
+
return super(locale, **kwargs) if !fallback || kwargs[:locale]
|
41
|
+
|
42
|
+
locales = Mobility.store_based_fallbacks[locale]
|
43
|
+
locales.each do |fallback_locale|
|
44
|
+
value = super(fallback_locale, **kwargs)
|
45
|
+
return value if Util.present?(value)
|
46
|
+
end
|
47
|
+
|
48
|
+
super(locale, **kwargs)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
register_plugin(:store_based_fallbacks, StoreBasedFallbacks)
|
54
|
+
end
|
55
|
+
end
|
@@ -65,6 +65,7 @@ module Spree
|
|
65
65
|
preference :show_raw_product_description, :boolean, deprecated: true
|
66
66
|
preference :tax_using_ship_address, :boolean, default: true
|
67
67
|
preference :track_inventory_levels, :boolean, default: true # Determines whether to track on_hand values for variants / products.
|
68
|
+
preference :use_user_locale, :boolean, default: true
|
68
69
|
|
69
70
|
# Store credits configurations
|
70
71
|
preference :non_expiring_credit_types, :array, default: []
|
@@ -75,7 +76,7 @@ module Spree
|
|
75
76
|
|
76
77
|
# searcher_class allows spree extension writers to provide their own Search class
|
77
78
|
def searcher_class
|
78
|
-
|
79
|
+
Spree::Deprecation.warn('`Spree::Config.searcher_class` is deprecated and will be removed in Spree v5, please use `Spree.searcher_class` instead.')
|
79
80
|
@searcher_class ||= Spree.searcher_class
|
80
81
|
end
|
81
82
|
|
@@ -75,7 +75,7 @@ module Spree
|
|
75
75
|
# Override this method in your controllers if you want to have special behavior in case the user is not authorized
|
76
76
|
# to access the requested action. For example, a popup window might simply close itself.
|
77
77
|
def redirect_unauthorized_access
|
78
|
-
|
78
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
79
79
|
Core::ControllerHelpers#redirect_unauthorized_access is deprecated and will be removed in Spree 5.0.
|
80
80
|
This method is implemented differently for Storefront and Admin
|
81
81
|
DEPRECATION
|
@@ -17,7 +17,7 @@ module Spree
|
|
17
17
|
attr_writer :title
|
18
18
|
|
19
19
|
def title
|
20
|
-
|
20
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
21
21
|
ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.
|
22
22
|
DEPRECATION
|
23
23
|
title_string = @title.present? ? @title : accurate_title
|
@@ -33,7 +33,7 @@ module Spree
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def default_title
|
36
|
-
|
36
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
37
37
|
ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.
|
38
38
|
DEPRECATION
|
39
39
|
current_store.name
|
@@ -41,7 +41,7 @@ module Spree
|
|
41
41
|
|
42
42
|
# this is a hook for subclasses to provide title
|
43
43
|
def accurate_title
|
44
|
-
|
44
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
45
45
|
ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.
|
46
46
|
DEPRECATION
|
47
47
|
current_store.seo_title
|
@@ -50,7 +50,7 @@ module Spree
|
|
50
50
|
private
|
51
51
|
|
52
52
|
def set_user_language
|
53
|
-
|
53
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
54
54
|
ControllerHelpers::Common#set_user_language is deprecated and will be removed in Spree 5.0.
|
55
55
|
Please use `before_action :set_locale` instead
|
56
56
|
DEPRECATION
|
@@ -65,7 +65,7 @@ module Spree
|
|
65
65
|
# Default layout is: +app/views/spree/layouts/spree_application+
|
66
66
|
#
|
67
67
|
def get_layout
|
68
|
-
|
68
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
69
69
|
ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.
|
70
70
|
DEPRECATION
|
71
71
|
return unless defined?(Spree::Frontend)
|