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.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/app/finders/spree/countries/find.rb +1 -1
  3. data/app/finders/spree/option_values/find_available.rb +1 -1
  4. data/app/finders/spree/product_properties/find_available.rb +1 -1
  5. data/app/finders/spree/products/find.rb +21 -13
  6. data/app/finders/spree/taxons/find.rb +7 -10
  7. data/app/helpers/spree/base_helper.rb +3 -7
  8. data/app/helpers/spree/products_helper.rb +3 -3
  9. data/app/models/concerns/spree/metadata.rb +7 -2
  10. data/app/models/concerns/spree/named_type.rb +1 -1
  11. data/app/models/concerns/spree/product_scopes.rb +27 -23
  12. data/app/models/concerns/spree/translatable_resource.rb +25 -0
  13. data/app/models/concerns/spree/translatable_resource_scopes.rb +24 -0
  14. data/app/models/concerns/spree/translatable_resource_slug.rb +15 -0
  15. data/app/models/concerns/spree/user_roles.rb +3 -3
  16. data/app/models/spree/address.rb +6 -4
  17. data/app/models/spree/asset.rb +1 -1
  18. data/app/models/spree/base.rb +6 -1
  19. data/app/models/spree/calculator/default_tax.rb +1 -1
  20. data/app/models/spree/cms/sections/image_gallery.rb +1 -7
  21. data/app/models/spree/cms/sections/side_by_side_images.rb +1 -7
  22. data/app/models/spree/cms_page.rb +2 -2
  23. data/app/models/spree/cms_section.rb +1 -1
  24. data/app/models/spree/country.rb +2 -2
  25. data/app/models/spree/credit_card.rb +1 -1
  26. data/app/models/spree/customer_return.rb +2 -2
  27. data/app/models/spree/data_feed/google.rb +15 -0
  28. data/app/models/spree/data_feed.rb +40 -0
  29. data/app/models/spree/digital_link.rb +5 -1
  30. data/app/models/spree/image.rb +2 -2
  31. data/app/models/spree/legacy_user.rb +3 -3
  32. data/app/models/spree/line_item.rb +1 -1
  33. data/app/models/spree/log_entry.rb +5 -1
  34. data/app/models/spree/menu.rb +1 -1
  35. data/app/models/spree/option_type.rb +6 -2
  36. data/app/models/spree/option_value.rb +5 -1
  37. data/app/models/spree/order/store_credit.rb +8 -0
  38. data/app/models/spree/order.rb +9 -9
  39. data/app/models/spree/order_contents.rb +31 -0
  40. data/app/models/spree/payment.rb +7 -15
  41. data/app/models/spree/payment_method.rb +1 -1
  42. data/app/models/spree/payment_source.rb +1 -1
  43. data/app/models/spree/preference.rb +5 -1
  44. data/app/models/spree/price.rb +1 -1
  45. data/app/models/spree/product.rb +64 -25
  46. data/app/models/spree/product_property.rb +13 -4
  47. data/app/models/spree/promotion.rb +2 -2
  48. data/app/models/spree/property.rb +8 -2
  49. data/app/models/spree/prototype.rb +1 -1
  50. data/app/models/spree/refund.rb +1 -1
  51. data/app/models/spree/reimbursement.rb +1 -1
  52. data/app/models/spree/return_authorization.rb +1 -1
  53. data/app/models/spree/return_item.rb +5 -1
  54. data/app/models/spree/role.rb +1 -1
  55. data/app/models/spree/shipment.rb +5 -5
  56. data/app/models/spree/shipping_category.rb +1 -1
  57. data/app/models/spree/shipping_method.rb +1 -1
  58. data/app/models/spree/stock/estimator.rb +1 -1
  59. data/app/models/spree/stock/splitter/weight.rb +1 -1
  60. data/app/models/spree/stock_item.rb +1 -1
  61. data/app/models/spree/stock_location.rb +1 -1
  62. data/app/models/spree/stock_transfer.rb +3 -3
  63. data/app/models/spree/store.rb +22 -3
  64. data/app/models/spree/store_credit.rb +2 -2
  65. data/app/models/spree/taxon.rb +47 -7
  66. data/app/models/spree/taxon_image.rb +2 -2
  67. data/app/models/spree/taxonomy.rb +5 -1
  68. data/app/models/spree/variant.rb +6 -9
  69. data/app/models/spree/wishlist.rb +6 -2
  70. data/app/models/spree/zone.rb +2 -2
  71. data/app/services/spree/data_feeds/google/optional_attributes.rb +23 -0
  72. data/app/services/spree/data_feeds/google/optional_sub_attributes.rb +21 -0
  73. data/app/services/spree/data_feeds/google/products_list.rb +14 -0
  74. data/app/services/spree/data_feeds/google/required_attributes.rb +67 -0
  75. data/app/services/spree/data_feeds/google/rss.rb +107 -0
  76. data/app/services/spree/locales/set_fallback_locale_for_store.rb +16 -0
  77. data/app/services/spree/seeds/countries.rb +12 -27
  78. data/app/services/spree/seeds/states.rb +8 -17
  79. data/app/services/spree/stock_locations/stock_items/create.rb +12 -18
  80. data/app/sorters/spree/products/sort.rb +23 -0
  81. data/app/validators/db_maximum_length_validator.rb +2 -6
  82. data/brakeman.ignore +326 -18
  83. data/config/initializers/friendly_id.rb +2 -0
  84. data/config/initializers/mobility.rb +16 -0
  85. data/config/initializers/rails61_fixes.rb +1 -3
  86. data/config/locales/en.yml +7 -0
  87. data/db/migrate/20220706112554_create_product_name_and_description_translations_for_mobility_table_backend.rb +27 -0
  88. data/db/migrate/20220715083542_create_spree_product_translations_for_mobility.rb +7 -0
  89. data/db/migrate/20220715120222_change_product_name_null_to_true.rb +5 -0
  90. data/db/migrate/20220718100743_create_spree_taxon_name_and_description_translations_for_mobility_table_backend.rb +27 -0
  91. data/db/migrate/20220718100948_change_taxon_name_null_to_true.rb +5 -0
  92. data/db/migrate/20220802070609_add_locale_to_friendly_id_slugs.rb +11 -0
  93. data/db/migrate/20220802073225_create_spree_product_slug_translations_for_mobility_table_backend.rb +5 -0
  94. data/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb +66 -0
  95. data/db/migrate/20221215151408_add_selected_locale_to_spree_users.rb +8 -0
  96. data/db/migrate/20221219123957_add_deleted_at_to_product_translations.rb +6 -0
  97. data/db/migrate/20221220133432_add_uniqueness_constraint_to_product_translations.rb +5 -0
  98. data/db/migrate/20221229132350_create_spree_data_feed_settings.rb +14 -0
  99. data/db/migrate/20230103144439_create_option_type_translations.rb +26 -0
  100. data/db/migrate/20230103151034_create_option_value_translations.rb +26 -0
  101. data/db/migrate/20230109084253_create_product_property_translations.rb +25 -0
  102. data/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb +58 -0
  103. data/db/migrate/20230109105943_create_property_translations.rb +26 -0
  104. data/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb +59 -0
  105. data/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb +15 -0
  106. data/db/migrate/20230111121534_add_additional_taxon_translation_fields.rb +8 -0
  107. data/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb +82 -0
  108. data/db/migrate/20230117115531_create_taxonomy_translations.rb +24 -0
  109. data/db/migrate/20230117120430_allow_null_taxonomy_name.rb +5 -0
  110. data/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb +11 -0
  111. data/db/migrate/20230210142732_create_store_translations.rb +50 -0
  112. data/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb +11 -0
  113. data/db/migrate/20230210230434_add_deleted_at_to_store_translations.rb +6 -0
  114. data/db/migrate/20230415155958_rename_data_feed_settings_table.rb +5 -0
  115. data/db/migrate/20230415160828_rename_data_feed_table_columns.rb +7 -0
  116. data/db/migrate/20230415161226_add_indexes_to_data_feeds_table.rb +5 -0
  117. data/db/migrate/20230512094803_rename_data_feeds_column_provider_to_type.rb +5 -0
  118. data/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb +5 -0
  119. data/lib/mobility/plugins/store_based_fallbacks.rb +55 -0
  120. data/lib/spree/core/configuration.rb +2 -1
  121. data/lib/spree/core/controller_helpers/auth.rb +1 -1
  122. data/lib/spree/core/controller_helpers/common.rb +5 -5
  123. data/lib/spree/core/controller_helpers/locale.rb +33 -2
  124. data/lib/spree/core/dependencies.rb +70 -94
  125. data/lib/spree/core/dependencies_helper.rb +19 -0
  126. data/lib/spree/core/engine.rb +7 -1
  127. data/lib/spree/core/preferences/preferable_class_methods.rb +1 -1
  128. data/lib/spree/core/product_duplicator.rb +4 -1
  129. data/lib/spree/core/product_filters.rb +7 -4
  130. data/lib/spree/core/search/base.rb +1 -1
  131. data/lib/spree/core/version.rb +1 -1
  132. data/lib/spree/core.rb +2 -0
  133. data/lib/spree/permitted_attributes.rb +1 -1
  134. data/lib/spree/testing_support/controller_requests.rb +10 -10
  135. data/lib/spree/testing_support/factories/google_data_feed_factory.rb +8 -0
  136. data/lib/spree/testing_support/factories/product_factory.rb +6 -0
  137. data/lib/spree/testing_support/factories/product_translation_factory.rb +6 -0
  138. data/lib/spree/testing_support/factories/store_factory.rb +3 -0
  139. data/lib/spree/testing_support/factories/variant_factory.rb +4 -0
  140. data/lib/spree/translation_migrations.rb +40 -0
  141. data/lib/spree_core.rb +1 -0
  142. data/spree_core.gemspec +6 -3
  143. metadata +147 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f53d1d3ed70fd19d1ae3665df1dfabac01948cd28e71b3a68c86c8a8f7afcf1a
4
- data.tar.gz: 87e8a6e4d121d979fadbe0d44d89d30f0f6d55c89b64d3bcd0c2354c794b9ef1
3
+ metadata.gz: 96a1ab3dd325e2cd0053b0ad881b73ddb153624fd04dba62dd61d4e01ab2aca4
4
+ data.tar.gz: 1e947a1bba157dd1df4ba6773d869675da4bffa856f4f1c57f63a4c7b5a592aa
5
5
  SHA512:
6
- metadata.gz: 51b6d8e283837db0d607f9528f1527d8cfc46c020a804bc3f2797c392eb040d6b7081df92d52eafac617c2fff64c6e98b500912173266f4c04286f32ab5fbdac
7
- data.tar.gz: d2305b19b0364a34e379955ce76fb453702c385f7377a23f40a65ae61f93de5a5d157bd4978c757b563c6c263f5375a32f224840129b29085af424cc00f6712d
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
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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
@@ -9,7 +9,7 @@ module Spree
9
9
  end
10
10
 
11
11
  def execute
12
- find_available(scope, products_scope).select(select_args).order(order_args)
12
+ find_available(scope, products_scope).includes(:translations).select(select_args).order(order_args)
13
13
  end
14
14
 
15
15
  private
@@ -9,7 +9,7 @@ module Spree
9
9
  end
10
10
 
11
11
  def execute
12
- find_available(scope, products_scope)
12
+ find_available(scope, products_scope).includes(:translations)
13
13
  end
14
14
 
15
15
  private
@@ -5,7 +5,7 @@ module Spree
5
5
  @scope = scope
6
6
 
7
7
  if current_currency.present?
8
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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
- products.like_any([:name], [name])
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 = products.with_property_values(property_filter_param, values).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
- products.order(name: :asc)
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
- products.order(name: :desc)
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
- if Rails::VERSION::STRING >= '6.1'
73
- taxons.joins(:parent).where(parent: { permalink: parent_permalink })
74
- else
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
- taxons.where(name_matcher)
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
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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[:meta_keywords].present?
117
- meta[:description] = object.meta_description if object[:meta_description].present?
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).to_s(:number)
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
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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
- serialize :public_metadata, HashSerializer
9
- serialize :private_metadata, HashSerializer
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
@@ -6,7 +6,7 @@ module Spree
6
6
  scope :active, -> { where(active: true) }
7
7
  default_scope { order(Arel.sql("LOWER(#{table_name}.name)")) }
8
8
 
9
- include UniqueName
9
+ include Spree::UniqueName
10
10
  end
11
11
  end
12
12
  end
@@ -32,15 +32,16 @@ module Spree
32
32
  end
33
33
 
34
34
  def self.property_conditions(property)
35
- properties = Property.table_name
35
+ properties_table = Property.table_name
36
+ property_translations_table = Property.translation_table_alias
36
37
  case property
37
- when Property then { "#{properties}.id" => property.id }
38
- when Integer then { "#{properties}.id" => property }
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
- ["#{properties.name} = ? OR #{properties.id} = ?", property, property]
42
+ ["#{property_translations_table.name} = ? OR #{properties_table.id} = ?", property, property]
42
43
  else
43
- { "#{properties}.name" => property }
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
- where("#{ProductProperty.table_name}.value = ?", value).
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
- where(Property.table_name => { filter_param: property_filter_param }).
143
- where(ProductProperty.table_name => { filter_param: property_values.map(&:parameterize) })
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).where(spree_option_types: { name: option })
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
- where(Spree::OptionValue.table_name => { name: value, option_type_id: option_type_id })
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
- if defined?(SpreeGlobalize)
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(Taxon.arel_table[:name].eq(t)).or(Taxon.where(Taxon.arel_table[:id].eq(t))).or(Taxon.where(Taxon.arel_table[:permalink].matches("%/#{t}/"))).or(Taxon.where(Taxon.arel_table[:permalink].matches("#{t}/"))).first
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
- ActiveSupport::Deprecation.warn('`User#admin` is deprecated and will be removed in Spree 5. Please use `User#spree_admin`')
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
- ActiveSupport::Deprecation.warn('`User#admin_created?` is deprecated and will be removed in Spree 5. Please use `User#spree_admin_created?`')
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
- ActiveSupport::Deprecation.warn('`User#admin?` is deprecated and will be removed in Spree 5. Please use `User#spree_admin?`')
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
@@ -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 >= '6.1'
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
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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")
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Asset < Spree::Base
3
3
  include Support::ActiveStorage
4
- include Metadata
4
+ include Spree::Metadata
5
5
  if defined?(Spree::Webhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
@@ -1,8 +1,13 @@
1
1
  class Spree::Base < ApplicationRecord
2
2
  include Spree::Preferences::Preferable
3
- serialize :preferences, Hash
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?
@@ -2,7 +2,7 @@ require_dependency 'spree/calculator'
2
2
 
3
3
  module Spree
4
4
  class Calculator::DefaultTax < Calculator
5
- include VatPriceCalculation
5
+ include Spree::VatPriceCalculation
6
6
  def self.description
7
7
  Spree.t(:default_tax)
8
8
  end
@@ -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 = if Rails::VERSION::STRING < '6.0'
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 = if Rails::VERSION::STRING < '6.0'
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
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class CmsPage < Base
3
- include SingleStoreResource
4
- include DisplayLink
3
+ include Spree::SingleStoreResource
4
+ include Spree::DisplayLink
5
5
 
6
6
  if defined?(Spree::Webhooks)
7
7
  include Spree::Webhooks::HasWebhooks
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class CmsSection < Base
3
- include DisplayLink
3
+ include Spree::DisplayLink
4
4
 
5
5
  acts_as_list scope: :cms_page
6
6
  belongs_to :cms_page, touch: true
@@ -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
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
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
- ActiveSupport::Deprecation.warn('Country#ensure_not_default is deprecated and will be removed in Spree v5')
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,7 +1,7 @@
1
1
  module Spree
2
2
  class CreditCard < Spree::Base
3
3
  include ActiveMerchant::Billing::CreditCardMethods
4
- include Metadata
4
+ include Spree::Metadata
5
5
  if defined?(Spree::Webhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
@@ -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
@@ -0,0 +1,15 @@
1
+ require_dependency 'spree/data_feed'
2
+
3
+ module Spree
4
+ class DataFeed::Google < DataFeed
5
+ class << self
6
+ def label
7
+ 'Google Merchant Center Feed'
8
+ end
9
+
10
+ def provider_name
11
+ 'google'
12
+ end
13
+ end
14
+ end
15
+ end