spree_core 5.0.4 → 5.1.0.beta2

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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/logo.png +0 -0
  3. data/app/finders/spree/countries/find.rb +0 -8
  4. data/app/finders/spree/products/find.rb +28 -1
  5. data/app/finders/spree/taxons/find.rb +1 -1
  6. data/app/helpers/spree/base_helper.rb +4 -16
  7. data/app/helpers/spree/integrations_helper.rb +15 -0
  8. data/app/helpers/spree/mail_helper.rb +4 -3
  9. data/app/helpers/spree/products_helper.rb +1 -4
  10. data/app/javascript/spree/core/controllers/disable_submit_button_controller.js +19 -0
  11. data/app/mailers/spree/invitation_mailer.rb +24 -0
  12. data/app/models/concerns/spree/integrations_concern.rb +11 -0
  13. data/app/models/concerns/spree/product_scopes.rb +6 -6
  14. data/app/models/concerns/spree/translatable_resource.rb +4 -0
  15. data/app/models/concerns/spree/translatable_resource_scopes.rb +17 -3
  16. data/app/models/concerns/spree/unique_name.rb +2 -0
  17. data/app/models/concerns/spree/user_management.rb +33 -0
  18. data/app/models/concerns/spree/user_methods.rb +19 -0
  19. data/app/models/concerns/spree/user_roles.rb +43 -17
  20. data/app/models/spree/ability.rb +8 -6
  21. data/app/models/spree/asset.rb +1 -6
  22. data/app/models/spree/base.rb +1 -0
  23. data/app/models/spree/base_analytics_event_handler.rb +7 -2
  24. data/app/models/spree/classification.rb +13 -0
  25. data/app/models/spree/custom_domain.rb +2 -1
  26. data/app/models/spree/export.rb +1 -1
  27. data/app/models/spree/integration.rb +63 -0
  28. data/app/models/spree/invitation.rb +153 -0
  29. data/app/models/spree/invitations/store.rb +6 -0
  30. data/app/models/spree/order.rb +16 -1
  31. data/app/models/spree/order_merger.rb +7 -5
  32. data/app/models/spree/product_property.rb +1 -14
  33. data/app/models/spree/property.rb +3 -1
  34. data/app/models/spree/reports/sales_total.rb +5 -1
  35. data/app/models/spree/role.rb +16 -0
  36. data/app/models/spree/role_user.rb +32 -1
  37. data/app/models/spree/shipment_handler.rb +1 -0
  38. data/app/models/spree/shipping_method.rb +1 -1
  39. data/app/models/spree/store.rb +9 -4
  40. data/app/models/spree/store_credit_category.rb +4 -0
  41. data/app/models/spree/taxon.rb +4 -3
  42. data/app/services/spree/country_to_timezone.rb +273 -0
  43. data/app/services/spree/seeds/admin_user.rb +4 -2
  44. data/app/services/spree/seeds/all.rb +3 -1
  45. data/app/services/spree/seeds/digital_delivery.rb +20 -0
  46. data/app/services/spree/seeds/returns_environment.rb +27 -0
  47. data/app/services/spree/seeds/tax_categories.rb +12 -0
  48. data/app/services/spree/stores/settings_defaults_by_country.rb +38 -0
  49. data/app/services/spree/tags/bulk_add.rb +13 -7
  50. data/app/views/spree/invitation_mailer/invitation_accepted.html.erb +12 -0
  51. data/app/views/spree/invitation_mailer/invitation_email.html.erb +21 -0
  52. data/config/locales/en.yml +43 -9
  53. data/db/migrate/20250407085228_create_spree_integrations.rb +12 -0
  54. data/db/migrate/20250410061306_create_spree_invitations.rb +20 -0
  55. data/db/migrate/20250418174652_add_resource_to_spree_role_users.rb +8 -0
  56. data/db/migrate/20250508060800_add_selected_locale_to_spree_admin_users.rb +8 -0
  57. data/db/migrate/20250509143831_add_session_id_to_spree_assets.rb +5 -0
  58. data/lib/generators/spree/authentication/devise/devise_generator.rb +5 -2
  59. data/lib/generators/spree/authentication/devise/templates/authentication_helpers.rb.tt +3 -3
  60. data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
  61. data/lib/generators/spree/dummy/templates/app/assets/config/manifest.js +0 -0
  62. data/lib/generators/spree/dummy/templates/rails/application.rb +1 -2
  63. data/lib/generators/spree/install/install_generator.rb +5 -0
  64. data/lib/spree/core/controller_helpers/auth.rb +15 -14
  65. data/lib/spree/core/controller_helpers/common.rb +0 -71
  66. data/lib/spree/core/controller_helpers/currency.rb +11 -0
  67. data/lib/spree/core/controller_helpers/strong_parameters.rb +3 -2
  68. data/lib/spree/core/engine.rb +14 -3
  69. data/lib/spree/core/preferences/preferable.rb +10 -0
  70. data/lib/spree/core/preferences/preferable_class_methods.rb +52 -0
  71. data/lib/spree/core/version.rb +1 -1
  72. data/lib/spree/core.rb +1 -0
  73. data/lib/spree/permitted_attributes.rb +121 -13
  74. data/lib/spree/testing_support/controller_requests.rb +0 -92
  75. data/lib/spree/testing_support/factories/integration_factory.rb +7 -0
  76. data/lib/spree/testing_support/factories/invitation_factory.rb +6 -0
  77. data/lib/spree/testing_support/factories/page_block_factory.rb +1 -0
  78. data/lib/spree/testing_support/factories/promotion_action_factory.rb +4 -0
  79. data/lib/spree/testing_support/factories/user_factory.rb +14 -1
  80. data/lib/spree/translation_migrations.rb +27 -15
  81. data/lib/tasks/core.rake +8 -0
  82. metadata +43 -7
  83. data/app/validators/db_maximum_length_validator.rb +0 -16
  84. data/lib/generators/spree/dummy/templates/rails/script/rails +0 -6
@@ -2,38 +2,66 @@ module Spree
2
2
  module PermittedAttributes
3
3
  ATTRIBUTES = [
4
4
  :address_attributes,
5
+ :asset_attributes,
5
6
  :checkout_attributes,
6
7
  :classification_attributes,
7
8
  :cms_page_attributes,
8
9
  :cms_section_attributes,
10
+ :custom_domain_attributes,
9
11
  :customer_return_attributes,
10
12
  :digital_attributes,
11
13
  :digital_link_attributes,
14
+ :export_attributes,
12
15
  :image_attributes,
16
+ :integration_attributes,
13
17
  :inventory_unit_attributes,
18
+ :invitation_attributes,
14
19
  :line_item_attributes,
15
20
  :menu_attributes,
16
21
  :menu_item_attributes,
17
22
  :option_type_attributes,
18
23
  :option_value_attributes,
24
+ :page_attributes,
25
+ :page_block_attributes,
26
+ :page_link_attributes,
27
+ :page_section_attributes,
19
28
  :payment_attributes,
29
+ :payment_method_attributes,
20
30
  :product_attributes,
31
+ :promotion_attributes,
32
+ :promotion_rule_attributes,
33
+ :promotion_action_attributes,
21
34
  :product_properties_attributes,
22
35
  :property_attributes,
36
+ :refund_attributes,
37
+ :refund_reason_attributes,
38
+ :reimbursement_attributes,
39
+ :reimbursement_type_attributes,
40
+ :report_attributes,
23
41
  :return_authorization_attributes,
42
+ :return_authorization_reason_attributes,
43
+ :role_attributes,
24
44
  :shipment_attributes,
45
+ :shipping_method_attributes,
46
+ :shipping_category_attributes,
25
47
  :source_attributes,
26
48
  :stock_item_attributes,
27
49
  :stock_location_attributes,
28
50
  :stock_movement_attributes,
51
+ :stock_transfer_attributes,
29
52
  :store_attributes,
30
53
  :store_credit_attributes,
54
+ :store_credit_category_attributes,
55
+ :tax_rate_attributes,
56
+ :tax_category_attributes,
31
57
  :taxon_attributes,
32
58
  :taxonomy_attributes,
59
+ :theme_attributes,
33
60
  :user_attributes,
34
61
  :variant_attributes,
35
62
  :wishlist_attributes,
36
- :wished_item_attributes
63
+ :wished_item_attributes,
64
+ :zone_attributes
37
65
  ]
38
66
 
39
67
  mattr_reader(*ATTRIBUTES)
@@ -47,6 +75,8 @@ module Spree
47
75
  state: [:name, :abbr] }
48
76
  ]
49
77
 
78
+ @@asset_attributes = [:type, :viewable_id, :viewable_type, :attachment, :alt, :position]
79
+
50
80
  @@checkout_attributes = [
51
81
  :coupon_code, :email, :shipping_method_id, :special_instructions, :use_billing, :use_shipping,
52
82
  :user_id, :bill_address_id, :ship_address_id, :accept_marketing, :signup_for_an_account
@@ -60,6 +90,8 @@ module Spree
60
90
 
61
91
  @@cms_section_attributes = [:name, :cms_page_id, :fit, :destination, { content: {}, settings: {} }]
62
92
 
93
+ @@custom_domain_attributes = [:url, :default]
94
+
63
95
  @@customer_return_attributes = [:stock_location_id, {
64
96
  return_items_attributes: [:id, :inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount,
65
97
  :acceptance_status, :exchange_variant_id, :resellable]
@@ -69,24 +101,41 @@ module Spree
69
101
 
70
102
  @@digital_link_attributes = [:access_counter]
71
103
 
104
+ @@export_attributes = [:type, :format, :record_selection, search_params: {}]
105
+
72
106
  @@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]
73
107
 
108
+ @@integration_attributes = [:type, :active]
109
+
74
110
  @@inventory_unit_attributes = [:shipment, :shipment_id, :variant_id]
75
111
 
112
+ @@invitation_attributes = [:email, :expires_at, :role_id]
113
+
76
114
  @@line_item_attributes = [:id, :variant_id, :quantity]
77
115
 
78
116
  @@menu_attributes = [:name, :locale, :location]
79
117
 
80
- @@menu_item_attributes = [:name, :subtite, :destination, :new_window, :item_type,
118
+ @@menu_item_attributes = [:name, :subtitle, :destination, :new_window, :item_type,
81
119
  :linked_resource_type, :linked_resource_id, :code, :menu_id]
82
120
 
83
- @@option_type_attributes = [:name, :presentation, :option_values_attributes]
121
+ @@option_type_attributes = [:name, :presentation, :position, :filterable,
122
+ option_values_attributes: [:id, :name, :presentation, :position, :_destroy]]
123
+
124
+ @@option_value_attributes = [:name, :presentation, :position]
125
+
126
+ @@page_attributes = [:name, :slug, :meta_title, :meta_description, :meta_keywords]
127
+
128
+ @@page_block_attributes = [:type, :name, :position]
84
129
 
85
- @@option_value_attributes = [:name, :presentation]
130
+ @@page_link_attributes = [:linkable_id, :linkable_type, :position, :label, :url]
131
+
132
+ @@page_section_attributes = [:type, :name, :position, :asset]
86
133
 
87
134
  @@payment_attributes = [:amount, :payment_method_id, :payment_method]
88
135
 
89
- @@product_properties_attributes = [:property_name, :value, :position]
136
+ @@payment_method_attributes = [:name, :type, :description, :active, :display_on, :auto_capture, :position]
137
+
138
+ @@product_properties_attributes = [:property_name, :property_id, :value, :position, :_destroy]
90
139
 
91
140
  @@product_attributes = [
92
141
  :name, :description, :available_on, :make_active_at, :discontinue_on, :permalink, :meta_description,
@@ -94,24 +143,60 @@ module Spree
94
143
  :option_values_hash, :weight, :height, :width, :depth,
95
144
  :shipping_category_id, :tax_category_id,
96
145
  :cost_currency, :cost_price, :compare_at_price,
97
- :slug,
146
+ :slug, :track_inventory, :backorderable, :barcode, :status,
147
+ :weight_unit, :dimensions_unit,
98
148
  {
99
149
  tag_list: [],
150
+ label_list: [],
100
151
  option_type_ids: [],
101
- taxon_ids: []
152
+ taxon_ids: [],
153
+ store_ids: [],
154
+ product_option_types_attributes: [:id, :option_type_id, :position, :_destroy]
102
155
  }
103
156
  ]
104
157
 
105
- @@property_attributes = [:name, :presentation, :position]
158
+ @@promotion_attributes = [:name, :description, :starts_at, :expires_at, :code, :usage_limit, :path, :match_policy,
159
+ :advertise, :promotion_category_id, :code_prefix, :kind, :number_of_codes, :multi_codes, store_ids: []]
160
+
161
+ @@promotion_rule_attributes = [:type, :preferred_match_policy, user_ids_to_add: [], product_ids_to_add: [], taxon_ids_to_add: []]
162
+
163
+ @@promotion_action_attributes = [:type, :calculator_type, calculator_attributes: {}, promotion_action_line_items_attributes: [:id, :promotion_action_id, :variant_id, :quantity, :_destroy]]
164
+
165
+ @@property_attributes = [:name, :presentation, :position, :kind, :display_on]
166
+
167
+ @@refund_attributes = [:amount, :refund_reason_id]
168
+
169
+ @@refund_reason_attributes = [:name, :active, :mutable]
170
+
171
+ @@reimbursement_attributes = [return_items_attributes: [:id, :override_reimbursement_type_id, :pre_tax_amount, :exchange_variant_id]]
172
+
173
+ @@reimbursement_type_attributes = [:name, :type, :active, :mutable]
174
+
175
+ @@report_attributes = [:type, :date_from, :date_to, :currency]
106
176
 
107
177
  @@return_authorization_attributes = [:amount, :memo, :stock_location_id, :inventory_units_attributes,
108
- :return_authorization_reason_id]
178
+ :return_authorization_reason_id, {
179
+ return_items_attributes: [:id, :inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount,
180
+ :acceptance_status, :exchange_variant_id, :resellable]
181
+ }]
182
+
183
+ @@return_authorization_reason_attributes = [:name, :active]
184
+
185
+ @@return_item_attributes = [:inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount, :acceptance_status, :exchange_variant_id, :resellable]
186
+
187
+ @@role_attributes = [:name]
109
188
 
110
189
  @@shipment_attributes = [
111
190
  :order, :special_instructions, :stock_location_id, :id,
112
191
  :tracking, :address, :inventory_units, :selected_shipping_rate_id
113
192
  ]
114
193
 
194
+ @@shipping_category_attributes = [:name]
195
+
196
+ @@shipping_method_attributes = [:name, :code,:tracking_url, :tax_category_id, :display_on,
197
+ :estimated_transit_business_days_min, :estimated_transit_business_days_max,
198
+ :calculator_type, :preferences, zone_ids: [], shipping_category_ids: [], calculator_attributes: {}]
199
+
115
200
  # month / year may be provided by some sources, or others may elect to use one field
116
201
  @@source_attributes = [
117
202
  :id, :number, :month, :year, :expiry, :verification_value,
@@ -119,7 +204,7 @@ module Spree
119
204
  :gateway_payment_profile_id, :last_digits, :name, :encrypted_data
120
205
  ]
121
206
 
122
- @@stock_item_attributes = [:variant, :stock_location, :backorderable, :variant_id]
207
+ @@stock_item_attributes = [:variant_id, :stock_location_id, :backorderable, :count_on_hand]
123
208
 
124
209
  @@stock_location_attributes = [
125
210
  :name, :active, :address1, :address2, :city, :zipcode,
@@ -131,6 +216,9 @@ module Spree
131
216
  :quantity, :stock_item, :stock_item_id, :originator, :action
132
217
  ]
133
218
 
219
+ @@stock_transfer_attributes = [:source_location_id, :destination_location_id, :reference,
220
+ stock_movements_attributes: [:variant_id, :quantity, :originator_id, :stock_item_id]]
221
+
134
222
  @@store_attributes = [:name, :url, :seo_title, :code, :meta_keywords,
135
223
  :meta_description, :default_currency, :mail_from_address,
136
224
  :customer_support_email, :description, :address, :contact_phone,
@@ -148,28 +236,48 @@ module Spree
148
236
 
149
237
  @@store_credit_attributes = %i[amount currency category_id memo]
150
238
 
239
+ @@store_credit_category_attributes = [:name]
240
+
151
241
  @@taxonomy_attributes = [:name]
152
242
 
243
+ @@tax_category_attributes = [:name, :tax_code,:description, :is_default]
244
+
245
+ @@tax_rate_attributes = [:name, :amount, :zone_id, :tax_category_id, :included_in_price, :show_rate_in_label, :calculator_type, calculator_attributes: {}]
246
+
153
247
  @@taxon_attributes = [
154
248
  :name, :parent_id, :position, :icon, :description, :permalink, :hide_from_nav,
155
- :taxonomy_id, :meta_description, :meta_keywords, :meta_title, :child_index
249
+ :taxonomy_id, :meta_description, :meta_keywords, :meta_title, :child_index,
250
+ :automatic, :rules_match_policy, :sort_order,
251
+ :image, :square_image, :description,
252
+ taxon_rules_attributes: [:id, :type, :value, :match_policy, :_destroy],
156
253
  ]
157
254
 
255
+ @@theme_attributes = [:name, :type, :default]
256
+
158
257
  @@user_attributes = [:email, :bill_address_id, :ship_address_id, :password, :first_name, :last_name,
159
258
  :password_confirmation, :selected_locale, :avatar, :accepts_email_marketing, :phone,
160
259
  { public_metadata: {}, private_metadata: {}, tag_list: [] }]
161
260
 
162
261
  @@variant_attributes = [
163
262
  :name, :presentation, :cost_price, :discontinue_on, :lock_version,
164
- :position, :track_inventory,
263
+ :position, :track_inventory, :tax_category_id,
165
264
  :product_id, :product, :option_values_attributes, :price, :compare_at_price,
166
265
  :weight, :height, :width, :depth, :sku, :barcode, :cost_currency,
167
266
  :weight_unit, :dimensions_unit,
168
- { options: [:name, :value], option_value_ids: [] }
267
+ {
268
+ options: [:id, :name, :value, :position, :_destroy],
269
+ stock_items_attributes: [:id, :count_on_hand, :stock_location_id, :backorderable, :_destroy],
270
+ prices_attributes: [:id, :amount, :compare_at_amount, :currency, :_destroy],
271
+ price: {},
272
+ option_value_variants_attributes: [:id, :option_value_id, :_destroy],
273
+ option_value_ids: []
274
+ }
169
275
  ]
170
276
 
171
277
  @@wishlist_attributes = [:name, :is_default, :is_private]
172
278
 
173
279
  @@wished_item_attributes = [:variant_id, :quantity]
280
+
281
+ @@zone_attributes = [:name, :description, :default_tax, :kind, :states_country_id, country_ids: [], state_ids: []]
174
282
  end
175
283
  end
@@ -6,98 +6,6 @@ module Spree
6
6
  included do
7
7
  routes { Spree::Core::Engine.routes }
8
8
  end
9
-
10
- def spree_get(action, parameters = nil, session = nil, flash = nil)
11
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
12
- ControllerRequests#spree_get is deprecated and will be removed in Spree 5.0.
13
- Please use get, params: {}
14
- DEPRECATION
15
- process_spree_action(action, parameters, session, flash, 'GET')
16
- end
17
-
18
- # Executes a request simulating POST HTTP method and set/volley the response
19
- def spree_post(action, parameters = nil, session = nil, flash = nil)
20
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
21
- ControllerRequests#spree_post is deprecated and will be removed in Spree 5.0.
22
- Please use post, params: {}
23
- DEPRECATION
24
- process_spree_action(action, parameters, session, flash, 'POST')
25
- end
26
-
27
- # Executes a request simulating PUT HTTP method and set/volley the response
28
- def spree_put(action, parameters = nil, session = nil, flash = nil)
29
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
30
- ControllerRequests#spree_put is deprecated and will be removed in Spree 5.0.
31
- Please use put, params: {}
32
- DEPRECATION
33
- process_spree_action(action, parameters, session, flash, 'PUT')
34
- end
35
-
36
- # # Executes a request simulating PATCH HTTP method and set/volley the response
37
- def spree_patch(action, parameters = nil, session = nil, flash = nil)
38
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
39
- ControllerRequests#spree_patch is deprecated and will be removed in Spree 5.0.
40
- Please use patch, params: {}
41
- DEPRECATION
42
- process_spree_action(action, parameters, session, flash, 'PATCH')
43
- end
44
-
45
- # Executes a request simulating DELETE HTTP method and set/volley the response
46
- def spree_delete(action, parameters = nil, session = nil, flash = nil)
47
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
48
- ControllerRequests#spree_delete is deprecated and will be removed in Spree 5.0.
49
- Please use delete, params: {}
50
- DEPRECATION
51
- process_spree_action(action, parameters, session, flash, 'DELETE')
52
- end
53
-
54
- def spree_xhr_get(action, parameters = nil, session = nil, flash = nil)
55
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
56
- ControllerRequests#spree_xhr_get is deprecated and will be removed in Spree 5.0.
57
- DEPRECATION
58
- process_spree_xhr_action(action, parameters, session, flash, :get)
59
- end
60
-
61
- def spree_xhr_post(action, parameters = nil, session = nil, flash = nil)
62
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
63
- ControllerRequests#spree_xhr_post is deprecated and will be removed in Spree 5.0.
64
- DEPRECATION
65
- process_spree_xhr_action(action, parameters, session, flash, :post)
66
- end
67
-
68
- def spree_xhr_put(action, parameters = nil, session = nil, flash = nil)
69
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
70
- ControllerRequests#spree_xhr_put is deprecated and will be removed in Spree 5.0.
71
- DEPRECATION
72
- process_spree_xhr_action(action, parameters, session, flash, :put)
73
- end
74
-
75
- def spree_xhr_patch(action, parameters = nil, session = nil, flash = nil)
76
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
77
- ControllerRequests#spree_xhr_patch is deprecated and will be removed in Spree 5.0.
78
- DEPRECATION
79
- process_spree_xhr_action(action, parameters, session, flash, :patch)
80
- end
81
-
82
- def spree_xhr_delete(action, parameters = nil, session = nil, flash = nil)
83
- Spree::Deprecation.warn(<<-DEPRECATION, caller)
84
- ControllerRequests#spree_xhr_delete is deprecated and will be removed in Spree 5.0.
85
- DEPRECATION
86
- process_spree_xhr_action(action, parameters, session, flash, :delete)
87
- end
88
-
89
- private
90
-
91
- def process_spree_action(action, parameters = nil, session = nil, flash = nil, method = 'GET')
92
- parameters ||= {}
93
- process(action, method: method, params: parameters, session: session, flash: flash)
94
- end
95
-
96
- def process_spree_xhr_action(action, parameters = nil, session = nil, flash = nil, method = :get)
97
- parameters ||= {}
98
- parameters.reverse_merge!(format: :json)
99
- process(action, method: method, params: parameters, session: session, flash: flash, xhr: true)
100
- end
101
9
  end
102
10
  end
103
11
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :integration, class: Spree::Integration do
3
+ type { 'Spree::Integration' }
4
+ store { Spree::Store.default }
5
+ active { true }
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :invitation, class: Spree::Invitation do
3
+ email { FFaker::Internet.email }
4
+ inviter { create(:admin_user) }
5
+ end
6
+ end
@@ -16,6 +16,7 @@ FactoryBot.define do
16
16
  type { 'Spree::PageBlocks::Heading' }
17
17
  end
18
18
 
19
+ factory :buttons_block, traits: [:buttons], class: Spree::PageBlocks::Buttons
19
20
  factory :heading_block, traits: [:heading], class: Spree::PageBlocks::Heading
20
21
  end
21
22
  end
@@ -7,4 +7,8 @@ FactoryBot.define do
7
7
  association :promotion
8
8
  association :calculator, factory: :flat_rate_calculator
9
9
  end
10
+
11
+ factory :promotion_action_create_line_items, class: Spree::Promotion::Actions::CreateLineItems do
12
+ association :promotion
13
+ end
10
14
  end
@@ -30,6 +30,19 @@ FactoryBot.define do
30
30
  first_name { FFaker::Name.first_name }
31
31
  last_name { FFaker::Name.last_name }
32
32
 
33
- spree_roles { [Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')] }
33
+ transient do
34
+ without_admin_role { false }
35
+ end
36
+
37
+ trait :without_admin_role do
38
+ without_admin_role { true }
39
+ end
40
+
41
+ after(:create) do |user, evaluator|
42
+ unless evaluator.without_admin_role
43
+ admin_role = Spree::Role.default_admin_role
44
+ create(:role_user, user: user, role: admin_role) unless user.has_spree_role?(admin_role.name)
45
+ end
46
+ end
34
47
  end
35
48
  end
@@ -12,14 +12,24 @@ module Spree
12
12
  nullify_translatable_fields = @resource_class.translatable_fields.map { |f| "#{f}=null" }.join(', ')
13
13
 
14
14
  unless @resource_class::Translation.exists?
15
- ActiveRecord::Base.connection.execute("
16
- INSERT INTO #{@translations_table} (#{@translatable_fields}, #{@foreign_key}, locale, created_at, updated_at)
17
- SELECT #{@translatable_fields}, id, '#{@default_locale}' as locale, created_at, updated_at FROM #{@resource_class.table_name};
18
- ")
19
- ActiveRecord::Base.connection.execute("
20
- UPDATE #{@resource_class.table_name}
21
- SET #{nullify_translatable_fields};
22
- ")
15
+ # Copy data from main table to translations table
16
+ @resource_class.find_each do |resource|
17
+ translation_attrs = @resource_class.translatable_fields.each_with_object({}) do |field, attrs|
18
+ attrs[field] = resource[field]
19
+ end
20
+
21
+ @resource_class::Translation.create!(
22
+ translation_attrs.merge(
23
+ @foreign_key => resource.id,
24
+ locale: @default_locale,
25
+ created_at: resource.created_at,
26
+ updated_at: resource.updated_at
27
+ )
28
+ )
29
+ end
30
+
31
+ # Nullify translatable fields in main table
32
+ @resource_class.update_all(nullify_translatable_fields)
23
33
  end
24
34
  end
25
35
 
@@ -27,14 +37,16 @@ module Spree
27
37
  translation_table_fields = @resource_class.translatable_fields.map { |f| "#{@translations_table}.#{f}" }.join(', ')
28
38
  row_expression = @resource_class.translatable_fields.count == 1 ? 'ROW' : ''
29
39
 
30
- ActiveRecord::Base.connection.execute("
31
- UPDATE #{@resource_class.table_name}
32
- SET (#{@translatable_fields}) = #{row_expression}(#{translation_table_fields})
33
- FROM #{@translations_table}
34
- WHERE #{@translations_table}.#{@foreign_key} = #{@resource_class.table_name}.id
35
- ")
40
+ # Update main table with translations
41
+ @resource_class::Translation.find_each do |translation|
42
+ resource = @resource_class.find(translation[@foreign_key])
43
+ @resource_class.translatable_fields.each do |field|
44
+ resource.update_column(field, translation[field])
45
+ end
46
+ end
36
47
 
37
- ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{@translations_table}")
48
+ # Clear translations table
49
+ @resource_class::Translation.delete_all
38
50
  end
39
51
  end
40
52
  end
data/lib/tasks/core.rake CHANGED
@@ -184,6 +184,14 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]}
184
184
  end
185
185
  end
186
186
  end
187
+
188
+ task migrate_admin_users_to_role_users: :environment do |_t, _args|
189
+ Spree.admin_user_class.all.each do |admin_user|
190
+ Spree::Store.all.each do |store|
191
+ store.add_user(admin_user)
192
+ end
193
+ end
194
+ end
187
195
  end
188
196
 
189
197
  namespace :core do