solidus_core 2.11.10 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -2
- data/app/assets/javascripts/spree.js.erb +0 -51
- data/app/controllers/spree/base_controller.rb +1 -1
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/helpers/spree/products_helper.rb +2 -2
- data/app/helpers/spree/store_helper.rb +0 -11
- data/app/mailers/spree/carton_mailer.rb +1 -5
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- data/app/models/concerns/spree/adjustment_source.rb +0 -15
- data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
- data/app/models/concerns/spree/default_price.rb +39 -10
- data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
- data/app/models/concerns/spree/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +10 -37
- data/app/models/concerns/spree/user_methods.rb +38 -13
- data/app/models/spree/ability.rb +0 -37
- data/app/models/spree/address/name.rb +2 -20
- data/app/models/spree/address.rb +8 -186
- data/app/models/spree/adjustment.rb +7 -33
- data/app/models/spree/base.rb +0 -53
- data/app/models/spree/calculator/flat_fee.rb +21 -0
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -7
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/country.rb +2 -7
- data/app/models/spree/credit_card.rb +1 -28
- data/app/models/spree/customer_return.rb +5 -7
- data/app/models/spree/image/active_storage_attachment.rb +2 -7
- data/app/models/spree/image/paperclip_attachment.rb +2 -2
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +6 -49
- data/app/models/spree/log_entry.rb +74 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +10 -1
- data/app/models/spree/order/number_generator.rb +7 -1
- data/app/models/spree/order.rb +82 -170
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_contents.rb +2 -1
- data/app/models/spree/order_inventory.rb +1 -1
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_promotion.rb +1 -1
- data/app/models/spree/order_shipping.rb +6 -9
- data/app/models/spree/order_taxation.rb +6 -4
- data/app/models/spree/order_updater.rb +17 -16
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment/processing.rb +58 -55
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
- data/app/models/spree/payment_method.rb +26 -110
- data/app/models/spree/price.rb +3 -3
- data/app/models/spree/product/scopes.rb +24 -33
- data/app/models/spree/product.rb +15 -42
- data/app/models/spree/product_property.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
- data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
- data/app/models/spree/promotion/rules/item_total.rb +50 -6
- data/app/models/spree/promotion/rules/product.rb +20 -8
- data/app/models/spree/promotion/rules/store.rb +4 -0
- data/app/models/spree/promotion/rules/taxon.rb +6 -15
- data/app/models/spree/promotion/rules/user.rb +4 -0
- data/app/models/spree/promotion.rb +39 -32
- data/app/models/spree/promotion_action.rb +6 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_code.rb +11 -7
- data/app/models/spree/promotion_handler/cart.rb +26 -6
- data/app/models/spree/promotion_rule.rb +5 -0
- data/app/models/spree/property.rb +1 -1
- data/app/models/spree/refund.rb +8 -52
- data/app/models/spree/reimbursement.rb +5 -43
- data/app/models/spree/reimbursement_performer.rb +2 -8
- data/app/models/spree/reimbursement_type/credit.rb +1 -4
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
- data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
- data/app/models/spree/return_authorization.rb +2 -5
- data/app/models/spree/return_item.rb +4 -24
- data/app/models/spree/shipment.rb +3 -56
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/shipping_rate_tax.rb +1 -1
- data/app/models/spree/state.rb +1 -5
- data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
- data/app/models/spree/stock/availability.rb +11 -3
- data/app/models/spree/stock/quantifier.rb +12 -8
- data/app/models/spree/stock/simple_coordinator.rb +8 -26
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +2 -8
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit.rb +14 -1
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/store_credit_prioritizer.rb +17 -0
- data/app/models/spree/tax/item_tax.rb +3 -2
- data/app/models/spree/tax/order_tax.rb +3 -1
- data/app/models/spree/tax/tax_helpers.rb +2 -2
- data/app/models/spree/tax/tax_location.rb +4 -7
- data/app/models/spree/tax_calculator/default.rb +31 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
- data/app/models/spree/tax_rate.rb +9 -27
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
- data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
- data/app/models/spree/taxon.rb +1 -12
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
- data/app/models/spree/variant/price_selector.rb +34 -4
- data/app/models/spree/variant.rb +52 -66
- data/app/models/spree/zone.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +4 -0
- data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
- data/config/i18n-tasks.yml +134 -0
- data/config/locales/en.yml +406 -263
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
- data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
- data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
- data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
- data/db/seeds.rb +4 -1
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
- data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
- data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
- data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
- data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
- data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
- data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
- data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
- data/lib/generators/solidus/install/install_generator.rb +247 -149
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
- data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
- data/lib/generators/solidus/update/update_generator.rb +112 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
- data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
- data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
- data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
- data/lib/spree/app_configuration.rb +134 -64
- data/lib/spree/bus.rb +20 -0
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +10 -15
- data/lib/spree/core/controller_helpers/current_host.rb +5 -3
- data/lib/spree/core/controller_helpers/order.rb +12 -32
- data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
- data/lib/spree/core/controller_helpers/pricing.rb +0 -8
- data/lib/spree/core/controller_helpers/search.rb +1 -1
- data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +54 -50
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +1 -41
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +18 -35
- data/lib/spree/core/state_machines/order.rb +2 -2
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/stock_configuration.rb +18 -0
- data/lib/spree/core/validators/email.rb +5 -3
- data/lib/spree/core/version.rb +5 -1
- data/lib/spree/core/versioned_value.rb +75 -0
- data/lib/spree/core.rb +40 -11
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/event/configuration.rb +0 -5
- data/lib/spree/event/subscriber.rb +0 -18
- data/lib/spree/event/subscriber_registry.rb +7 -7
- data/lib/spree/event.rb +1 -32
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/migrations.rb +13 -11
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permission_sets/default_customer.rb +8 -1
- data/lib/spree/permitted_attributes.rb +17 -59
- data/lib/spree/preferences/configuration.rb +84 -0
- data/lib/spree/preferences/preferable.rb +13 -0
- data/lib/spree/preferences/preferable_class_methods.rb +37 -4
- data/lib/spree/preferences/preference_differentiator.rb +29 -0
- data/lib/spree/preferences/static_model_preferences.rb +25 -10
- data/lib/spree/rails_compatibility.rb +106 -0
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/bus_helpers.rb +101 -0
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/common_rake.rb +71 -23
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/database.yml +42 -22
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +47 -34
- data/lib/spree/testing_support/factories/address_factory.rb +9 -6
- data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
- data/lib/spree/testing_support/factories/country_factory.rb +1 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +8 -5
- data/lib/spree/testing_support/factories/product_factory.rb +4 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/factories/state_factory.rb +8 -2
- data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
- data/lib/spree/testing_support/factories/user_factory.rb +6 -0
- data/lib/spree/testing_support/factory_bot.rb +2 -2
- data/lib/spree/testing_support/order_walkthrough.rb +6 -8
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/spree/testing_support/silence_deprecations.rb +9 -0
- data/lib/tasks/colorado_delivery_fee.rake +28 -0
- data/lib/tasks/payment_method.rake +29 -0
- data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
- data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
- data/solidus_core.gemspec +14 -7
- metadata +127 -78
- data/app/mailers/spree/test_mailer.rb +0 -13
- data/app/models/concerns/spree/user_payment_source.rb +0 -26
- data/app/models/spree/calculator/free_shipping.rb +0 -22
- data/app/models/spree/calculator/percent_per_item.rb +0 -51
- data/app/models/spree/calculator/price_sack.rb +0 -28
- data/app/models/spree/gateway/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- data/app/models/spree/gateway.rb +0 -14
- data/app/models/spree/order/checkout.rb +0 -244
- data/app/models/spree/order_capturing.rb +0 -50
- data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
- data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
- data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
- data/lib/generators/spree/install/install_generator.rb +0 -15
- data/lib/solidus/migrations/rename_gateways.rb +0 -41
- data/lib/spree/core/current_store.rb +0 -24
- data/lib/spree/paranoia_deprecations.rb +0 -41
- data/lib/spree/promo/environment.rb +0 -12
- data/lib/spree/testing_support/bar_ability.rb +0 -19
- data/lib/tasks/core.rake +0 -104
- data/lib/tasks/email.rake +0 -12
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
- data/lib/tasks/migrations/migrate_address_names.rake +0 -158
- data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
- data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
- data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
- data/lib/tasks/migrations/rename_gateways.rake +0 -23
- data/lib/tasks/order_capturing.rake +0 -27
- data/lib/tasks/upgrade.rake +0 -13
data/lib/tasks/core.rake
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_record'
|
4
|
-
|
5
|
-
def prompt_for_agree(prompt)
|
6
|
-
print prompt
|
7
|
-
["y", "yes"].include? STDIN.gets.strip.downcase
|
8
|
-
end
|
9
|
-
|
10
|
-
namespace :db do
|
11
|
-
desc 'Loads a specified fixture file:
|
12
|
-
use rake db:load_file[/absolute/path/to/sample/filename.rb]'
|
13
|
-
|
14
|
-
task :load_file, [:file, :dir] => :environment do |_t, args|
|
15
|
-
Spree::Deprecation.warn("load_file has been deprecated. Please load your own file.")
|
16
|
-
file = Pathname.new(args.file)
|
17
|
-
|
18
|
-
puts "loading ruby #{file}"
|
19
|
-
require file
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Loads fixtures from the the dir you specify using rake db:load_dir[loadfrom]"
|
23
|
-
task :load_dir, [:dir] => :environment do |_t, args|
|
24
|
-
Spree::Deprecation.warn("rake spree:load_dir has been deprecated and will be removed with Solidus 3.0. Please load your files directly.")
|
25
|
-
dir = args.dir
|
26
|
-
dir = File.join(Rails.root, "db", dir) if Pathname.new(dir).relative?
|
27
|
-
|
28
|
-
ruby_files = {}
|
29
|
-
Dir.glob(File.join(dir, '**/*.{rb}')).each do |fixture_file|
|
30
|
-
ruby_files[File.basename(fixture_file, '.*')] = fixture_file
|
31
|
-
end
|
32
|
-
ruby_files.sort.each do |fixture, ruby_file|
|
33
|
-
# If file is exists within application it takes precendence.
|
34
|
-
if File.exist?(File.join(Rails.root, "db/default/spree", "#{fixture}.rb"))
|
35
|
-
ruby_file = File.expand_path(File.join(Rails.root, "db/default/spree", "#{fixture}.rb"))
|
36
|
-
end
|
37
|
-
# an invoke will only execute the task once
|
38
|
-
Rake::Task["db:load_file"].execute( Rake::TaskArguments.new([:file], [ruby_file]) )
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
desc "Migrate schema to version 0 and back up again. WARNING: Destroys all data in tables!!"
|
43
|
-
task remigrate: :environment do
|
44
|
-
Spree::Deprecation.warn("remigrate has been deprecated. Please use db:reset or other db: commands instead.")
|
45
|
-
|
46
|
-
if ENV['SKIP_NAG'] || ENV['OVERWRITE'].to_s.casecmp('true') || prompt_for_agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")
|
47
|
-
|
48
|
-
# Drop all tables
|
49
|
-
ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.drop_table t }
|
50
|
-
|
51
|
-
# Migrate upward
|
52
|
-
Rake::Task["db:migrate"].invoke
|
53
|
-
|
54
|
-
# Dump the schema
|
55
|
-
Rake::Task["db:schema:dump"].invoke
|
56
|
-
else
|
57
|
-
puts "Task cancelled."
|
58
|
-
exit
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
desc "Bootstrap is: migrating, loading defaults, sample data and seeding (for all extensions) and load_products tasks"
|
63
|
-
task :bootstrap do
|
64
|
-
Spree::Deprecation.warn("rake bootstrap has been deprecated, please run db:setup instead.")
|
65
|
-
|
66
|
-
# remigrate unless production mode (as saftey check)
|
67
|
-
if %w[demo development test].include? Rails.env
|
68
|
-
if ENV['AUTO_ACCEPT'] || prompt_for_agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")
|
69
|
-
ENV['SKIP_NAG'] = 'yes'
|
70
|
-
Rake::Task["db:create"].invoke
|
71
|
-
Rake::Task["db:remigrate"].invoke
|
72
|
-
else
|
73
|
-
puts "Task cancelled, exiting."
|
74
|
-
exit
|
75
|
-
end
|
76
|
-
else
|
77
|
-
puts "NOTE: Bootstrap in production mode will not drop database before migration"
|
78
|
-
Rake::Task["db:migrate"].invoke
|
79
|
-
end
|
80
|
-
|
81
|
-
ActiveRecord::Base.send(:subclasses).each(&:reset_column_information)
|
82
|
-
|
83
|
-
load_defaults = Spree::Country.count == 0
|
84
|
-
load_defaults ||= prompt_for_agree('Countries present, load sample data anyways? [y/n]: ')
|
85
|
-
if load_defaults
|
86
|
-
Rake::Task["db:seed"].invoke
|
87
|
-
end
|
88
|
-
|
89
|
-
if Rails.env.production? && Spree::Product.count > 0
|
90
|
-
load_sample = prompt_for_agree("WARNING: In Production and products exist in database, load sample data anyways? [y/n]:" )
|
91
|
-
else
|
92
|
-
load_sample = true if ENV['AUTO_ACCEPT']
|
93
|
-
load_sample ||= prompt_for_agree('Load Sample Data? [y/n]: ')
|
94
|
-
end
|
95
|
-
|
96
|
-
if load_sample
|
97
|
-
# Reload models' attributes in case they were loaded in old migrations with wrong attributes
|
98
|
-
ActiveRecord::Base.descendants.each(&:reset_column_information)
|
99
|
-
Rake::Task["spree_sample:load"].invoke
|
100
|
-
end
|
101
|
-
|
102
|
-
puts "Bootstrap Complete.\n\n"
|
103
|
-
end
|
104
|
-
end
|
data/lib/tasks/email.rake
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :email do
|
4
|
-
desc 'Sends test email to specified address - Example: EMAIL=solidus@example.com bundle exec rake email:test'
|
5
|
-
task test: :environment do
|
6
|
-
Spree::Deprecation.warn("rake email:test has been deprecated and will be removed with Solidus 3.0")
|
7
|
-
|
8
|
-
raise ArgumentError, "Must pass EMAIL environment variable. Example: EMAIL=solidus@example.com bundle exec rake email:test" if ENV['EMAIL'].blank?
|
9
|
-
|
10
|
-
Spree::TestMailer.test_email(ENV['EMAIL']).deliver!
|
11
|
-
end
|
12
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace 'spree:migrations:copy_order_bill_address_to_credit_card' do
|
4
|
-
# This copies the billing address from the order associated with a
|
5
|
-
# credit card's most recent payment to the credit card.
|
6
|
-
|
7
|
-
# Used in the migration CopyOrderBillAddressToCreditCard and made available as a
|
8
|
-
# rake task to allow running it a second time after deploying the new code, in
|
9
|
-
# case some order->credit card data was missed between the time that the
|
10
|
-
# migration was run and the application servers were restarted with the new
|
11
|
-
# code.
|
12
|
-
|
13
|
-
# This task should be safe to run multiple times.
|
14
|
-
|
15
|
-
task up: :environment do
|
16
|
-
Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:up has been deprecated and will be removed with Solidus 3.0.")
|
17
|
-
|
18
|
-
if Spree::CreditCard.connection.adapter_name =~ /postgres/i
|
19
|
-
postgres_copy
|
20
|
-
else
|
21
|
-
ruby_copy
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
task down: :environment do
|
26
|
-
Spree::Deprecation.warn("rake spree:migrations:copy_order_bill_address_to_credit_card:down has been deprecated and will be removed with Solidus 3.0.")
|
27
|
-
|
28
|
-
Spree::CreditCard.update_all(address_id: nil)
|
29
|
-
end
|
30
|
-
|
31
|
-
def ruby_copy
|
32
|
-
scope = Spree::CreditCard.where(address_id: nil).includes(payments: :order)
|
33
|
-
|
34
|
-
scope.find_each(batch_size: 500) do |cc|
|
35
|
-
# remove payments that lack a bill address
|
36
|
-
payments = cc.payments.select { |p| p.order.bill_address_id }
|
37
|
-
|
38
|
-
payment = payments.sort_by do |p|
|
39
|
-
[
|
40
|
-
%w(failed invalid).include?(p.state) ? 0 : 1, # prioritize valid payments
|
41
|
-
p.created_at, # prioritize more recent payments
|
42
|
-
]
|
43
|
-
end.last
|
44
|
-
|
45
|
-
next if payment.nil?
|
46
|
-
|
47
|
-
cc.update_column(:address_id, payment.order.bill_address_id)
|
48
|
-
puts "Successfully associated billing address (#{payment.order.bill_address_id}) with credit card (#{cc.id})"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# This was 20x faster for us but the syntax is postgres-specific. I'm sure
|
53
|
-
# there are equivalent versions for other DBs if someone wants to write them.
|
54
|
-
# I took a quick stab at crafting a cross-db compatible version but it was
|
55
|
-
# slow.
|
56
|
-
def postgres_copy
|
57
|
-
batch_size = 10_000
|
58
|
-
|
59
|
-
current_start_id = 1
|
60
|
-
|
61
|
-
while current_start_id <= last_credit_card_id
|
62
|
-
current_end_id = current_start_id + batch_size
|
63
|
-
puts "updating #{current_start_id} to #{current_end_id}"
|
64
|
-
|
65
|
-
# first try to find a valid payment for each credit card
|
66
|
-
Spree::CreditCard.connection.execute(
|
67
|
-
postgres_sql(
|
68
|
-
start_id: current_start_id,
|
69
|
-
end_id: current_end_id,
|
70
|
-
payment_state: "not in ('failed', 'invalid')"
|
71
|
-
)
|
72
|
-
)
|
73
|
-
|
74
|
-
# fall back to using invalid payments for each credit card
|
75
|
-
Spree::CreditCard.connection.execute(
|
76
|
-
postgres_sql(
|
77
|
-
start_id: current_start_id,
|
78
|
-
end_id: current_end_id,
|
79
|
-
payment_state: "in ('failed', 'invalid')"
|
80
|
-
)
|
81
|
-
)
|
82
|
-
|
83
|
-
current_start_id += batch_size
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def postgres_sql(start_id:, end_id:, payment_state:)
|
88
|
-
<<-SQL
|
89
|
-
update spree_credit_cards c
|
90
|
-
set address_id = o.bill_address_id
|
91
|
-
from spree_payments p
|
92
|
-
inner join spree_orders o
|
93
|
-
on o.id = p.order_id
|
94
|
-
and o.bill_address_id is not null
|
95
|
-
left join (
|
96
|
-
select p2.*
|
97
|
-
from spree_payments p2
|
98
|
-
inner join spree_orders o2
|
99
|
-
on o2.id = p2.order_id
|
100
|
-
and o2.bill_address_id is not null
|
101
|
-
) more_recent_payment
|
102
|
-
on more_recent_payment.source_id = p.source_id
|
103
|
-
and more_recent_payment.source_type = 'Spree::CreditCard'
|
104
|
-
and more_recent_payment.created_at > p.created_at
|
105
|
-
and more_recent_payment.state #{payment_state}
|
106
|
-
where c.address_id is null
|
107
|
-
and p.source_id = c.id
|
108
|
-
and p.source_type = 'Spree::CreditCard'
|
109
|
-
and p.state #{payment_state}
|
110
|
-
and more_recent_payment.id is null
|
111
|
-
and o.bill_address_id is not null
|
112
|
-
and c.id between #{start_id} and #{end_id}
|
113
|
-
SQL
|
114
|
-
end
|
115
|
-
|
116
|
-
def last_credit_card_id
|
117
|
-
Spree::CreditCard.last.try!(:id) || 0
|
118
|
-
end
|
119
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'thor'
|
4
|
-
|
5
|
-
namespace :solidus do
|
6
|
-
namespace :migrations do
|
7
|
-
namespace :migrate_address_names do
|
8
|
-
desc 'Backfills Spree::Address name attribute using firstname and lastname
|
9
|
-
concatenation in order to retain historical data when upgrading to new
|
10
|
-
address name format'
|
11
|
-
task up: :environment do
|
12
|
-
puts "Combining addresses' firstname and lastname into name ... "
|
13
|
-
class Spree::AddressForMigration < ApplicationRecord
|
14
|
-
self.table_name = 'spree_addresses'
|
15
|
-
end
|
16
|
-
|
17
|
-
records = Spree::AddressForMigration.unscoped.where(name: [nil, ''])
|
18
|
-
count = records.count
|
19
|
-
connection = ActiveRecord::Base.connection
|
20
|
-
adapter_name = connection.adapter_name.downcase
|
21
|
-
shell = Thor::Shell::Basic.new
|
22
|
-
puts " Your DB contains #{count} addresses that may be affected by this task."
|
23
|
-
# `trim` is not needed for pg or mysql when using `concat_ws`:
|
24
|
-
# select concat_ws('joinstring', 'foo', null);
|
25
|
-
# concat_ws
|
26
|
-
# -----------
|
27
|
-
# foo
|
28
|
-
# (1 row)
|
29
|
-
# select concat_ws('joinstring', 'foo', null) = trim(concat_ws('joinstring', 'foo', null));
|
30
|
-
# ?column?
|
31
|
-
# ----------
|
32
|
-
# t
|
33
|
-
# (1 row)
|
34
|
-
unless count.zero?
|
35
|
-
concat_statement = begin
|
36
|
-
case adapter_name
|
37
|
-
when /sqlite/
|
38
|
-
"name = TRIM(COALESCE(firstname, '') || ' ' || COALESCE(lastname, ''))"
|
39
|
-
when /postgres/, /mysql2/
|
40
|
-
"name = CONCAT_WS(' ', firstname, lastname)"
|
41
|
-
else
|
42
|
-
abort " No migration path available for adapter #{adapter_name}. Please write your own."
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# The batch size should be limited to avoid locking the table records for too long. These are
|
47
|
-
# the numbers I got with 1_000_000 records in `spree_addresses`, all with different name and
|
48
|
-
# surname, with postgresql:
|
49
|
-
#
|
50
|
-
# Updating 1000000 records in one shot
|
51
|
-
# batch took 178 seconds
|
52
|
-
#
|
53
|
-
# Updating 1000000 addresses in batches of 200000
|
54
|
-
# batch took 36 seconds
|
55
|
-
# batch took 31 seconds
|
56
|
-
# batch took 31 seconds
|
57
|
-
# batch took 31 seconds
|
58
|
-
# batch took 30 seconds
|
59
|
-
#
|
60
|
-
# Updating 1000000 addresses in batches of 150000
|
61
|
-
# batch took 29 seconds
|
62
|
-
# batch took 27 seconds
|
63
|
-
# batch took 27 seconds
|
64
|
-
# batch took 27 seconds
|
65
|
-
# batch took 26 seconds
|
66
|
-
# batch took 26 seconds
|
67
|
-
# batch took 19 seconds
|
68
|
-
#
|
69
|
-
# Updating 1000000 addresses in batches of 100000
|
70
|
-
# batch took 17 seconds
|
71
|
-
# batch took 15 seconds
|
72
|
-
# batch took 17 seconds
|
73
|
-
# batch took 17 seconds
|
74
|
-
# batch took 17 seconds
|
75
|
-
# batch took 17 seconds
|
76
|
-
# batch took 17 seconds
|
77
|
-
# batch took 17 seconds
|
78
|
-
# batch took 17 seconds
|
79
|
-
# batch took 17 seconds
|
80
|
-
#
|
81
|
-
# This is with mysql:
|
82
|
-
# Updating 1000000 records in one shot
|
83
|
-
# batch updated in 153 seconds
|
84
|
-
#
|
85
|
-
# Updating 1000000 records in batches of 200000, this may take a while...
|
86
|
-
# batch took 41 seconds
|
87
|
-
# batch took 37 seconds
|
88
|
-
# batch took 35 seconds
|
89
|
-
# batch took 28 seconds
|
90
|
-
# batch took 27 seconds
|
91
|
-
#
|
92
|
-
# Updating 1000000 records in batches of 150000, this may take a while...
|
93
|
-
# batch took 30 seconds
|
94
|
-
# batch took 29 seconds
|
95
|
-
# batch took 18 seconds
|
96
|
-
# batch took 18 seconds
|
97
|
-
# batch took 17 seconds
|
98
|
-
# batch took 29 seconds
|
99
|
-
# batch took 12 seconds
|
100
|
-
#
|
101
|
-
# Updating 1000000 records in batches of 100000, this may take a while...
|
102
|
-
# batch took 10 seconds
|
103
|
-
# batch took 11 seconds
|
104
|
-
# batch took 12 seconds
|
105
|
-
# batch took 13 seconds
|
106
|
-
# batch took 12 seconds
|
107
|
-
# batch took 12 seconds
|
108
|
-
# batch took 14 seconds
|
109
|
-
# batch took 19 seconds
|
110
|
-
# batch took 20 seconds
|
111
|
-
# batch took 21 seconds
|
112
|
-
#
|
113
|
-
# Please note that the migration will be much faster when there's no index
|
114
|
-
# on the `name` column. For example, with mysql each batch takes exactly
|
115
|
-
# the same time:
|
116
|
-
#
|
117
|
-
# Updating 1000000 records in batches of 200000, this may take a while...
|
118
|
-
# batch took 17 seconds
|
119
|
-
# batch took 17 seconds
|
120
|
-
# batch took 17 seconds
|
121
|
-
# batch took 16 seconds
|
122
|
-
# batch took 17 seconds
|
123
|
-
#
|
124
|
-
# So, if special need arise, one can drop the index added with migration
|
125
|
-
# 20210122110141_add_name_to_spree_addresses.rb and add the index later,
|
126
|
-
# in non blocking ways. For postgresql:
|
127
|
-
# add_index(:spree_addresses, :name, algorithm: :concurrently)
|
128
|
-
#
|
129
|
-
# For mysql 5.6:
|
130
|
-
# sql = "ALTER TABLE spree_addresses ADD INDEX index_spree_addresses_on_name (name), ALGORITHM=INPLACE, LOCK=NONE;"
|
131
|
-
# ActiveRecord::Base.connection.execute sql
|
132
|
-
#
|
133
|
-
puts ' Data migration will happen in batches. The default value is 100_000, which should take less than 20 seconds on mysql or postgresql.'
|
134
|
-
size = shell.ask(' Please enter a different batch size, or press return to confirm the default: ')
|
135
|
-
size = (size.presence || 100_000).to_i
|
136
|
-
|
137
|
-
abort " Invalid batch size number #{size}, please run the task again." unless size.positive?
|
138
|
-
|
139
|
-
batches_total = (count / size).ceil
|
140
|
-
puts " We're going to migrate #{count} records in #{batches_total} batches of #{size}."
|
141
|
-
|
142
|
-
answer = shell.ask(' Do you want to proceed?', limited_to: ['Y', 'N'], case_insensitive: true)
|
143
|
-
if answer == 'Y'
|
144
|
-
puts " Updating #{count} records in batches of #{size}, this may take a while..."
|
145
|
-
|
146
|
-
records.in_batches(of: size).each.with_index(1) do |batch, index|
|
147
|
-
now = Time.zone.now
|
148
|
-
batch.update_all(concat_statement)
|
149
|
-
puts " Batch #{index}/#{batches_total} done in #{(Time.zone.now - now).to_i} seconds."
|
150
|
-
end
|
151
|
-
else
|
152
|
-
puts " Database not migrated. Please, make sure to fill address's name field on your own."
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :solidus do
|
4
|
-
namespace :migrations do
|
5
|
-
namespace :migrate_default_billing_addresses_to_address_book do
|
6
|
-
task up: :environment do
|
7
|
-
print "Migrating default billing addresses to address book ... "
|
8
|
-
if Spree::UserAddress.where(default_billing: true).any?
|
9
|
-
Spree.user_class.joins(:bill_address).update_all(bill_address_id: nil) # rubocop:disable Rails/SkipsModelValidations
|
10
|
-
end
|
11
|
-
Spree::UserAddress.joins(
|
12
|
-
<<~SQL
|
13
|
-
JOIN spree_users ON spree_user_addresses.user_id = spree_users.id
|
14
|
-
AND spree_user_addresses.address_id = spree_users.bill_address_id
|
15
|
-
SQL
|
16
|
-
).update_all(default_billing: true)
|
17
|
-
puts "Success"
|
18
|
-
end
|
19
|
-
|
20
|
-
task down: :environment do
|
21
|
-
Spree::UserAddress.update_all(default_billing: false) # rubocop:disable Rails/SkipsModelValidations
|
22
|
-
puts "Rolled back default billing address migration to address book"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :solidus do
|
4
|
-
namespace :migrations do
|
5
|
-
namespace :migrate_shipping_rate_taxes do
|
6
|
-
task up: :environment do
|
7
|
-
Spree::Deprecation.warn("rake spree:migrations:migrate_shipping_rate_taxes:up has been deprecated and will be removed with Solidus 3.0.")
|
8
|
-
|
9
|
-
print "Adding persisted tax notes to historic shipping rates ... "
|
10
|
-
Spree::ShippingRate.where.not(tax_rate_id: nil).find_each do |shipping_rate|
|
11
|
-
tax_rate = Spree::TaxRate.unscoped.find(shipping_rate.tax_rate_id)
|
12
|
-
shipping_rate.taxes.find_or_create_by!(
|
13
|
-
tax_rate: tax_rate,
|
14
|
-
amount: tax_rate.compute_amount(shipping_rate)
|
15
|
-
)
|
16
|
-
end
|
17
|
-
Spree::ShippingRate.where.not(tax_rate_id: nil).update_all(tax_rate_id: nil)
|
18
|
-
puts "Success."
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace 'spree:migrations:migrate_user_addresses' do
|
4
|
-
# This creates an entry in the user_addresses table for a user's currently
|
5
|
-
# associated shipping and billing addresses.
|
6
|
-
|
7
|
-
# This task should not need to be run more than once. But the de-dup behavior in
|
8
|
-
# UserAddressBook should make it safe.
|
9
|
-
# When the code (in the same PR) is deployed, each new order's addresses will be added
|
10
|
-
# to the user's address book. This will catch up all the historical data.
|
11
|
-
|
12
|
-
task up: :environment do
|
13
|
-
Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:up has been deprecated and will be removed with Solidus 3.0.")
|
14
|
-
|
15
|
-
Spree.user_class.find_each(batch_size: 500) do |user|
|
16
|
-
ship_address = Spree::Address.find_by(id: user.ship_address_id)
|
17
|
-
bill_address = Spree::Address.find_by(id: user.bill_address_id)
|
18
|
-
|
19
|
-
current_addresses = [bill_address, ship_address].compact.uniq
|
20
|
-
|
21
|
-
current_addresses.each do |address|
|
22
|
-
# since ship_address is last, it will override bill_address as default when both are present
|
23
|
-
user.save_in_address_book(address.attributes, true)
|
24
|
-
end
|
25
|
-
|
26
|
-
puts "Migrated addresses for user ##{user.id}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
task down: :environment do
|
31
|
-
Spree::Deprecation.warn("rake spree:migrations:migrate_user_addresses:down has been deprecated and will be removed with Solidus 3.0.")
|
32
|
-
Spree::UserAddress.delete_all
|
33
|
-
end
|
34
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'solidus/migrations/rename_gateways'
|
4
|
-
|
5
|
-
namespace 'solidus:migrations:rename_gateways' do
|
6
|
-
task up: :environment do
|
7
|
-
Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:up has been deprecated and will be removed with Solidus 3.0.")
|
8
|
-
count = Solidus::Migrations::RenameGateways.new.up
|
9
|
-
|
10
|
-
unless ENV['VERBOSE'] == 'false' || !verbose
|
11
|
-
puts "Renamed #{count} gateways into payment methods."
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
task down: :environment do
|
16
|
-
Spree::Deprecation.warn("rake solidus:migrations:rename_gateways:down has been deprecated and will be removed with Solidus 3.0.")
|
17
|
-
count = Solidus::Migrations::RenameGateways.new.down
|
18
|
-
|
19
|
-
unless ENV['VERBOSE'] == 'false' || !verbose
|
20
|
-
puts "Renamed #{count} payment methods into gateways."
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :order_capturing do
|
4
|
-
desc "Looks for orders with inventory that is fully shipped/short-shipped, and captures money for it"
|
5
|
-
task capture_payments: :environment do
|
6
|
-
Spree::Deprecation.warn("rake order_capturing:capture_payments has been deprecated and will be removed with Solidus 3.0.")
|
7
|
-
|
8
|
-
failures = []
|
9
|
-
orders = Spree::Order.complete.where(payment_state: 'balance_due').where('completed_at > ?', Spree::Config[:order_capturing_time_window].days.ago)
|
10
|
-
|
11
|
-
orders.find_each do |order|
|
12
|
-
if order.inventory_units.all? { |iu| iu.canceled? || iu.shipped? }
|
13
|
-
if Spree::OrderCapturing.failure_handler
|
14
|
-
begin
|
15
|
-
Spree::OrderCapturing.new(order).capture_payments
|
16
|
-
rescue StandardError => e
|
17
|
-
failures << { message: "Order #{order.number} unable to capture. #{e.class}: #{e.message}" }
|
18
|
-
end
|
19
|
-
else
|
20
|
-
Spree::OrderCapturing.new(order).capture_payments
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
Spree::OrderCapturing.failure_handler.call(failures) if failures.any?
|
26
|
-
end
|
27
|
-
end
|
data/lib/tasks/upgrade.rake
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :solidus do
|
4
|
-
namespace :upgrade do
|
5
|
-
desc "Upgrade Solidus to version 2.11"
|
6
|
-
task two_point_eleven: [
|
7
|
-
'solidus:migrations:migrate_default_billing_addresses_to_address_book:up',
|
8
|
-
'solidus:migrations:migrate_address_names:up'
|
9
|
-
] do
|
10
|
-
puts "Your Solidus install is ready for Solidus 2.11"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|