spree_core 4.5.5 → 4.6.0

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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/app/finders/spree/option_values/find_available.rb +1 -1
  3. data/app/finders/spree/product_properties/find_available.rb +1 -1
  4. data/app/finders/spree/products/find.rb +20 -12
  5. data/app/finders/spree/taxons/find.rb +10 -7
  6. data/app/helpers/spree/base_helper.rb +2 -2
  7. data/app/models/concerns/spree/product_scopes.rb +27 -23
  8. data/app/models/concerns/spree/translatable_resource.rb +25 -0
  9. data/app/models/concerns/spree/translatable_resource_scopes.rb +24 -0
  10. data/app/models/concerns/spree/translatable_resource_slug.rb +17 -0
  11. data/app/models/spree/address.rb +1 -1
  12. data/app/models/spree/asset.rb +1 -1
  13. data/app/models/spree/base.rb +1 -0
  14. data/app/models/spree/calculator/default_tax.rb +1 -1
  15. data/app/models/spree/cms_page.rb +1 -1
  16. data/app/models/spree/cms_section.rb +1 -1
  17. data/app/models/spree/credit_card.rb +1 -1
  18. data/app/models/spree/customer_return.rb +2 -2
  19. data/app/models/spree/data_feed/google.rb +15 -0
  20. data/app/models/spree/data_feed.rb +40 -0
  21. data/app/models/spree/line_item.rb +1 -1
  22. data/app/models/spree/option_type.rb +5 -1
  23. data/app/models/spree/option_value.rb +5 -1
  24. data/app/models/spree/order/store_credit.rb +0 -8
  25. data/app/models/spree/order.rb +3 -3
  26. data/app/models/spree/payment.rb +3 -3
  27. data/app/models/spree/payment_method.rb +1 -1
  28. data/app/models/spree/payment_source.rb +1 -1
  29. data/app/models/spree/price.rb +1 -1
  30. data/app/models/spree/product.rb +44 -13
  31. data/app/models/spree/product_property.rb +12 -3
  32. data/app/models/spree/promotion.rb +2 -2
  33. data/app/models/spree/property.rb +8 -2
  34. data/app/models/spree/prototype.rb +1 -1
  35. data/app/models/spree/refund.rb +1 -1
  36. data/app/models/spree/reimbursement.rb +1 -1
  37. data/app/models/spree/return_authorization.rb +1 -1
  38. data/app/models/spree/shipment.rb +5 -5
  39. data/app/models/spree/shipping_method.rb +1 -1
  40. data/app/models/spree/stock/estimator.rb +1 -1
  41. data/app/models/spree/stock_item.rb +1 -1
  42. data/app/models/spree/stock_transfer.rb +3 -3
  43. data/app/models/spree/store.rb +20 -1
  44. data/app/models/spree/store_credit.rb +1 -1
  45. data/app/models/spree/taxon.rb +23 -7
  46. data/app/models/spree/taxonomy.rb +5 -1
  47. data/app/models/spree/variant.rb +6 -9
  48. data/app/services/spree/data_feeds/google/optional_attributes.rb +23 -0
  49. data/app/services/spree/data_feeds/google/optional_sub_attributes.rb +21 -0
  50. data/app/services/spree/data_feeds/google/products_list.rb +14 -0
  51. data/app/services/spree/data_feeds/google/required_attributes.rb +67 -0
  52. data/app/services/spree/data_feeds/google/rss.rb +107 -0
  53. data/app/sorters/spree/products/sort.rb +23 -0
  54. data/brakeman.ignore +326 -18
  55. data/config/initializers/friendly_id.rb +2 -0
  56. data/config/initializers/mobility.rb +18 -0
  57. data/config/locales/en.yml +1 -0
  58. data/db/migrate/20220706112554_create_product_name_and_description_translations_for_mobility_table_backend.rb +27 -0
  59. data/db/migrate/20220715083542_create_spree_product_translations_for_mobility.rb +7 -0
  60. data/db/migrate/20220715120222_change_product_name_null_to_true.rb +5 -0
  61. data/db/migrate/20220718100743_create_spree_taxon_name_and_description_translations_for_mobility_table_backend.rb +27 -0
  62. data/db/migrate/20220718100948_change_taxon_name_null_to_true.rb +5 -0
  63. data/db/migrate/20220802070609_add_locale_to_friendly_id_slugs.rb +11 -0
  64. data/db/migrate/20220802073225_create_spree_product_slug_translations_for_mobility_table_backend.rb +5 -0
  65. data/db/migrate/20220804073928_transfer_data_to_translatable_tables.rb +66 -0
  66. data/db/migrate/20221215151408_add_selected_locale_to_spree_users.rb +8 -0
  67. data/db/migrate/20221219123957_add_deleted_at_to_product_translations.rb +6 -0
  68. data/db/migrate/20221220133432_add_uniqueness_constraint_to_product_translations.rb +5 -0
  69. data/db/migrate/20221229132350_create_spree_data_feed_settings.rb +14 -0
  70. data/db/migrate/20230103144439_create_option_type_translations.rb +26 -0
  71. data/db/migrate/20230103151034_create_option_value_translations.rb +26 -0
  72. data/db/migrate/20230109084253_create_product_property_translations.rb +25 -0
  73. data/db/migrate/20230109094907_transfer_options_data_to_translatable_tables.rb +58 -0
  74. data/db/migrate/20230109105943_create_property_translations.rb +26 -0
  75. data/db/migrate/20230109110840_transfer_property_data_to_translatable_tables.rb +59 -0
  76. data/db/migrate/20230110142344_backfill_friendly_id_slug_locale.rb +15 -0
  77. data/db/migrate/20230111121534_add_additional_taxon_translation_fields.rb +8 -0
  78. data/db/migrate/20230111122511_transfer_product_and_taxon_data_to_translatable_tables.rb +82 -0
  79. data/db/migrate/20230117115531_create_taxonomy_translations.rb +24 -0
  80. data/db/migrate/20230117120430_allow_null_taxonomy_name.rb +5 -0
  81. data/db/migrate/20230117121303_transfer_taxonomy_data_to_translatable_tables.rb +11 -0
  82. data/db/migrate/20230210142732_create_store_translations.rb +50 -0
  83. data/db/migrate/20230210142849_transfer_store_data_to_translatable_tables.rb +11 -0
  84. data/db/migrate/20230210230434_add_deleted_at_to_store_translations.rb +6 -0
  85. data/db/migrate/20230415155958_rename_data_feed_settings_table.rb +5 -0
  86. data/db/migrate/20230415160828_rename_data_feed_table_columns.rb +7 -0
  87. data/db/migrate/20230415161226_add_indexes_to_data_feeds_table.rb +5 -0
  88. data/db/migrate/20230512094803_rename_data_feeds_column_provider_to_type.rb +5 -0
  89. data/db/migrate/20230514162157_add_index_on_locale_and_permalink_to_spree_taxons.rb +5 -0
  90. data/lib/spree/core/configuration.rb +1 -0
  91. data/lib/spree/core/controller_helpers/locale.rb +26 -2
  92. data/lib/spree/core/dependencies.rb +70 -94
  93. data/lib/spree/core/dependencies_helper.rb +19 -0
  94. data/lib/spree/core/engine.rb +6 -1
  95. data/lib/spree/core/product_duplicator.rb +1 -1
  96. data/lib/spree/core/product_filters.rb +7 -4
  97. data/lib/spree/core/search/base.rb +1 -1
  98. data/lib/spree/core/version.rb +1 -1
  99. data/lib/spree/core.rb +2 -0
  100. data/lib/spree/permitted_attributes.rb +1 -1
  101. data/lib/spree/testing_support/factories/google_data_feed_factory.rb +8 -0
  102. data/lib/spree/testing_support/factories/product_factory.rb +6 -0
  103. data/lib/spree/testing_support/factories/product_translation_factory.rb +6 -0
  104. data/lib/spree/testing_support/factories/store_factory.rb +1 -0
  105. data/lib/spree/testing_support/factories/variant_factory.rb +4 -0
  106. data/lib/spree/translation_migrations.rb +40 -0
  107. data/spree_core.gemspec +3 -0
  108. metadata +93 -6
  109. data/app/models/spree/order_contents.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9e92a8b9ec1056e6a654750c5d05801ef1f2ca356da7c0a6cd92ce9df2c422d
4
- data.tar.gz: a71e05bf2f2bd55147e3462acc1370af3ea2070d799e05f0a6de21fcc45aa19f
3
+ metadata.gz: 619f5416fb099c1cccaeb2432fd6002b53aa605aff90c9b4078f2a51ba73e89b
4
+ data.tar.gz: e53a5c780f9c4e79c50cc38d2fdd055dc20b04bef93c89e33e88b7a4fd9facce
5
5
  SHA512:
6
- metadata.gz: 9a67ebe4c0b04eee91586efeb6a0aa084a0c98e2907858796ba2f5295b32e085cc63c8d4497cddbd0b3659794f79fb446cec8119d8fddcff7bef2c9b0e362627
7
- data.tar.gz: a9bd08d86b0784bef3fc8be5e855f2f6742ee4ce7e3513c77433cd69c4727d304bc499f5c29f98749cdeb5981226cd11c461e1b531e574c91a3bc147a34e6ed7
6
+ metadata.gz: 7e8cc84789a7c8564b45576c2aa9f8974f62da3b2c752869a9950497b01382b073b50a4d7746d9f2142bee4248115b58a527637b104f3750504499f2a6608459
7
+ data.tar.gz: fab84d0b2eb02221f96209f11c118feb77928d69269b009abb4c9a773089f1a011a96bbb3b731abce9cd8af45208eaabdef464c27244b7fd954554de1203c15b
@@ -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
@@ -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
 
@@ -70,9 +66,13 @@ module Spree
70
66
  return taxons unless parent_permalink?
71
67
 
72
68
  if Rails::VERSION::STRING >= '6.1'
73
- taxons.joins(:parent).where(parent: { permalink: parent_permalink })
69
+ taxons.joins(:parent).
70
+ join_translation_table(Taxon, 'parents_spree_taxons').
71
+ where(["#{Taxon.translation_table_alias}.permalink = ?", parent_permalink])
74
72
  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])
73
+ taxons.joins("INNER JOIN #{Spree::Taxon.table_name} AS parent_taxon ON parent_taxon.id = #{Spree::Taxon.table_name}.parent_id").
74
+ join_translation_table(Taxon, 'parent_taxon').
75
+ where(["#{Taxon.translation_table_alias}.permalink = ?", parent_permalink])
76
76
  end
77
77
  end
78
78
 
@@ -91,7 +91,10 @@ module Spree
91
91
  def by_name(taxons)
92
92
  return taxons unless name?
93
93
 
94
- taxons.where(name_matcher)
94
+ taxon_name = name
95
+
96
+ # i18n mobility scope doesn't automatically get set for query blocks (Mobility issue #599) - set it explicitly
97
+ taxons.i18n { name.matches("%#{taxon_name}%") }
95
98
  end
96
99
  end
97
100
  end
@@ -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)
@@ -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.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,17 @@
1
+ module Spree
2
+ module TranslatableResourceSlug
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def localized_slugs_for_store(store)
7
+ localized_slugs = Hash[translations.pluck(:locale, :slug)]
8
+ default_locale = store.default_locale
9
+ supported_locales = store.supported_locales_list
10
+
11
+ supported_locales.each_with_object({}) do |locale, hash|
12
+ hash[locale] = localized_slugs[locale] || localized_slugs[default_locale]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,7 +2,7 @@ module Spree
2
2
  class Address < Spree::Base
3
3
  require 'validates_zipcode'
4
4
 
5
- include Spree::Metadata
5
+ include Metadata
6
6
  if defined?(Spree::Webhooks)
7
7
  include Spree::Webhooks::HasWebhooks
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Asset < Spree::Base
3
3
  include Support::ActiveStorage
4
- include Spree::Metadata
4
+ include Metadata
5
5
  if defined?(Spree::Webhooks)
6
6
  include Spree::Webhooks::HasWebhooks
7
7
  end
@@ -3,6 +3,7 @@ class Spree::Base < ApplicationRecord
3
3
  serialize :preferences, Hash
4
4
 
5
5
  include Spree::RansackableAttributes
6
+ include Spree::TranslatableResourceScopes
6
7
 
7
8
  after_initialize do
8
9
  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 Spree::VatPriceCalculation
5
+ include VatPriceCalculation
6
6
  def self.description
7
7
  Spree.t(:default_tax)
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class CmsPage < Base
3
3
  include SingleStoreResource
4
- include Spree::DisplayLink
4
+ include 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 Spree::DisplayLink
3
+ include DisplayLink
4
4
 
5
5
  acts_as_list scope: :cms_page
6
6
  belongs_to :cms_page, touch: true
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class CreditCard < Spree::Base
3
3
  include ActiveMerchant::Billing::CreditCardMethods
4
- include Spree::Metadata
4
+ include 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 Spree::NumberIdentifier
5
- include Spree::Metadata
4
+ include NumberIdentifier
5
+ include 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
@@ -0,0 +1,40 @@
1
+ module Spree
2
+ class DataFeed < Base
3
+ belongs_to :store, class_name: 'Spree::Store', foreign_key: 'store_id'
4
+
5
+ scope :for_store, ->(store) { where(store: store) }
6
+
7
+ before_validation :generate_slug
8
+
9
+ with_options presence: true do
10
+ validates :store
11
+ validates :name, uniqueness: true
12
+ validates :slug, uniqueness: { scope: :store_id }
13
+ end
14
+
15
+ def formatted_url
16
+ "#{store.formatted_url}/api/v2/data_feeds/#{self.class.provider_name}/#{slug}.rss"
17
+ end
18
+
19
+ private
20
+
21
+ def generate_slug
22
+ new_slug = slug.blank? ? SecureRandom.uuid : slug.parameterize
23
+ write_attribute(:slug, new_slug)
24
+ end
25
+
26
+ class << self
27
+ def label
28
+ raise NotImplementedError
29
+ end
30
+
31
+ def provider_name
32
+ raise NotImplementedError
33
+ end
34
+
35
+ def available_types
36
+ Rails.application.config.spree.data_feed_types
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class LineItem < Spree::Base
3
- include Spree::Metadata
3
+ include Metadata
4
4
  if defined?(Spree::Webhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end
@@ -1,11 +1,15 @@
1
1
  module Spree
2
2
  class OptionType < Spree::Base
3
3
  include UniqueName
4
- include Spree::Metadata
4
+ include Metadata
5
+ include TranslatableResource
5
6
  if defined?(Spree::Webhooks)
6
7
  include Spree::Webhooks::HasWebhooks
7
8
  end
8
9
 
10
+ TRANSLATABLE_FIELDS = %i[name presentation].freeze
11
+ translates(*TRANSLATABLE_FIELDS)
12
+
9
13
  acts_as_list
10
14
  auto_strip_attributes :name, :presentation
11
15
 
@@ -1,10 +1,14 @@
1
1
  module Spree
2
2
  class OptionValue < Spree::Base
3
- include Spree::Metadata
3
+ include Metadata
4
+ include TranslatableResource
4
5
  if defined?(Spree::Webhooks)
5
6
  include Spree::Webhooks::HasWebhooks
6
7
  end
7
8
 
9
+ TRANSLATABLE_FIELDS = %i[name presentation].freeze
10
+ translates(*TRANSLATABLE_FIELDS)
11
+
8
12
  belongs_to :option_type, class_name: 'Spree::OptionType', touch: true, inverse_of: :option_values
9
13
 
10
14
  acts_as_list scope: :option_type
@@ -1,14 +1,6 @@
1
1
  module Spree
2
2
  class Order < Spree::Base
3
3
  module StoreCredit
4
- def add_store_credit_payments(amount = nil)
5
- Spree::Dependencies.checkout_add_store_credit_service.constantize.call(order: self, amount: amount)
6
- end
7
-
8
- def remove_store_credit_payments
9
- Spree::Dependencies.checkout_remove_store_credit_service.constantize.call(order: self)
10
- end
11
-
12
4
  def covered_by_store_credit?
13
5
  return false unless user
14
6
 
@@ -20,10 +20,10 @@ module Spree
20
20
  include Spree::Core::NumberGenerator.new(prefix: 'R')
21
21
  include Spree::Core::TokenGenerator
22
22
 
23
- include Spree::NumberIdentifier
24
- include Spree::NumberAsParam
23
+ include NumberIdentifier
24
+ include NumberAsParam
25
25
  include SingleStoreResource
26
- include Spree::MemoizedData
26
+ include MemoizedData
27
27
  include Spree::Metadata
28
28
  if defined?(Spree::Webhooks)
29
29
  include Spree::Webhooks::HasWebhooks
@@ -3,9 +3,9 @@ require_dependency 'spree/payment/processing'
3
3
  module Spree
4
4
  class Payment < Spree::Base
5
5
  include Spree::Core::NumberGenerator.new(prefix: 'P', letters: true, length: 7)
6
- include Spree::NumberIdentifier
7
- include Spree::NumberAsParam
8
- include Spree::Metadata
6
+ include NumberIdentifier
7
+ include NumberAsParam
8
+ include Metadata
9
9
  if defined?(Spree::Webhooks)
10
10
  include Spree::Webhooks::HasWebhooks
11
11
  end
@@ -3,7 +3,7 @@ module Spree
3
3
  acts_as_paranoid
4
4
  acts_as_list
5
5
 
6
- include Spree::MultiStoreResource
6
+ include MultiStoreResource
7
7
  include Spree::Metadata
8
8
  if defined?(Spree::Security::PaymentMethods)
9
9
  include Spree::Security::PaymentMethods
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class PaymentSource < Spree::Base
3
- include Spree::Metadata
3
+ include Metadata
4
4
 
5
5
  belongs_to :payment_method, class_name: 'Spree::PaymentMethod'
6
6
  belongs_to :user, class_name: 'Spree::User', optional: true
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class Price < Spree::Base
3
- include Spree::VatPriceCalculation
3
+ include VatPriceCalculation
4
4
  if defined?(Spree::Webhooks)
5
5
  include Spree::Webhooks::HasWebhooks
6
6
  end