solidus_core 2.11.6 → 3.0.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.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spree.js.erb +0 -51
- 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.rb +2 -0
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +11 -11
- 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/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +0 -37
- data/app/models/concerns/spree/user_methods.rb +2 -11
- data/app/models/spree/ability.rb +0 -37
- data/app/models/spree/address.rb +8 -186
- data/app/models/spree/address/name.rb +2 -20
- data/app/models/spree/adjustment.rb +0 -28
- data/app/models/spree/base.rb +0 -35
- data/app/models/spree/calculator.rb +4 -7
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/country.rb +1 -6
- data/app/models/spree/credit_card.rb +0 -27
- data/app/models/spree/customer_return.rb +1 -4
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/image/active_storage_attachment.rb +10 -2
- data/app/models/spree/image/paperclip_attachment.rb +1 -1
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +2 -45
- data/app/models/spree/order.rb +3 -136
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_updater.rb +2 -11
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method.rb +5 -103
- data/app/models/spree/payment_method/bogus_credit_card.rb +13 -9
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +4 -4
- data/app/models/spree/product.rb +0 -39
- data/app/models/spree/product/scopes.rb +0 -27
- data/app/models/spree/promotion.rb +2 -6
- data/app/models/spree/promotion/actions/create_adjustment.rb +0 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/rules/taxon.rb +2 -15
- data/app/models/spree/promotion_action.rb +5 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_rule.rb +4 -0
- data/app/models/spree/refund.rb +0 -50
- data/app/models/spree/reimbursement.rb +3 -41
- 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 +1 -4
- data/app/models/spree/return_item.rb +1 -19
- data/app/models/spree/shipment.rb +1 -54
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/state.rb +0 -4
- data/app/models/spree/stock/simple_coordinator.rb +0 -14
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +1 -7
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/tax_calculator/shipping_rate.rb +1 -12
- data/app/models/spree/tax_rate.rb +0 -27
- data/app/models/spree/taxon.rb +0 -11
- data/app/models/spree/taxon/active_storage_attachment.rb +0 -5
- data/app/models/spree/taxon/paperclip_attachment.rb +0 -5
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/variant.rb +1 -45
- data/config/locales/en.yml +0 -8
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/lib/generators/solidus/install/install_generator.rb +13 -2
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -39
- data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
- 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 +14 -65
- data/lib/spree/core.rb +9 -8
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -14
- data/lib/spree/core/controller_helpers/order.rb +2 -22
- 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/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +0 -35
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +0 -40
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +0 -26
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/event.rb +0 -31
- data/lib/spree/event/configuration.rb +0 -5
- data/lib/spree/event/subscriber.rb +0 -18
- data/lib/spree/event/subscriber_registry.rb +3 -1
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permitted_attributes.rb +2 -53
- data/lib/spree/preferences/persistable.rb +23 -0
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app.rb +6 -14
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/factories/order_factory.rb +0 -1
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/fixtures/file.txt +1 -0
- data/lib/spree/testing_support/order_walkthrough.rb +0 -3
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/tasks/upgrade.rake +7 -5
- data/solidus_core.gemspec +2 -5
- metadata +9 -48
- 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.rb +0 -14
- data/app/models/spree/gateway/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- 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/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 -38
- 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
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Spree::OrderCapturing
|
4
|
-
# Allows for prioritizing payment methods in the order to be captured
|
5
|
-
class_attribute :sorted_payment_method_classes
|
6
|
-
self.sorted_payment_method_classes = []
|
7
|
-
|
8
|
-
# Allows your store to void unused payments and release auths
|
9
|
-
class_attribute :void_unused_payments
|
10
|
-
self.void_unused_payments = false
|
11
|
-
|
12
|
-
class_attribute :failure_handler
|
13
|
-
self.failure_handler = ->(failures) { raise Spree::OrderCapturingFailures.new(failures.to_json) }
|
14
|
-
|
15
|
-
def initialize(order, sorted_payment_method_classes = nil)
|
16
|
-
Spree::Deprecation.warn "Spree::OrderCapturing is deprecated and will be removed without replacement. " \
|
17
|
-
"Please implement your own automated capturing logic in your store."
|
18
|
-
@order = order
|
19
|
-
@sorted_payment_method_classes = sorted_payment_method_classes || Spree::OrderCapturing.sorted_payment_method_classes
|
20
|
-
end
|
21
|
-
|
22
|
-
def capture_payments
|
23
|
-
return if @order.paid?
|
24
|
-
|
25
|
-
Spree::OrderMutex.with_lock!(@order) do
|
26
|
-
uncaptured_amount = @order.display_total.cents
|
27
|
-
|
28
|
-
sorted_payments(@order).each do |payment|
|
29
|
-
amount = [uncaptured_amount, payment.money.cents].min
|
30
|
-
|
31
|
-
if amount > 0
|
32
|
-
payment.capture!(amount)
|
33
|
-
uncaptured_amount -= amount
|
34
|
-
elsif Spree::OrderCapturing.void_unused_payments
|
35
|
-
payment.void_transaction!
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def sorted_payments(order)
|
44
|
-
order.payments.pending.sort_by do |payment|
|
45
|
-
[@sorted_payment_method_classes.index(payment.payment_method.class), payment.id]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class Spree::OrderCapturingFailures < StandardError; end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'generators/solidus/install/install_generator'
|
4
|
-
|
5
|
-
module Spree
|
6
|
-
# @private
|
7
|
-
class InstallGenerator < Solidus::InstallGenerator
|
8
|
-
def print_deprecation_warning
|
9
|
-
puts " "
|
10
|
-
puts "*" * 50
|
11
|
-
puts "spree:install generator is deprecated, please use solidus:install."
|
12
|
-
puts " "
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Solidus
|
4
|
-
module Migrations
|
5
|
-
class RenameGateways
|
6
|
-
DEFAULT_MAPPING = {
|
7
|
-
'Spree::Gateway' => 'Spree::PaymentMethod::CreditCard',
|
8
|
-
'Spree::Gateway::Bogus' => 'Spree::PaymentMethod::BogusCreditCard',
|
9
|
-
'Spree::Gateway::BogusSimple' => 'Spree::PaymentMethod::SimpleBogusCreditCard'
|
10
|
-
}
|
11
|
-
|
12
|
-
attr_reader :gateway_mapping
|
13
|
-
|
14
|
-
def initialize(gateway_mapping = DEFAULT_MAPPING)
|
15
|
-
Spree::Deprecation.warn 'Solidus::Migrations::RenameGateways is deprecated and will be removed with Solidus 3.0.'
|
16
|
-
|
17
|
-
@gateway_mapping = gateway_mapping
|
18
|
-
end
|
19
|
-
|
20
|
-
def up
|
21
|
-
gateway_mapping.inject(0) do |count, mapping|
|
22
|
-
count + update(from: mapping[0], to: mapping[1])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def down
|
27
|
-
gateway_mapping.inject(0) do |count, mapping|
|
28
|
-
count + update(from: mapping[1], to: mapping[0])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def update(from:, to:)
|
35
|
-
ActiveRecord::Base.connection.update <<-SQL.strip_heredoc
|
36
|
-
UPDATE spree_payment_methods SET type = '#{to}' WHERE type = '#{from}';
|
37
|
-
SQL
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Default class for deciding what the current store is, given an HTTP request
|
4
|
-
# This is an extension point used in Spree::Core::ControllerHelpers::Store
|
5
|
-
# Custom versions of this class must respond to a store instance method
|
6
|
-
module Spree
|
7
|
-
module Core
|
8
|
-
class CurrentStore
|
9
|
-
def initialize(request)
|
10
|
-
@request = request
|
11
|
-
@current_store_selector = Spree::Config.current_store_selector_class.new(request)
|
12
|
-
Spree::Deprecation.warn "Using Spree::Core::CurrentStore is deprecated. Use Spree::Config.current_store_selector_class instead", caller
|
13
|
-
end
|
14
|
-
|
15
|
-
# Delegate store selection to Spree::Config.current_store_selector_class
|
16
|
-
# Using this class is deprecated.
|
17
|
-
#
|
18
|
-
# @return [Spree::Store]
|
19
|
-
def store
|
20
|
-
@current_store_selector.store
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
module ParanoiaDeprecations
|
5
|
-
module InstanceMethods
|
6
|
-
def paranoia_destroy
|
7
|
-
Spree::Deprecation.warn <<~WARN, caller
|
8
|
-
Calling #destroy (or #paranoia_destroy) on a #{self.class} currently performs a soft-destroy using the paranoia gem.
|
9
|
-
In Solidus 3.0, paranoia will be removed, and this will perform a HARD destroy instead. To continue soft-deleting, use #discard instead.
|
10
|
-
WARN
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
|
-
def paranoia_delete
|
15
|
-
Spree::Deprecation.warn <<~WARN, caller
|
16
|
-
Calling #delete (or #paranoia_delete) on a #{self.class} currently performs a soft-destroy using the paranoia gem.
|
17
|
-
In Solidus 3.0, paranoia will be removed, and this will perform a HARD destroy instead. To continue soft-deleting, use #discard instead.
|
18
|
-
WARN
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module ClassMethods
|
24
|
-
def with_deleted
|
25
|
-
Spree::Deprecation.warn <<~WARN, caller
|
26
|
-
#{self}.with_deleted has been deprecated. Use #{self}.with_discarded instead.
|
27
|
-
In Solidus 3.0, paranoia will be removed, and this method will be replaced by #{self}.with_discarded.
|
28
|
-
WARN
|
29
|
-
super
|
30
|
-
end
|
31
|
-
|
32
|
-
def only_deleted
|
33
|
-
Spree::Deprecation.warn <<~WARN, caller
|
34
|
-
#{self}.only_deleted has been deprecated. Use #{self}.discarded instead.
|
35
|
-
In Solidus 3.0, paranoia will be removed, and this method will be replaced by #{self}.discarded.
|
36
|
-
WARN
|
37
|
-
super
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Spree::Deprecation.warn "BarAbility is deprecated. Use stub_authorization! instead"
|
4
|
-
|
5
|
-
# Fake ability for testing administration
|
6
|
-
# @private
|
7
|
-
class BarAbility
|
8
|
-
include CanCan::Ability
|
9
|
-
|
10
|
-
def initialize(user)
|
11
|
-
user ||= Spree::User.new
|
12
|
-
if user.has_spree_role? 'bar'
|
13
|
-
# allow dispatch to :admin, :index, and :show on Spree::Order
|
14
|
-
can [:admin, :index, :show], Spree::Order
|
15
|
-
# allow dispatch to :index, :show, :create and :update shipments on the admin
|
16
|
-
can [:admin, :manage], Spree::Shipment
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
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
|