spree_core 5.4.0.beta → 5.4.0.beta3

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 (161) hide show
  1. checksums.yaml +4 -4
  2. data/app/finders/spree/products/find.rb +2 -42
  3. data/app/helpers/spree/base_helper.rb +1 -54
  4. data/app/mailers/spree/base_mailer.rb +4 -3
  5. data/app/models/concerns/spree/adjustment_source.rb +0 -8
  6. data/app/models/concerns/spree/admin_user_methods.rb +0 -2
  7. data/app/models/concerns/spree/image_methods.rb +4 -0
  8. data/app/models/concerns/spree/metadata.rb +10 -0
  9. data/app/models/concerns/spree/product_scopes.rb +21 -49
  10. data/app/models/concerns/spree/stores/markets.rb +7 -7
  11. data/app/models/concerns/spree/vat_price_calculation.rb +2 -2
  12. data/app/models/spree/ability.rb +5 -5
  13. data/app/models/spree/address.rb +3 -2
  14. data/app/models/spree/adjustable/promotion_accumulator.rb +1 -1
  15. data/app/models/spree/adjustment.rb +1 -20
  16. data/app/models/spree/api_key.rb +60 -2
  17. data/app/models/spree/country.rb +7 -3
  18. data/app/models/spree/credit_card.rb +0 -27
  19. data/app/models/spree/current.rb +38 -2
  20. data/app/models/spree/exports/products.rb +0 -6
  21. data/app/models/spree/gateway/bogus.rb +9 -9
  22. data/app/models/spree/gateway.rb +0 -3
  23. data/app/models/spree/gift_card_batch.rb +4 -0
  24. data/app/models/spree/image/configuration/active_storage.rb +0 -2
  25. data/app/models/spree/image.rb +7 -31
  26. data/app/models/spree/log_entry.rb +8 -5
  27. data/app/models/spree/market.rb +1 -2
  28. data/app/models/spree/market_country.rb +17 -0
  29. data/app/models/spree/newsletter_subscriber.rb +0 -3
  30. data/app/models/spree/order/checkout.rb +0 -18
  31. data/app/models/spree/order.rb +22 -16
  32. data/app/models/spree/payment/gateway_options.rb +2 -2
  33. data/app/models/spree/payment/processing.rb +5 -5
  34. data/app/models/spree/payment.rb +1 -1
  35. data/app/models/spree/payment_connection_error.rb +3 -0
  36. data/app/models/spree/payment_method/check.rb +1 -1
  37. data/app/models/spree/payment_method/store_credit.rb +5 -5
  38. data/app/models/spree/payment_response.rb +70 -0
  39. data/app/models/spree/permission_sets/default_customer.rb +0 -5
  40. data/app/models/spree/permission_sets/product_display.rb +0 -2
  41. data/app/models/spree/permission_sets/product_management.rb +0 -2
  42. data/app/models/spree/product.rb +5 -85
  43. data/app/models/spree/promotion.rb +2 -14
  44. data/app/models/spree/promotion_handler/coupon.rb +3 -3
  45. data/app/models/spree/prototype.rb +0 -3
  46. data/app/models/spree/refund.rb +6 -2
  47. data/app/models/spree/reimbursement.rb +0 -2
  48. data/app/models/spree/shipment.rb +0 -1
  49. data/app/models/spree/shipment_handler.rb +0 -2
  50. data/app/models/spree/shipping_category.rb +3 -3
  51. data/app/models/spree/store.rb +10 -49
  52. data/app/models/spree/store_credit.rb +4 -0
  53. data/app/models/spree/tax_category.rb +1 -11
  54. data/app/models/spree/taxon.rb +0 -16
  55. data/app/models/spree/variant.rb +2 -40
  56. data/app/models/spree/zone.rb +1 -4
  57. data/app/services/spree/cart/add_item.rb +8 -4
  58. data/app/services/spree/cart/create.rb +13 -2
  59. data/app/services/spree/newsletter/subscribe.rb +2 -2
  60. data/app/services/spree/products/duplicator.rb +0 -12
  61. data/app/services/spree/products/prepare_nested_attributes.rb +0 -12
  62. data/app/subscribers/spree/invitation_email_subscriber.rb +1 -1
  63. data/config/locales/en.yml +4 -20
  64. data/db/migrate/20210914000000_spree_four_three.rb +0 -38
  65. data/db/migrate/20210915064329_add_metadata_to_spree_multiple_tables.rb +0 -1
  66. data/db/migrate/20260226000000_add_locale_to_spree_orders.rb +5 -0
  67. data/db/migrate/20260226100000_add_token_digest_to_spree_api_keys.rb +21 -0
  68. data/lib/spree/core/configuration.rb +0 -3
  69. data/lib/spree/core/controller_helpers/strong_parameters.rb +1 -2
  70. data/lib/spree/core/dependencies.rb +2 -10
  71. data/lib/spree/core/engine.rb +0 -13
  72. data/lib/spree/core/pricing/resolver.rb +1 -9
  73. data/lib/spree/core/version.rb +1 -1
  74. data/lib/spree/core.rb +10 -26
  75. data/lib/spree/permitted_attributes.rb +2 -14
  76. data/lib/spree/testing_support/factories/order_factory.rb +1 -0
  77. data/lib/spree/testing_support/factories/payment_method_factory.rb +1 -6
  78. data/lib/spree/testing_support/factories/product_factory.rb +0 -7
  79. data/lib/spree/testing_support/factories/prototype_factory.rb +0 -2
  80. data/lib/tasks/cli.rake +50 -0
  81. data/lib/tasks/core.rake +0 -265
  82. metadata +9 -111
  83. data/app/finders/spree/posts/find.rb +0 -137
  84. data/app/finders/spree/product_properties/find_available.rb +0 -20
  85. data/app/helpers/spree/mail_helper.rb +0 -27
  86. data/app/jobs/spree/api_key_touch_job.rb +0 -9
  87. data/app/mailers/spree/test_mailer.rb +0 -8
  88. data/app/models/action_text/video_embed.rb +0 -13
  89. data/app/models/concerns/spree/filter_param.rb +0 -21
  90. data/app/models/concerns/spree/has_one_link.rb +0 -42
  91. data/app/models/concerns/spree/linkable.rb +0 -9
  92. data/app/models/concerns/spree/previewable.rb +0 -17
  93. data/app/models/spree/data_feed/google.rb +0 -15
  94. data/app/models/spree/data_feed.rb +0 -42
  95. data/app/models/spree/gateway/bogus_simple.rb +0 -24
  96. data/app/models/spree/newsletter_subscriber/emails.rb +0 -12
  97. data/app/models/spree/order/emails.rb +0 -24
  98. data/app/models/spree/post.rb +0 -108
  99. data/app/models/spree/post_category.rb +0 -46
  100. data/app/models/spree/product_property.rb +0 -51
  101. data/app/models/spree/property.rb +0 -86
  102. data/app/models/spree/property_prototype.rb +0 -9
  103. data/app/models/spree/reimbursement/emails.rb +0 -11
  104. data/app/models/spree/shipment/emails.rb +0 -11
  105. data/app/models/spree/store_favicon_image.rb +0 -20
  106. data/app/models/spree/store_logo.rb +0 -4
  107. data/app/models/spree/store_mailer_logo.rb +0 -7
  108. data/app/models/spree/taxon_image/configuration/active_storage.rb +0 -26
  109. data/app/models/spree/taxon_image.rb +0 -28
  110. data/app/presenters/spree/filters/properties_presenter.rb +0 -23
  111. data/app/presenters/spree/filters/property_presenter.rb +0 -42
  112. data/app/services/spree/data_feeds/google/optional_attributes.rb +0 -23
  113. data/app/services/spree/data_feeds/google/optional_sub_attributes.rb +0 -21
  114. data/app/services/spree/data_feeds/google/products_list.rb +0 -14
  115. data/app/services/spree/data_feeds/google/required_attributes.rb +0 -68
  116. data/app/services/spree/data_feeds/google/rss.rb +0 -109
  117. data/app/sorters/spree/posts/sort.rb +0 -40
  118. data/app/views/action_text/video_embeds/_thumbnail.html.erb +0 -1
  119. data/app/views/action_text/video_embeds/_video_embed.html.erb +0 -3
  120. data/app/views/layouts/action_text/contents/_content.html.erb +0 -3
  121. data/app/views/spree/test_mailer/test_email.html.erb +0 -40
  122. data/app/views/spree/test_mailer/test_email.text.erb +0 -4
  123. data/config/initializers/oembed.rb +0 -1
  124. data/db/migrate/20221229132350_create_spree_data_feed_settings.rb +0 -14
  125. data/db/migrate/20230109084253_create_product_property_translations.rb +0 -24
  126. data/db/migrate/20230109105943_create_property_translations.rb +0 -24
  127. data/db/migrate/20230415155958_rename_data_feed_settings_table.rb +0 -5
  128. data/db/migrate/20230415160828_rename_data_feed_table_columns.rb +0 -7
  129. data/db/migrate/20230415161226_add_indexes_to_data_feeds_table.rb +0 -5
  130. data/db/migrate/20230512094803_rename_data_feeds_column_provider_to_type.rb +0 -5
  131. data/db/migrate/20240914153106_add_display_on_to_spree_properties.rb +0 -5
  132. data/db/migrate/20240915144935_add_position_to_spree_properties.rb +0 -6
  133. data/db/migrate/20250121160028_create_spree_posts_and_spree_post_categories.rb +0 -33
  134. data/db/migrate/20250127083740_add_kind_to_spree_properties.rb +0 -5
  135. data/db/migrate/20250217171018_create_action_text_video_embeds.rb +0 -11
  136. data/db/migrate/20250305121657_remove_spree_posts_indices.rb +0 -7
  137. data/db/migrate/20250730154601_add_unique_index_on_spree_properties_name.rb +0 -24
  138. data/db/sample_data/posts.rb +0 -7
  139. data/lib/generators/spree/cursor_rules/cursor_rules_generator.rb +0 -19
  140. data/lib/generators/spree/cursor_rules/templates/spree_rules.mdc +0 -387
  141. data/lib/spree/core/controller_helpers/search.rb +0 -17
  142. data/lib/spree/core/importer/order.rb +0 -244
  143. data/lib/spree/core/importer/product.rb +0 -67
  144. data/lib/spree/core/importer.rb +0 -9
  145. data/lib/spree/core/product_filters.rb +0 -218
  146. data/lib/spree/core/query_filters/comparable.rb +0 -50
  147. data/lib/spree/core/query_filters/date.rb +0 -8
  148. data/lib/spree/core/query_filters/number.rb +0 -8
  149. data/lib/spree/core/query_filters/text.rb +0 -36
  150. data/lib/spree/core/query_filters.rb +0 -11
  151. data/lib/spree/core/search/base.rb +0 -144
  152. data/lib/spree/testing_support/factories/favicon_image_factory.rb +0 -9
  153. data/lib/spree/testing_support/factories/google_data_feed_factory.rb +0 -7
  154. data/lib/spree/testing_support/factories/post_category_factory.rb +0 -7
  155. data/lib/spree/testing_support/factories/post_factory.rb +0 -22
  156. data/lib/spree/testing_support/factories/product_property_factory.rb +0 -7
  157. data/lib/spree/testing_support/factories/property_factory.rb +0 -28
  158. data/lib/spree/testing_support/factories/taxon_image_factory.rb +0 -9
  159. data/lib/spree/testing_support/flash.rb +0 -25
  160. data/lib/spree/testing_support/flatpickr_capybara.rb +0 -124
  161. data/lib/tasks/exchanges.rake +0 -66
@@ -39,15 +39,11 @@ module Spree
39
39
  :payment_session_attributes,
40
40
  :payment_setup_session_attributes,
41
41
  :policy_attributes,
42
- :post_attributes,
43
- :post_category_attributes,
44
42
  :price_list_attributes,
45
43
  :product_attributes,
46
44
  :promotion_attributes,
47
45
  :promotion_rule_attributes,
48
46
  :promotion_action_attributes,
49
- :product_properties_attributes,
50
- :property_attributes,
51
47
  :refund_attributes,
52
48
  :refund_reason_attributes,
53
49
  :reimbursement_attributes,
@@ -97,7 +93,7 @@ module Spree
97
93
 
98
94
  @@checkout_attributes = [
99
95
  :coupon_code, :email, :shipping_method_id, :special_instructions, :use_billing, :use_shipping,
100
- :user_id, :bill_address_id, :ship_address_id, :accept_marketing, :signup_for_an_account, :currency,
96
+ :user_id, :bill_address_id, :ship_address_id, :accept_marketing, :signup_for_an_account, :currency, :locale,
101
97
  :internal_note
102
98
  ]
103
99
 
@@ -140,7 +136,7 @@ module Spree
140
136
 
141
137
  @@invitation_attributes = [:email, :expires_at, :role_id]
142
138
 
143
- @@line_item_attributes = [:id, :variant_id, :quantity]
139
+ @@line_item_attributes = [:id, :variant_id, :quantity, { metadata: {} }]
144
140
 
145
141
  @@market_attributes = [:name, :currency, :default_locale, :supported_locales,
146
142
  :tax_inclusive, :default, :position, country_ids: []]
@@ -177,14 +173,8 @@ module Spree
177
173
 
178
174
  @@policy_attributes = [:name, :slug, :body]
179
175
 
180
- @@post_attributes = [:title, :meta_title, :meta_description, :slug, :author_id, :post_category_id, :published_at, :content, :excerpt, :image, tag_list: []]
181
-
182
- @@post_category_attributes = [:title, :slug, :description]
183
-
184
176
  @@price_list_attributes = [:name, :description, :match_policy, :starts_at, :ends_at, :status, :position]
185
177
 
186
- @@product_properties_attributes = [:property_name, :property_id, :value, :position, :_destroy]
187
-
188
178
  @@product_attributes = [
189
179
  :name, :description, :available_on, :make_active_at, :discontinue_on, :permalink, :meta_description,
190
180
  :meta_keywords, :meta_title, :price, :sku, :deleted_at, :prototype_id,
@@ -210,8 +200,6 @@ module Spree
210
200
 
211
201
  @@promotion_action_attributes = [:type, :calculator_type, calculator_attributes: {}, promotion_action_line_items_attributes: [:id, :promotion_action_id, :variant_id, :quantity, :_destroy]]
212
202
 
213
- @@property_attributes = [:name, :presentation, :position, :kind, :display_on]
214
-
215
203
  @@refund_attributes = [:amount, :refund_reason_id]
216
204
 
217
205
  @@refund_reason_attributes = [:name, :active, :mutable]
@@ -5,6 +5,7 @@ FactoryBot.define do
5
5
  completed_at { nil }
6
6
  email { user&.email }
7
7
  currency { 'USD' }
8
+ locale { 'en' }
8
9
 
9
10
  transient do
10
11
  line_items_price { BigDecimal(10) }
@@ -23,12 +23,7 @@ FactoryBot.define do
23
23
  name { 'Credit Card' }
24
24
  end
25
25
 
26
- # authorize.net was moved to spree_gateway.
27
- # Leaving this factory in place with bogus in case anyone is using it.
28
- factory :simple_credit_card_payment_method, parent: :payment_method, class: Spree::Gateway::BogusSimple do
29
- type { 'Spree::Gateway::BogusSimple' }
30
- name { 'Credit Card' }
31
- end
26
+ factory :simple_credit_card_payment_method, parent: :credit_card_payment_method
32
27
 
33
28
  factory :store_credit_payment_method, parent: :payment_method, class: Spree::PaymentMethod::StoreCredit do
34
29
  type { 'Spree::PaymentMethod::StoreCredit' }
@@ -50,13 +50,6 @@ FactoryBot.define do
50
50
  factory :product_with_option_types do
51
51
  after(:create) { |product| create(:product_option_type, product: product) }
52
52
  end
53
- factory :product_with_properties do
54
- after(:create) do |product|
55
- property = create(:property, :brand)
56
- create(:product_property, product: product, property: property, value: 'Epsilon')
57
- end
58
- end
59
-
60
53
  factory :digital_product do
61
54
  track_inventory { false }
62
55
  shipping_category { |r| Spree::ShippingCategory.digital || r.association(:digital_shipping_category) }
@@ -1,11 +1,9 @@
1
1
  FactoryBot.define do
2
2
  factory :prototype, class: Spree::Prototype do
3
3
  name { 'Baseball Cap' }
4
- properties { [build(:property)] }
5
4
  end
6
5
  factory :prototype_with_option_types, class: Spree::Prototype do
7
6
  name { 'Baseball Cap' }
8
- properties { [build(:property)] }
9
7
  option_types { [build(:option_type)] }
10
8
  end
11
9
  end
@@ -0,0 +1,50 @@
1
+ namespace :spree do
2
+ namespace :cli do
3
+ desc 'Ensure a default publishable API key exists and print its token'
4
+ task ensure_api_key: :environment do
5
+ store = Spree::Store.default
6
+ key = store.api_keys.active.publishable.first ||
7
+ store.api_keys.create!(name: 'Default', key_type: 'publishable')
8
+ print key.plaintext_token
9
+ end
10
+
11
+ desc 'Create an API key'
12
+ task create_api_key: :environment do
13
+ name = ENV.fetch('NAME')
14
+ key_type = ENV.fetch('KEY_TYPE')
15
+ store = Spree::Store.default
16
+ key = store.api_keys.create!(name: name, key_type: key_type)
17
+ print key.plaintext_token
18
+ end
19
+
20
+ desc 'List API keys (pipe-delimited)'
21
+ task list_api_keys: :environment do
22
+ Spree::Store.default.api_keys.order(created_at: :desc).each do |k|
23
+ status = k.revoked_at ? 'revoked' : 'active'
24
+ token = k.secret? ? k.token_prefix : k.token
25
+ puts [k.prefixed_id, k.name, k.key_type, token, k.created_at.strftime('%Y-%m-%d %H:%M'), status].join('|')
26
+ end
27
+ end
28
+
29
+ desc 'Revoke an API key by prefixed ID'
30
+ task revoke_api_key: :environment do
31
+ id = ENV.fetch('ID')
32
+ key = Spree::Store.default.api_keys.find_by_prefix_id!(id)
33
+ key.revoke!
34
+ print key.name
35
+ end
36
+
37
+ desc 'Create an admin user'
38
+ task create_admin: :environment do
39
+ email = ENV.fetch('EMAIL')
40
+ password = ENV.fetch('PASSWORD')
41
+ admin = Spree.admin_user_class.create!(
42
+ email: email,
43
+ password: password,
44
+ password_confirmation: password
45
+ )
46
+ admin.add_role('admin', Spree::Store.default)
47
+ print admin.email
48
+ end
49
+ end
50
+ end
data/lib/tasks/core.rake CHANGED
@@ -1,190 +1,6 @@
1
1
  require 'active_record'
2
2
 
3
3
  namespace :db do
4
- desc %q{Loads a specified fixture file:
5
- use rake db:load_file[/absolute/path/to/sample/filename.rb]}
6
-
7
- task :load_file, [:file, :dir] => :environment do |_t, args|
8
- file = Pathname.new(args.file)
9
-
10
- puts "loading ruby #{file}"
11
- load file
12
- end
13
-
14
- desc 'Loads fixtures from the the dir you specify using rake db:load_dir[loadfrom]'
15
- task :load_dir, [:dir] => :environment do |_t, args|
16
- dir = args.dir
17
- dir = File.join(Rails.root, 'db', dir) if Pathname.new(dir).relative?
18
-
19
- ruby_files = {}
20
- Dir.glob(File.join(dir, '**/*.{rb}')).each do |fixture_file|
21
- ext = File.extname fixture_file
22
- ruby_files[File.basename(fixture_file, '.*')] = fixture_file
23
- end
24
- ruby_files.sort.each do |fixture, ruby_file|
25
- # If file exists within application it takes precedence.
26
- if File.exist?(File.join(Rails.root, 'db/default/spree', "#{fixture}.rb"))
27
- ruby_file = File.expand_path(File.join(Rails.root, 'db/default/spree', "#{fixture}.rb"))
28
- end
29
- # an invoke will only execute the task once
30
- Rake::Task['db:load_file'].execute(Rake::TaskArguments.new([:file], [ruby_file]))
31
- end
32
- end
33
-
34
- desc 'Migrate schema to version 0 and back up again. WARNING: Destroys all data in tables!!'
35
- task remigrate: :environment do
36
- require 'highline/import'
37
-
38
- if ENV['SKIP_NAG'] || ENV['OVERWRITE'].to_s.casecmp('true').zero? || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")
39
-
40
- # Drop all tables
41
- ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.drop_table t }
42
-
43
- # Migrate upward
44
- Rake::Task['db:migrate'].invoke
45
-
46
- # Dump the schema
47
- Rake::Task['db:schema:dump'].invoke
48
- else
49
- say 'Task cancelled.'
50
- exit
51
- end
52
- end
53
-
54
- desc 'Bootstrap is: migrating, loading defaults, sample data and seeding (for all extensions) and load_products tasks'
55
- task :bootstrap do
56
- require 'highline/import'
57
-
58
- # remigrate unless production mode (as safety check)
59
- if %w[demo development test].include? Rails.env
60
- if ENV['AUTO_ACCEPT'] || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")
61
- ENV['SKIP_NAG'] = 'yes'
62
- Rake::Task['db:create'].invoke
63
- Rake::Task['db:remigrate'].invoke
64
- else
65
- say 'Task cancelled, exiting.'
66
- exit
67
- end
68
- else
69
- say 'NOTE: Bootstrap in production mode will not drop database before migration'
70
- Rake::Task['db:migrate'].invoke
71
- end
72
-
73
- ActiveRecord::Base.send(:subclasses).each(&:reset_column_information)
74
-
75
- load_defaults = Spree::Country.count == 0
76
- load_defaults ||= agree('Countries present, load sample data anyways? [y/n]: ')
77
- Rake::Task['db:seed'].invoke if load_defaults
78
-
79
- if Rails.env.production? && Spree::Product.count > 0
80
- load_sample = agree('WARNING: In Production and products exist in database, load sample data anyways? [y/n]:')
81
- else
82
- load_sample = true if ENV['AUTO_ACCEPT']
83
- load_sample ||= agree('Load Sample Data? [y/n]: ')
84
- end
85
-
86
- if load_sample
87
- # Reload models' attributes in case they were loaded in old migrations with wrong attributes
88
- ActiveRecord::Base.descendants.each(&:reset_column_information)
89
- Rake::Task['spree_sample:load'].invoke
90
- end
91
-
92
- puts "Bootstrap Complete.\n\n"
93
- end
94
-
95
- desc 'Fix orphan line items after upgrading to Spree 3.1: only needed if you have line items attached to deleted records with Slug (product) and SKU (variant) duplicates of non-deleted records.'
96
- task fix_orphan_line_items: :environment do |_t, _args|
97
- def get_input
98
- STDOUT.flush
99
- input = STDIN.gets.chomp
100
- case input.upcase
101
- when 'Y'
102
- return true
103
-
104
- when 'N'
105
- puts 'aborting .....'
106
- return false
107
- else
108
- return true
109
- end
110
- end
111
-
112
- puts 'WARNING: This task will re-associate any line_items associated with deleted variants to non-deleted variants with matching SKUs. Because other attributes and product associations may switch during the re-association, this may have unintended side-effects. If this task finishes successfully, line items for old order should no longer be orphaned from their variants. You should run this task after you have already run the db migratoin AddDiscontinuedToProductsAndVariants. If the db migration did not warn you that it was leaving deleted records in place because of duplicate SKUs, then you do not need to run this rake task.'
113
- puts 'Are you sure you want to continue? (Y/n):'
114
-
115
- if get_input
116
- puts 'looping through all your deleted variants ...'
117
-
118
- # first verify that I can really fix all of your line items
119
-
120
- no_live_variants_found = []
121
- variants_to_fix = []
122
-
123
- Spree::Variant.deleted.each do |variant|
124
- # check if this variant has any line items at all
125
- next if variant.line_items.none?
126
-
127
- variants_to_fix << variant
128
- dup_variant = Spree::Variant.find_by(sku: variant.sku)
129
- if dup_variant
130
- # this variant is OK
131
- else
132
- no_live_variants_found << variant
133
- end
134
- end
135
-
136
- if variants_to_fix.none?
137
- abort('ABORT: You have no deleted variants that are associated to line items. You do not need to run this raks task.')
138
- end
139
-
140
- if no_live_variants_found.any?
141
- puts "ABORT: Unfortunately, I found some deleted variants in your database that do not have matching non-deleted variants to replace them with. This script can only be used to cleanup deleted variants that have SKUs that match non-deleted variants. To continue, you must either (1) un-delete these variants (hint: mark them 'discontinued' instead) or (2) create new variants with a matching SKU for each variant in the list below."
142
- no_live_variants_found.each do |deleted_variant|
143
- puts "variant id #{deleted_variant.id} (sku is '#{deleted_variant.sku}') ... no match found"
144
- end
145
- abort
146
- end
147
-
148
- puts 'Ready to fix...'
149
- variants_to_fix.each do |variant|
150
- dup_variant = Spree::Variant.find_by(sku: variant.sku)
151
- puts "Changing all line items for #{variant.sku} variant id #{variant.id} (deleted) to variant id #{dup_variant.id} (not deleted) ..."
152
- Spree::LineItem.unscoped.where(variant_id: variant.id).update_all(variant_id: dup_variant.id)
153
- end
154
-
155
- puts 'DONE ! Your database should no longer have line items that are associated with deleted variants.'
156
- end
157
- end
158
-
159
- desc 'Migrates taxon icons to spree assets after upgrading to Spree 3.4: only needed if you used taxons icons.'
160
- task migrate_taxon_icons: :environment do |_t, _args|
161
- Spree::Taxon.where.not(icon_file_name: nil).find_each do |taxon|
162
- taxon.create_icon(attachment_file_name: taxon.icon_file_name,
163
- attachment_content_type: taxon.icon_content_type,
164
- attachment_file_size: taxon.icon_file_size,
165
- attachment_updated_at: taxon.icon_updated_at)
166
- end
167
- end
168
-
169
- desc 'Migrates taxon icons to taxon images after upgrading to Spree 3.7: only needed if you used taxons icons.'
170
- task migrate_taxon_icons_to_images: :environment do |_t, _args|
171
- Spree::Asset.where(type: 'Spree::TaxonIcon').update_all(type: 'Spree::TaxonImage')
172
- end
173
-
174
- desc 'Ensure all Order associated with Store after upgrading to Spree 3.7'
175
- task associate_orders_with_store: :environment do |_t, _args|
176
- Spree::Order.where(store_id: nil).update_all(store_id: Spree::Store.default.id)
177
- end
178
-
179
- desc 'Ensure all Order has currency present after upgrading to Spree 3.7'
180
- task ensure_order_currency_presence: :environment do |_t, _args|
181
- Spree::Order.where(currency: nil).find_in_batches do |orders|
182
- orders.each do |order|
183
- order.update!(currency: order.store.default_currency)
184
- end
185
- end
186
- end
187
-
188
4
  task migrate_admin_users_to_role_users: :environment do |_t, _args|
189
5
  default_store = Spree::Store.default
190
6
  Spree::RoleUser.where(resource: nil).each do |role_user|
@@ -218,89 +34,8 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]}
218
34
  puts "Migrated #{policy_slug} to store #{store.id}"
219
35
  end
220
36
  end
221
-
222
- Spree::PageLink.where(linkable_type: 'ActionText::RichText').each do |page_link|
223
- # Check if this page link is attached to ActionText content
224
- # Find the ActionText record
225
- action_text = ActionText::RichText.find_by(id: page_link.linkable_id)
226
- next unless action_text
227
-
228
- # Check if the ActionText belongs to a store policy
229
- if action_text.record_type == 'Spree::Store' && action_text.name.to_s.include?('policy')
230
- # Find the corresponding policy in the new policies system
231
- store = action_text.record
232
- policy_name = derive_policy_name.call(action_text.name)
233
-
234
- policy = store.policies.find_by(name: Spree.t(policy_name))
235
-
236
- if policy
237
- # Update the page link to point to the policy instead
238
- page_link.update!(
239
- linked_resource_type: 'Spree::Policy',
240
- linked_resource_id: policy.id
241
- )
242
-
243
- puts "Migrated #{policy_name} to store #{store.id}"
244
- end
245
- end
246
- end
247
37
  end
248
38
 
249
- desc 'Migrate product properties to metafields'
250
- task migrate_product_properties_to_metafields: :environment do |_t, _args|
251
- Spree::Property.find_each do |property|
252
- metafield_definition = Spree::MetafieldDefinition.find_or_initialize_by(
253
- namespace: 'properties',
254
- key: property.name,
255
- resource_type: 'Spree::Product'
256
- )
257
- metafield_definition.assign_attributes(
258
- metafield_type: property.kind_to_metafield_type,
259
- display_on: property.display_on
260
- )
261
- metafield_definition.save!
262
-
263
- property.product_properties.includes(:product).find_each do |product_property|
264
- product_property.product.set_metafield("properties.#{property.name}", product_property.value)
265
- puts "Migrated #{property.name} to product #{product_property.product.id}"
266
- end
267
- end
268
- end
269
-
270
- desc 'Migrate product details sections to PDP 2.0 with blocks and metafields'
271
- task migrate_product_details_pages: :environment do |_t, _args|
272
- Spree::PageSections::ProductDetails.find_each do |section|
273
- next if section.blocks.any?
274
-
275
- if defined?(SpreeMultiTenant)
276
- SpreeMultiTenant.with_tenant(section.tenant) do
277
- section.send(:create_blocks)
278
- end
279
- else
280
- section.send(:create_blocks)
281
- end
282
- end
283
-
284
- Spree::Pages::ProductDetails.find_each do |page|
285
- next if page.sections.exists?(type: 'Spree::PageSections::Breadcrumbs')
286
-
287
- block = proc do
288
- breadcrumbs = page.sections.create!(type: 'Spree::PageSections::Breadcrumbs')
289
- breadcrumbs.move_to_top
290
-
291
- page_details = page.sections.find_by(type: 'Spree::PageSections::ProductDetails')
292
- if page_details.present?
293
- page_details.update!(preferred_top_padding: 0, preferred_top_border_width: 0)
294
- end
295
- end
296
-
297
- if defined?(SpreeMultiTenant)
298
- SpreeMultiTenant.with_tenant(page.tenant, &block)
299
- else
300
- block.call
301
- end
302
- end
303
- end
304
39
  end
305
40
 
306
41
  namespace :core do