spree_core 4.5.0 → 4.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 96a1ab3dd325e2cd0053b0ad881b73ddb153624fd04dba62dd61d4e01ab2aca4
|
|
4
|
+
data.tar.gz: 1e947a1bba157dd1df4ba6773d869675da4bffa856f4f1c57f63a4c7b5a592aa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6307ed6baf1241414853b53c6528f08448fb465fcdd4603e96f29aaf507fa2188a7f481f4e000b5ec9370e7894c49680ad86ad61d39b1c2e36d7735988c36c95
|
|
7
|
+
data.tar.gz: 1d75cd60145ae2fe99f9d9a8e2c13cd7c3b9026847b561c31299ce1bbd0596c7f4e14499e01f658dfe0e8c87e5335ee718d6983213d8ac1d8338a3300836d1f3
|
|
@@ -8,7 +8,7 @@ module Spree
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def call
|
|
11
|
-
|
|
11
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
12
12
|
Spree::Countries::Find.new.call is deprecated and will be removed in Spree 5.0.
|
|
13
13
|
Please use Spree::Countries::Find.new.execute instead
|
|
14
14
|
DEPRECATION
|
|
@@ -5,7 +5,7 @@ module Spree
|
|
|
5
5
|
@scope = scope
|
|
6
6
|
|
|
7
7
|
if current_currency.present?
|
|
8
|
-
|
|
8
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
9
9
|
`current_currency` param is deprecated and will be removed in Spree 5.
|
|
10
10
|
Please pass `:currency` in `params` hash instead.
|
|
11
11
|
DEPRECATION
|
|
@@ -146,7 +146,10 @@ module Spree
|
|
|
146
146
|
def by_name(products)
|
|
147
147
|
return products unless name?
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
product_name = name
|
|
150
|
+
|
|
151
|
+
# i18n mobility scope doesn't automatically get set for query blocks (Mobility issue #599) - set it explicitly
|
|
152
|
+
products.i18n { name.matches("%#{product_name}%") }
|
|
150
153
|
end
|
|
151
154
|
|
|
152
155
|
def by_options(products)
|
|
@@ -183,7 +186,7 @@ module Spree
|
|
|
183
186
|
|
|
184
187
|
next if values.empty?
|
|
185
188
|
|
|
186
|
-
ids =
|
|
189
|
+
ids = scope.unscope(:order, :includes).with_property_values(property_filter_param, values).ids
|
|
187
190
|
product_ids = index == 0 ? ids : product_ids & ids
|
|
188
191
|
index += 1
|
|
189
192
|
end
|
|
@@ -209,21 +212,19 @@ module Spree
|
|
|
209
212
|
products
|
|
210
213
|
end
|
|
211
214
|
when 'name-a-z'
|
|
212
|
-
|
|
215
|
+
# workaround for Mobility issue #596 - explicitly select fields to avoid error when selecting distinct
|
|
216
|
+
products.i18n.
|
|
217
|
+
select("#{Product.table_name}.*").select(:name).order(name: :asc)
|
|
213
218
|
when 'name-z-a'
|
|
214
|
-
|
|
219
|
+
# workaround for Mobility issue #596
|
|
220
|
+
products.i18n.
|
|
221
|
+
select("#{Product.table_name}.*").select(:name).order(name: :desc)
|
|
215
222
|
when 'newest-first'
|
|
216
223
|
products.order(available_on: :desc)
|
|
217
224
|
when 'price-high-to-low'
|
|
218
|
-
products
|
|
219
|
-
select("#{Product.table_name}.*, #{Spree::Price.table_name}.amount").
|
|
220
|
-
reorder('').
|
|
221
|
-
send(:descend_by_master_price)
|
|
225
|
+
order_by_price(products, :descend_by_master_price)
|
|
222
226
|
when 'price-low-to-high'
|
|
223
|
-
products
|
|
224
|
-
select("#{Product.table_name}.*, #{Spree::Price.table_name}.amount").
|
|
225
|
-
reorder('').
|
|
226
|
-
send(:ascend_by_master_price)
|
|
227
|
+
order_by_price(products, :ascend_by_master_price)
|
|
227
228
|
end
|
|
228
229
|
end
|
|
229
230
|
|
|
@@ -265,6 +266,13 @@ module Spree
|
|
|
265
266
|
taxons = store.taxons.where(id: taxons_ids.to_s.split(','))
|
|
266
267
|
taxons.map(&:cached_self_and_descendants_ids).flatten.compact.uniq.map(&:to_s)
|
|
267
268
|
end
|
|
269
|
+
|
|
270
|
+
def order_by_price(scope, order_type)
|
|
271
|
+
scope.
|
|
272
|
+
select("#{Product.table_name}.*, #{Spree::Price.table_name}.amount").
|
|
273
|
+
reorder('').
|
|
274
|
+
send(order_type)
|
|
275
|
+
end
|
|
268
276
|
end
|
|
269
277
|
end
|
|
270
278
|
end
|
|
@@ -50,10 +50,6 @@ module Spree
|
|
|
50
50
|
name.present?
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def name_matcher
|
|
54
|
-
Spree::Taxon.arel_table[:name].matches("%#{name}%")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
53
|
def by_ids(taxons)
|
|
58
54
|
return taxons unless ids?
|
|
59
55
|
|
|
@@ -69,11 +65,9 @@ module Spree
|
|
|
69
65
|
def by_parent_permalink(taxons)
|
|
70
66
|
return taxons unless parent_permalink?
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
taxons.joins("INNER JOIN #{Spree::Taxon.table_name} AS parent_taxon ON parent_taxon.id = #{Spree::Taxon.table_name}.parent_id").where(["parent_taxon.permalink = ?", parent_permalink])
|
|
76
|
-
end
|
|
68
|
+
taxons.joins(:parent).
|
|
69
|
+
join_translation_table(Taxon, 'parents_spree_taxons').
|
|
70
|
+
where(["#{Taxon.translation_table_alias}.permalink = ?", parent_permalink])
|
|
77
71
|
end
|
|
78
72
|
|
|
79
73
|
def by_taxonomy(taxons)
|
|
@@ -91,7 +85,10 @@ module Spree
|
|
|
91
85
|
def by_name(taxons)
|
|
92
86
|
return taxons unless name?
|
|
93
87
|
|
|
94
|
-
|
|
88
|
+
taxon_name = name
|
|
89
|
+
|
|
90
|
+
# i18n mobility scope doesn't automatically get set for query blocks (Mobility issue #599) - set it explicitly
|
|
91
|
+
taxons.i18n { name.matches("%#{taxon_name}%") }
|
|
95
92
|
end
|
|
96
93
|
end
|
|
97
94
|
end
|
|
@@ -55,7 +55,7 @@ module Spree
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def logo(image_path = nil, options = {})
|
|
58
|
-
|
|
58
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
59
59
|
`BaseHelper#logo` is deprecated and will be removed in Spree 5.0.
|
|
60
60
|
Please use `FrontendHelper#logo` instead
|
|
61
61
|
DEPRECATION
|
|
@@ -113,8 +113,8 @@ module Spree
|
|
|
113
113
|
meta = {}
|
|
114
114
|
|
|
115
115
|
if object.is_a? ApplicationRecord
|
|
116
|
-
meta[:keywords] = object.meta_keywords if object
|
|
117
|
-
meta[:description] = object.meta_description if object
|
|
116
|
+
meta[:keywords] = object.meta_keywords if object.try(:meta_keywords).present?
|
|
117
|
+
meta[:description] = object.meta_description if object.try(:meta_description).present?
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
if meta[:description].blank? && object.is_a?(Spree::Product)
|
|
@@ -174,10 +174,6 @@ module Spree
|
|
|
174
174
|
Spree::Core::Engine.frontend_available?
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
-
def rails_5?
|
|
178
|
-
Rails::VERSION::STRING < '6.0'
|
|
179
|
-
end
|
|
180
|
-
|
|
181
177
|
def spree_storefront_resource_url(resource, options = {})
|
|
182
178
|
if defined?(locale_param) && locale_param.present?
|
|
183
179
|
options.merge!(locale: locale_param)
|
|
@@ -53,7 +53,7 @@ module Spree
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def cache_key_for_products(products = @products, additional_cache_key = nil)
|
|
56
|
-
max_updated_at = (products.except(:group, :order).maximum(:updated_at) || Date.today).
|
|
56
|
+
max_updated_at = (products.except(:group, :order).maximum(:updated_at) || Date.today).to_formatted_s(:number)
|
|
57
57
|
products_cache_keys = "spree/products/#{products.map(&:id).join('-')}-#{params[:page]}-#{params[:sort_by]}-#{max_updated_at}-#{@taxon&.id}"
|
|
58
58
|
(common_product_cache_keys + [products_cache_keys] + [additional_cache_key]).compact.join('/')
|
|
59
59
|
end
|
|
@@ -76,7 +76,7 @@ module Spree
|
|
|
76
76
|
|
|
77
77
|
# will return a human readable string
|
|
78
78
|
def available_status(product)
|
|
79
|
-
|
|
79
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
80
80
|
`Spree::ProductsHelper#available_status` method from spree/core is deprecated and will be removed.
|
|
81
81
|
Please use `Spree::Admin::ProductsHelper#available_status` from spree_backend instead.
|
|
82
82
|
DEPRECATION
|
|
@@ -140,7 +140,7 @@ module Spree
|
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
def related_products
|
|
143
|
-
|
|
143
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
144
144
|
ProductsHelper#related_products is deprecated and will be removed in Spree 5.0.
|
|
145
145
|
Please use ProductsHelper#relations from now on.
|
|
146
146
|
DEPRECATION
|
|
@@ -5,8 +5,13 @@ module Spree
|
|
|
5
5
|
included do
|
|
6
6
|
attribute :public_metadata, default: {}
|
|
7
7
|
attribute :private_metadata, default: {}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if Rails::VERSION::STRING >= '7.1.0'
|
|
9
|
+
serialize :public_metadata, coder: HashSerializer
|
|
10
|
+
serialize :private_metadata, coder: HashSerializer
|
|
11
|
+
else
|
|
12
|
+
serialize :public_metadata, HashSerializer
|
|
13
|
+
serialize :private_metadata, HashSerializer
|
|
14
|
+
end
|
|
10
15
|
end
|
|
11
16
|
|
|
12
17
|
# https://nandovieira.com/using-postgresql-and-jsonb-with-ruby-on-rails
|
|
@@ -32,15 +32,16 @@ module Spree
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def self.property_conditions(property)
|
|
35
|
-
|
|
35
|
+
properties_table = Property.table_name
|
|
36
|
+
property_translations_table = Property.translation_table_alias
|
|
36
37
|
case property
|
|
37
|
-
when Property then { "#{
|
|
38
|
-
when Integer then { "#{
|
|
38
|
+
when Property then { "#{properties_table}.id" => property.id }
|
|
39
|
+
when Integer then { "#{properties_table}.id" => property }
|
|
39
40
|
else
|
|
40
41
|
if Property.column_for_attribute('id').type == :uuid
|
|
41
|
-
["#{
|
|
42
|
+
["#{property_translations_table.name} = ? OR #{properties_table.id} = ?", property, property]
|
|
42
43
|
else
|
|
43
|
-
{ "#{
|
|
44
|
+
{ "#{property_translations_table}.name" => property }
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
end
|
|
@@ -126,21 +127,25 @@ module Spree
|
|
|
126
127
|
|
|
127
128
|
# a scope that finds all products having property specified by name, object or id
|
|
128
129
|
add_search_scope :with_property do |property|
|
|
129
|
-
joins(:properties).where(property_conditions(property))
|
|
130
|
+
joins(:properties).join_translation_table(Property).where(property_conditions(property))
|
|
130
131
|
end
|
|
131
132
|
|
|
132
133
|
# a simple test for product with a certain property-value pairing
|
|
133
134
|
# note that it can test for properties with NULL values, but not for absent values
|
|
134
135
|
add_search_scope :with_property_value do |property, value|
|
|
135
136
|
joins(:properties).
|
|
136
|
-
|
|
137
|
+
join_translation_table(Property).
|
|
138
|
+
join_translation_table(ProductProperty).
|
|
139
|
+
where("#{ProductProperty.translation_table_alias}.value = ?", value).
|
|
137
140
|
where(property_conditions(property))
|
|
138
141
|
end
|
|
139
142
|
|
|
140
143
|
add_search_scope :with_property_values do |property_filter_param, property_values|
|
|
141
144
|
joins(product_properties: :property).
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
join_translation_table(Property).
|
|
146
|
+
join_translation_table(ProductProperty).
|
|
147
|
+
where(Property.translation_table_alias => { filter_param: property_filter_param }).
|
|
148
|
+
where(ProductProperty.translation_table_alias => { filter_param: property_values.map(&:parameterize) })
|
|
144
149
|
end
|
|
145
150
|
|
|
146
151
|
add_search_scope :with_option do |option|
|
|
@@ -151,7 +156,9 @@ module Spree
|
|
|
151
156
|
elsif OptionType.column_for_attribute('id').type == :uuid
|
|
152
157
|
joins(:option_types).where(spree_option_types: { name: option }).or(Product.joins(:option_types).where(spree_option_types: { id: option }))
|
|
153
158
|
else
|
|
154
|
-
joins(:option_types).
|
|
159
|
+
joins(:option_types).
|
|
160
|
+
join_translation_table(OptionType).
|
|
161
|
+
where(OptionType.translation_table_alias => { name: option })
|
|
155
162
|
end
|
|
156
163
|
end
|
|
157
164
|
|
|
@@ -164,6 +171,7 @@ module Spree
|
|
|
164
171
|
OptionType.where(id: option).or(OptionType.where(name: option))&.first&.id
|
|
165
172
|
else
|
|
166
173
|
OptionType.where(name: option)&.first&.id
|
|
174
|
+
OptionType.where(name: option)&.first&.id
|
|
167
175
|
end
|
|
168
176
|
end
|
|
169
177
|
|
|
@@ -171,7 +179,9 @@ module Spree
|
|
|
171
179
|
|
|
172
180
|
group("#{Spree::Product.table_name}.id").
|
|
173
181
|
joins(variants_including_master: :option_values).
|
|
174
|
-
|
|
182
|
+
join_translation_table(Spree::OptionValue).
|
|
183
|
+
where(Spree::OptionValue.translation_table_alias => { name: value },
|
|
184
|
+
Spree::OptionValue.table_name => { option_type_id: option_type_id })
|
|
175
185
|
end
|
|
176
186
|
|
|
177
187
|
# Finds all products which have either:
|
|
@@ -295,19 +305,10 @@ module Spree
|
|
|
295
305
|
# .search_by_name
|
|
296
306
|
if defined?(PgSearch)
|
|
297
307
|
include PgSearch::Model
|
|
298
|
-
|
|
299
|
-
if defined?(SpreeGlobalize)
|
|
300
|
-
pg_search_scope :search_by_name, associated_against: { translations: :name }, using: { tsearch: { any_word: true, prefix: true } }
|
|
301
|
-
else
|
|
302
|
-
pg_search_scope :search_by_name, against: :name, using: { tsearch: { any_word: true, prefix: true } }
|
|
303
|
-
end
|
|
308
|
+
pg_search_scope :search_by_name, against: :name, using: { tsearch: { any_word: true, prefix: true } }
|
|
304
309
|
else
|
|
305
310
|
def self.search_by_name(query)
|
|
306
|
-
|
|
307
|
-
joins(:translations).order(:name).where("LOWER(#{Product::Translation.table_name}.name) LIKE LOWER(:query)", query: "%#{query}%").distinct
|
|
308
|
-
else
|
|
309
|
-
where("LOWER(#{Product.table_name}.name) LIKE LOWER(:query)", query: "%#{query}%")
|
|
310
|
-
end
|
|
311
|
+
i18n { name.lower.matches("%#{query.downcase}%") }
|
|
311
312
|
end
|
|
312
313
|
end
|
|
313
314
|
search_scopes << :search_by_name
|
|
@@ -339,7 +340,10 @@ module Spree
|
|
|
339
340
|
case t
|
|
340
341
|
when ApplicationRecord then t
|
|
341
342
|
else
|
|
342
|
-
Taxon.where(
|
|
343
|
+
Taxon.where(name: t).
|
|
344
|
+
or(Taxon.where(Taxon.arel_table[:id].eq(t))).
|
|
345
|
+
or(Taxon.where(Taxon.arel_table[:permalink].matches("%/#{t}/"))).
|
|
346
|
+
or(Taxon.where(Taxon.arel_table[:permalink].matches("#{t}/"))).first
|
|
343
347
|
end
|
|
344
348
|
end.compact.flatten.uniq
|
|
345
349
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module TranslatableResource
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
extend Mobility
|
|
7
|
+
default_scope { i18n }
|
|
8
|
+
|
|
9
|
+
def get_field_with_locale(locale, field_name, fallback: false)
|
|
10
|
+
# method will return nil if no translation is present due to fallback: false setting
|
|
11
|
+
public_send(field_name, locale: locale, fallback: fallback)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class_methods do
|
|
16
|
+
def translatable_fields
|
|
17
|
+
const_get(:TRANSLATABLE_FIELDS)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def translation_table_alias
|
|
21
|
+
"#{self::Translation.table_name}_#{Mobility.normalize_locale(Mobility.locale)}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module TranslatableResourceScopes
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
class_methods do
|
|
6
|
+
# To be used when joining on the resource itself does not automatically join on its translations table
|
|
7
|
+
# This method is to be used when you've already joined on the translatable table itself
|
|
8
|
+
#
|
|
9
|
+
# If the resource table is aliased, pass the alias to `join_on_table_alias`, otherwise omit the param
|
|
10
|
+
def join_translation_table(translatable_class, join_on_table_alias = nil)
|
|
11
|
+
join_on_table_name = if join_on_table_alias.nil?
|
|
12
|
+
translatable_class.table_name
|
|
13
|
+
else
|
|
14
|
+
join_on_table_alias
|
|
15
|
+
end
|
|
16
|
+
translatable_class_foreign_key = "#{translatable_class.table_name.singularize}_id"
|
|
17
|
+
|
|
18
|
+
joins("LEFT OUTER JOIN #{translatable_class::Translation.table_name} #{translatable_class.translation_table_alias}
|
|
19
|
+
ON #{translatable_class.translation_table_alias}.#{translatable_class_foreign_key} = #{join_on_table_name}.id
|
|
20
|
+
AND #{translatable_class.translation_table_alias}.locale = '#{Mobility.locale}'")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module TranslatableResourceSlug
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
def localized_slugs_for_store(store)
|
|
7
|
+
supported_locales = store.supported_locales_list
|
|
8
|
+
|
|
9
|
+
supported_locales.each_with_object({}) do |locale, hash|
|
|
10
|
+
hash[locale] = I18n.with_locale(locale) { slug }
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -14,19 +14,19 @@ module Spree
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def self.admin
|
|
17
|
-
|
|
17
|
+
Spree::Deprecation.warn('`User#admin` is deprecated and will be removed in Spree 5. Please use `User#spree_admin`')
|
|
18
18
|
|
|
19
19
|
spree_admin
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def self.admin_created?
|
|
23
|
-
|
|
23
|
+
Spree::Deprecation.warn('`User#admin_created?` is deprecated and will be removed in Spree 5. Please use `User#spree_admin_created?`')
|
|
24
24
|
|
|
25
25
|
spree_admin_created?
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def admin?
|
|
29
|
-
|
|
29
|
+
Spree::Deprecation.warn('`User#admin?` is deprecated and will be removed in Spree 5. Please use `User#spree_admin?`')
|
|
30
30
|
|
|
31
31
|
spree_admin?
|
|
32
32
|
end
|
data/app/models/spree/address.rb
CHANGED
|
@@ -2,7 +2,7 @@ module Spree
|
|
|
2
2
|
class Address < Spree::Base
|
|
3
3
|
require 'validates_zipcode'
|
|
4
4
|
|
|
5
|
-
include Metadata
|
|
5
|
+
include Spree::Metadata
|
|
6
6
|
if defined?(Spree::Webhooks)
|
|
7
7
|
include Spree::Webhooks::HasWebhooks
|
|
8
8
|
end
|
|
@@ -10,7 +10,9 @@ module Spree
|
|
|
10
10
|
include Spree::Security::Addresses
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
if Rails::VERSION::STRING >= '
|
|
13
|
+
if Rails::VERSION::STRING >= '7.1.0'
|
|
14
|
+
serialize :preferences, type: Hash, coder: YAML, default: {}
|
|
15
|
+
else
|
|
14
16
|
serialize :preferences, Hash, default: {}
|
|
15
17
|
end
|
|
16
18
|
|
|
@@ -67,7 +69,7 @@ module Spree
|
|
|
67
69
|
self.whitelisted_ransackable_associations = %w[country state user]
|
|
68
70
|
|
|
69
71
|
def self.build_default
|
|
70
|
-
|
|
72
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
71
73
|
`Address#build_default` is deprecated and will be removed in Spree 5.0.
|
|
72
74
|
Please use standard rails `Address.new(country: current_store.default_country)`
|
|
73
75
|
DEPRECATION
|
|
@@ -75,7 +77,7 @@ module Spree
|
|
|
75
77
|
end
|
|
76
78
|
|
|
77
79
|
def self.default(user = nil, kind = 'bill')
|
|
78
|
-
|
|
80
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
79
81
|
`Address#default` is deprecated and will be removed in Spree 5.0.
|
|
80
82
|
DEPRECATION
|
|
81
83
|
if user && user_address = user.public_send(:"#{kind}_address")
|
data/app/models/spree/asset.rb
CHANGED
data/app/models/spree/base.rb
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
class Spree::Base < ApplicationRecord
|
|
2
2
|
include Spree::Preferences::Preferable
|
|
3
|
-
|
|
3
|
+
if Rails::VERSION::STRING >= '7.1.0'
|
|
4
|
+
serialize :preferences, type: Hash, coder: YAML
|
|
5
|
+
else
|
|
6
|
+
serialize :preferences, Hash
|
|
7
|
+
end
|
|
4
8
|
|
|
5
9
|
include Spree::RansackableAttributes
|
|
10
|
+
include Spree::TranslatableResourceScopes
|
|
6
11
|
|
|
7
12
|
after_initialize do
|
|
8
13
|
if has_attribute?(:preferences) && !preferences.nil?
|
|
@@ -3,11 +3,7 @@ module Spree::Cms::Sections
|
|
|
3
3
|
after_initialize :default_values
|
|
4
4
|
validate :reset_multiple_link_attributes
|
|
5
5
|
|
|
6
|
-
LINKED_RESOURCE_TYPE =
|
|
7
|
-
['Spree::Taxon'].freeze
|
|
8
|
-
else
|
|
9
|
-
['Spree::Taxon', 'Spree::Product'].freeze
|
|
10
|
-
end
|
|
6
|
+
LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freeze
|
|
11
7
|
|
|
12
8
|
LAYOUT_OPTIONS = ['Default', 'Reversed'].freeze
|
|
13
9
|
LABEL_OPTIONS = ['Show', 'Hide'].freeze
|
|
@@ -71,8 +67,6 @@ module Spree::Cms::Sections
|
|
|
71
67
|
private
|
|
72
68
|
|
|
73
69
|
def reset_multiple_link_attributes
|
|
74
|
-
return if Rails::VERSION::STRING < '6.0'
|
|
75
|
-
|
|
76
70
|
if link_type_one_changed?
|
|
77
71
|
return if link_type_one_was.nil?
|
|
78
72
|
|
|
@@ -3,11 +3,7 @@ module Spree::Cms::Sections
|
|
|
3
3
|
after_initialize :default_values
|
|
4
4
|
validate :reset_multiple_link_attributes
|
|
5
5
|
|
|
6
|
-
LINKED_RESOURCE_TYPE =
|
|
7
|
-
['Spree::Taxon'].freeze
|
|
8
|
-
else
|
|
9
|
-
['Spree::Taxon', 'Spree::Product'].freeze
|
|
10
|
-
end
|
|
6
|
+
LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freeze
|
|
11
7
|
|
|
12
8
|
store :content, accessors: [:link_type_one, :link_one, :title_one, :subtitle_one,
|
|
13
9
|
:link_type_two, :link_two, :title_two, :subtitle_two], coder: JSON
|
|
@@ -49,8 +45,6 @@ module Spree::Cms::Sections
|
|
|
49
45
|
private
|
|
50
46
|
|
|
51
47
|
def reset_multiple_link_attributes
|
|
52
|
-
return if Rails::VERSION::STRING < '6.0'
|
|
53
|
-
|
|
54
48
|
if link_type_one_changed?
|
|
55
49
|
return if link_type_one_was.nil?
|
|
56
50
|
|
data/app/models/spree/country.rb
CHANGED
|
@@ -19,7 +19,7 @@ module Spree
|
|
|
19
19
|
validates :name, :iso_name, :iso, :iso3, presence: true, uniqueness: { case_sensitive: false, scope: spree_base_uniqueness_scope }
|
|
20
20
|
|
|
21
21
|
def self.default(store = nil)
|
|
22
|
-
|
|
22
|
+
Spree::Deprecation.warn(<<-DEPRECATION, caller)
|
|
23
23
|
`Country#default` is deprecated and will be removed in Spree 5.0.
|
|
24
24
|
Please use `current_store.default_country` instead
|
|
25
25
|
DEPRECATION
|
|
@@ -49,7 +49,7 @@ module Spree
|
|
|
49
49
|
private
|
|
50
50
|
|
|
51
51
|
def ensure_not_default
|
|
52
|
-
|
|
52
|
+
Spree::Deprecation.warn('Country#ensure_not_default is deprecated and will be removed in Spree v5')
|
|
53
53
|
|
|
54
54
|
if id.eql?(Spree::Config[:default_country_id])
|
|
55
55
|
errors.add(:base, Spree.t(:default_country_cannot_be_deleted))
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
class CustomerReturn < Spree::Base
|
|
3
3
|
include Spree::Core::NumberGenerator.new(prefix: 'CR', length: 9)
|
|
4
|
-
include NumberIdentifier
|
|
5
|
-
include Metadata
|
|
4
|
+
include Spree::NumberIdentifier
|
|
5
|
+
include Spree::Metadata
|
|
6
6
|
if defined?(Spree::Webhooks)
|
|
7
7
|
include Spree::Webhooks::HasWebhooks
|
|
8
8
|
end
|