solidus_core 2.2.2 → 2.3.0.beta1
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.
- checksums.yaml +4 -4
- data/README.md +4 -7
- data/app/assets/javascripts/spree.js.erb +2 -2
- data/app/helpers/spree/base_helper.rb +3 -4
- data/app/models/spree/address.rb +1 -1
- data/app/models/spree/adjustment.rb +3 -1
- data/app/models/spree/app_configuration.rb +43 -0
- data/app/models/spree/billing_integration.rb +2 -2
- data/app/models/spree/calculator/default_tax.rb +3 -1
- data/app/models/spree/calculator/distributed_amount.rb +24 -0
- data/app/models/spree/calculator/free_shipping.rb +0 -1
- data/app/models/spree/calculator/tiered_flat_rate.rb +17 -3
- data/app/models/spree/calculator/tiered_percent.rb +18 -3
- data/app/models/spree/distributed_amounts_handler.rb +43 -0
- data/app/models/spree/gateway/bogus.rb +7 -83
- data/app/models/spree/gateway/bogus_simple.rb +7 -20
- data/app/models/spree/gateway.rb +8 -58
- data/app/models/spree/image.rb +1 -1
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/order/checkout.rb +1 -4
- data/app/models/spree/order/number_generator.rb +43 -0
- data/app/models/spree/order.rb +33 -38
- data/app/models/spree/order_contents.rb +1 -1
- data/app/models/spree/order_taxation.rb +79 -0
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +55 -33
- data/app/models/spree/payment.rb +0 -1
- data/app/models/spree/payment_method/bogus_credit_card.rb +87 -0
- data/app/models/spree/payment_method/check.rb +14 -6
- data/app/models/spree/payment_method/credit_card.rb +41 -0
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +24 -0
- data/app/models/spree/payment_method/store_credit.rb +5 -13
- data/app/models/spree/payment_method.rb +126 -40
- data/app/models/spree/preferences/preferable.rb +5 -1
- data/app/models/spree/preferences/store.rb +2 -2
- data/app/models/spree/product/scopes.rb +14 -1
- data/app/models/spree/product.rb +10 -4
- data/app/models/spree/promotion_action.rb +4 -0
- data/app/models/spree/promotion_code/batch_builder.rb +3 -2
- data/app/models/spree/promotion_rule.rb +4 -0
- data/app/models/spree/role.rb +2 -0
- data/app/models/spree/role_user.rb +2 -0
- data/app/models/spree/shipment.rb +4 -2
- data/app/models/spree/shipping_method.rb +3 -1
- data/app/models/spree/shipping_rate.rb +1 -1
- data/app/models/spree/state.rb +10 -2
- data/app/models/spree/stock_item.rb +3 -3
- data/app/models/spree/store.rb +5 -0
- data/app/models/spree/store_credit.rb +2 -2
- data/app/models/spree/store_credit_event.rb +1 -1
- data/app/models/spree/store_selector/by_server_name.rb +30 -0
- data/app/models/spree/store_selector/legacy.rb +48 -0
- data/app/models/spree/tax/item_tax.rb +20 -0
- data/app/models/spree/tax/order_adjuster.rb +2 -14
- data/app/models/spree/tax/order_tax.rb +18 -0
- data/app/models/spree/tax/shipping_rate_taxer.rb +4 -13
- data/app/models/spree/tax/tax_helpers.rb +5 -3
- data/app/models/spree/tax_calculator/default.rb +83 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +46 -0
- data/app/models/spree/tax_category.rb +9 -1
- data/app/models/spree/tax_rate.rb +31 -7
- data/app/models/spree/tax_rate_tax_category.rb +6 -0
- data/app/models/spree/taxon.rb +1 -1
- data/app/models/spree/variant.rb +1 -1
- data/app/views/spree/{shipment_mailer → carton_mailer}/shipped_email.html.erb +3 -3
- data/app/views/spree/order_mailer/cancel_email.html.erb +3 -3
- data/app/views/spree/order_mailer/confirm_email.html.erb +2 -2
- data/app/views/spree/order_mailer/inventory_cancellation_email.html.erb +26 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +2 -2
- data/app/views/spree/test_mailer/test_email.html.erb +2 -2
- data/config/locales/en.yml +66 -57
- data/db/default/spree/refund_reasons.rb +1 -0
- data/db/default/spree/shipping_categories.rb +1 -0
- data/db/default/spree/stock_locations.rb +2 -0
- data/db/default/spree/stores.rb +3 -4
- data/db/migrate/20170412103617_transform_tax_rate_category_relation.rb +48 -0
- data/db/migrate/20170422134804_add_roles_unique_constraints.rb +6 -0
- data/db/migrate/20170522143442_add_time_range_to_tax_rate.rb +6 -0
- data/db/migrate/20170608074534_rename_bogus_gateways.rb +13 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +1 -1
- data/lib/generators/spree/dummy/dummy_generator.rb +10 -4
- data/lib/generators/spree/dummy/templates/rails/database.yml +12 -12
- data/lib/generators/spree/install/install_generator.rb +5 -5
- data/lib/generators/spree/install/templates/config/initializers/{spree.rb → solidus.rb} +0 -0
- data/lib/solidus/migrations/rename_gateways.rb +39 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +10 -5
- data/lib/spree/core/controller_helpers/store.rb +1 -9
- data/lib/spree/core/current_store.rb +6 -14
- data/lib/spree/core/engine.rb +4 -3
- data/lib/spree/core/importer/order.rb +4 -4
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +0 -1
- data/lib/spree/localized_number.rb +2 -1
- data/lib/spree/permitted_attributes.rb +12 -6
- data/lib/spree/testing_support/capybara_ext.rb +0 -1
- data/lib/spree/testing_support/factories/adjustment_factory.rb +5 -1
- data/lib/spree/testing_support/factories/order_factory.rb +26 -24
- data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipment_factory.rb +7 -3
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_factory.rb +3 -1
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -4
- data/lib/tasks/migrations/migrate_user_addresses.rake +2 -2
- data/lib/tasks/migrations/rename_gateways.rake +19 -0
- data/solidus_core.gemspec +2 -3
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +32 -6
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +0 -1
- data/spec/lib/spree/core/current_store_spec.rb +6 -11
- data/spec/lib/spree/core/price_migrator_spec.rb +4 -4
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +199 -91
- data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +18 -0
- data/spec/lib/spree/localized_number_spec.rb +6 -0
- data/spec/mailers/carton_mailer_spec.rb +3 -3
- data/spec/models/spree/address_spec.rb +3 -3
- data/spec/models/spree/adjustment_spec.rb +71 -27
- data/spec/models/spree/calculator/default_tax_spec.rb +72 -1
- data/spec/models/spree/calculator/distributed_amount_spec.rb +32 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +20 -1
- data/spec/models/spree/calculator/tiered_percent_spec.rb +20 -1
- data/spec/models/spree/distributed_amounts_handler_spec.rb +79 -0
- data/spec/models/spree/gateway/bogus_simple.rb +7 -13
- data/spec/models/spree/gateway/bogus_spec.rb +8 -4
- data/spec/models/spree/gateway_spec.rb +6 -105
- data/spec/models/spree/image_spec.rb +23 -0
- data/spec/models/spree/order/checkout_spec.rb +3 -18
- data/spec/models/spree/order/number_generator_spec.rb +45 -0
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +135 -0
- data/spec/models/spree/order/payment_spec.rb +7 -2
- data/spec/models/spree/order/state_machine_spec.rb +4 -2
- data/spec/models/spree/order_capturing_spec.rb +8 -8
- data/spec/models/spree/order_contents_spec.rb +8 -1
- data/spec/models/spree/order_shipping_spec.rb +5 -1
- data/spec/models/spree/order_spec.rb +156 -83
- data/spec/models/spree/order_taxation_spec.rb +126 -0
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +20 -21
- data/spec/models/spree/payment_create_spec.rb +14 -6
- data/spec/models/spree/payment_method/bogus_credit_card_spec.rb +8 -0
- data/spec/models/spree/payment_method/check_spec.rb +78 -0
- data/spec/models/spree/payment_method/credit_card_spec.rb +66 -0
- data/spec/models/spree/payment_method/simple_bogus_credit_card_spec.rb +18 -0
- data/spec/models/spree/payment_method_spec.rb +47 -2
- data/spec/models/spree/payment_spec.rb +6 -8
- data/spec/models/spree/preference_spec.rb +1 -1
- data/spec/models/spree/price_spec.rb +1 -1
- data/spec/models/spree/product/scopes_spec.rb +46 -0
- data/spec/models/spree/promotion_action_spec.rb +4 -0
- data/spec/models/spree/promotion_code/batch_builder_spec.rb +25 -3
- data/spec/models/spree/promotion_code_batch_spec.rb +0 -6
- data/spec/models/spree/promotion_handler/coupon_spec.rb +1 -1
- data/spec/models/spree/promotion_rule_spec.rb +5 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
- data/spec/models/spree/shipment_spec.rb +24 -3
- data/spec/models/spree/shipping_rate_spec.rb +5 -5
- data/spec/models/spree/state_spec.rb +31 -4
- data/spec/models/spree/stock/coordinator_spec.rb +24 -0
- data/spec/models/spree/stock/estimator_spec.rb +1 -1
- data/spec/models/spree/store_selector/by_server_name_spec.rb +26 -0
- data/spec/models/spree/store_selector/legacy_spec.rb +44 -0
- data/spec/models/spree/store_spec.rb +10 -2
- data/spec/models/spree/tax/order_adjuster_spec.rb +11 -21
- data/spec/models/spree/tax/shipping_rate_taxer_spec.rb +10 -3
- data/spec/models/spree/tax/taxation_integration_spec.rb +43 -8
- data/spec/models/spree/tax_calculator/default_spec.rb +54 -0
- data/spec/models/spree/tax_rate_spec.rb +92 -0
- data/spec/models/spree/variant/vat_price_generator_spec.rb +4 -4
- data/spec/models/spree/variant_spec.rb +8 -2
- data/spec/spec_helper.rb +2 -1
- data/spec/support/test_gateway.rb +1 -1
- metadata +45 -24
- data/app/models/spree/tax/item_adjuster.rb +0 -51
- data/spec/models/spree/tax/item_adjuster_spec.rb +0 -82
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class TransformTaxRateCategoryRelation < ActiveRecord::Migration[5.0]
|
|
2
|
+
class TaxRate < ActiveRecord::Base
|
|
3
|
+
self.table_name = "spree_tax_rates"
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class TaxRateTaxCategory < ActiveRecord::Base
|
|
7
|
+
self.table_name = "spree_tax_rate_tax_categories"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def up
|
|
11
|
+
create_table :spree_tax_rate_tax_categories do |t|
|
|
12
|
+
t.integer :tax_category_id, index: true, null: false
|
|
13
|
+
t.integer :tax_rate_id, index: true, null: false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
add_foreign_key :spree_tax_rate_tax_categories, :spree_tax_categories, column: :tax_category_id
|
|
17
|
+
add_foreign_key :spree_tax_rate_tax_categories, :spree_tax_rates, column: :tax_rate_id
|
|
18
|
+
|
|
19
|
+
TaxRate.where.not(tax_category_id: nil).find_each do |tax_rate|
|
|
20
|
+
TaxRateTaxCategory.create!(
|
|
21
|
+
tax_rate_id: tax_rate.id,
|
|
22
|
+
tax_category_id: tax_rate.tax_category_id
|
|
23
|
+
)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
remove_column :spree_tax_rates, :tax_category_id
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def down
|
|
30
|
+
add_column :spree_tax_rates, :tax_category_id, :integer, index: true
|
|
31
|
+
add_foreign_key :spree_tax_rates, :spree_tax_categories, column: :tax_category_id
|
|
32
|
+
|
|
33
|
+
TaxRate.find_each do |tax_rate|
|
|
34
|
+
tax_category_ids = TaxRateTaxCategory.where(tax_rate_id: tax_rate.id).pluck(:tax_category_id)
|
|
35
|
+
|
|
36
|
+
tax_category_ids.each_with_index do |category_id, i|
|
|
37
|
+
if i.zero?
|
|
38
|
+
tax_rate.update!(tax_category_id: category_id)
|
|
39
|
+
else
|
|
40
|
+
new_tax_rate = tax_rate.dup
|
|
41
|
+
new_tax_rate.update!(tax_category_id: category_id)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
drop_table :spree_tax_rate_tax_categories
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class RenameBogusGateways < ActiveRecord::Migration[5.0]
|
|
2
|
+
def up
|
|
3
|
+
say_with_time 'Renaming bogus gateways into payment methods' do
|
|
4
|
+
Rake::Task['solidus:migrations:rename_gateways:up'].invoke
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def down
|
|
9
|
+
say_with_time 'Renaming bogus payment methods into gateways' do
|
|
10
|
+
Rake::Task['solidus:migrations:rename_gateways:down'].invoke
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -3,7 +3,7 @@ module Spree
|
|
|
3
3
|
include Rails::Generators::ResourceHelpers
|
|
4
4
|
include Rails::Generators::Migration
|
|
5
5
|
|
|
6
|
-
desc "Set up a
|
|
6
|
+
desc "Set up a Solidus installation with a custom User class"
|
|
7
7
|
|
|
8
8
|
def self.source_paths
|
|
9
9
|
paths = superclass.source_paths
|
|
@@ -4,7 +4,7 @@ require 'spree/core/version'
|
|
|
4
4
|
|
|
5
5
|
module Spree
|
|
6
6
|
class DummyGenerator < Rails::Generators::Base
|
|
7
|
-
desc "Creates blank Rails application, installs
|
|
7
|
+
desc "Creates blank Rails application, installs Solidus and all sample data"
|
|
8
8
|
|
|
9
9
|
class_option :lib_name, default: ''
|
|
10
10
|
class_option :database, default: ''
|
|
@@ -30,6 +30,15 @@ module Spree
|
|
|
30
30
|
opts[:database] = 'sqlite3' if opts[:database].blank?
|
|
31
31
|
opts[:force] = true
|
|
32
32
|
opts[:skip_bundle] = true
|
|
33
|
+
opts[:skip_gemfile] = true
|
|
34
|
+
opts[:skip_git] = true
|
|
35
|
+
opts[:skip_keeps] = true
|
|
36
|
+
opts[:skip_listen] = true
|
|
37
|
+
opts[:skip_puma] = true
|
|
38
|
+
opts[:skip_rc] = true
|
|
39
|
+
opts[:skip_spring] = true
|
|
40
|
+
opts[:skip_test] = true
|
|
41
|
+
opts[:skip_yarn] = true
|
|
33
42
|
|
|
34
43
|
puts "Generating dummy Rails application..."
|
|
35
44
|
invoke Rails::Generators::AppGenerator,
|
|
@@ -46,9 +55,6 @@ module Spree
|
|
|
46
55
|
template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
|
|
47
56
|
template "rails/test.rb", "#{dummy_path}/config/environments/test.rb", force: true
|
|
48
57
|
template "rails/script/rails", "#{dummy_path}/spec/dummy/script/rails", force: true
|
|
49
|
-
|
|
50
|
-
# FIXME: We aren't ready for rails 5 defaults
|
|
51
|
-
remove_file "#{dummy_path}/config/initializers/new_framework_defaults.rb"
|
|
52
58
|
end
|
|
53
59
|
|
|
54
60
|
def test_dummy_inject_extension_requirements
|
|
@@ -5,32 +5,32 @@ end %>
|
|
|
5
5
|
when 'sqlite' %>
|
|
6
6
|
development:
|
|
7
7
|
adapter: sqlite3
|
|
8
|
-
database: db/
|
|
8
|
+
database: db/solidus_development.sqlite3
|
|
9
9
|
test:
|
|
10
10
|
adapter: sqlite3
|
|
11
|
-
database: db/
|
|
11
|
+
database: db/solidus_test.sqlite3
|
|
12
12
|
timeout: 10000
|
|
13
13
|
production:
|
|
14
14
|
adapter: sqlite3
|
|
15
|
-
database: db/
|
|
15
|
+
database: db/solidus_production.sqlite3
|
|
16
16
|
<% when 'mysql' %>
|
|
17
17
|
development:
|
|
18
18
|
adapter: mysql2
|
|
19
|
-
database: <%= database_prefix %><%= options[:lib_name] %>
|
|
19
|
+
database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development
|
|
20
20
|
encoding: utf8
|
|
21
21
|
test:
|
|
22
22
|
adapter: mysql2
|
|
23
|
-
database: <%= database_prefix %><%= options[:lib_name] %>
|
|
23
|
+
database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test
|
|
24
24
|
encoding: utf8
|
|
25
25
|
production:
|
|
26
26
|
adapter: mysql2
|
|
27
|
-
database: <%= database_prefix %><%= options[:lib_name] %>
|
|
27
|
+
database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production
|
|
28
28
|
encoding: utf8
|
|
29
29
|
<% when 'postgres', 'postgresql' %>
|
|
30
30
|
<% db_host = ENV['DB_HOST'] -%>
|
|
31
31
|
development:
|
|
32
32
|
adapter: postgresql
|
|
33
|
-
database: <%= database_prefix %><%= options[:lib_name] %>
|
|
33
|
+
database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development
|
|
34
34
|
username: postgres
|
|
35
35
|
min_messages: warning
|
|
36
36
|
<% unless db_host.blank? %>
|
|
@@ -38,7 +38,7 @@ development:
|
|
|
38
38
|
<% end %>
|
|
39
39
|
test:
|
|
40
40
|
adapter: postgresql
|
|
41
|
-
database: <%= database_prefix %><%= options[:lib_name] %>
|
|
41
|
+
database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test
|
|
42
42
|
username: postgres
|
|
43
43
|
min_messages: warning
|
|
44
44
|
<% unless db_host.blank? %>
|
|
@@ -46,7 +46,7 @@ test:
|
|
|
46
46
|
<% end %>
|
|
47
47
|
production:
|
|
48
48
|
adapter: postgresql
|
|
49
|
-
database: <%= database_prefix %><%= options[:lib_name] %>
|
|
49
|
+
database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production
|
|
50
50
|
username: postgres
|
|
51
51
|
min_messages: warning
|
|
52
52
|
<% unless db_host.blank? %>
|
|
@@ -55,13 +55,13 @@ production:
|
|
|
55
55
|
<% when 'sqlite', '', nil %>
|
|
56
56
|
development:
|
|
57
57
|
adapter: sqlite3
|
|
58
|
-
database: db/
|
|
58
|
+
database: db/solidus_development.sqlite3
|
|
59
59
|
test:
|
|
60
60
|
adapter: sqlite3
|
|
61
|
-
database: db/
|
|
61
|
+
database: db/solidus_test.sqlite3
|
|
62
62
|
production:
|
|
63
63
|
adapter: sqlite3
|
|
64
|
-
database: db/
|
|
64
|
+
database: db/solidus_production.sqlite3
|
|
65
65
|
<% else %>
|
|
66
66
|
<% raise "Invalid DB specified: #{ENV['DB']}" %>
|
|
67
67
|
<% end %>
|
|
@@ -5,7 +5,7 @@ require 'bundler/cli'
|
|
|
5
5
|
|
|
6
6
|
module Spree
|
|
7
7
|
class InstallGenerator < Rails::Generators::Base
|
|
8
|
-
class_option :migrate, type: :boolean, default: true, banner: 'Run
|
|
8
|
+
class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
|
|
9
9
|
class_option :seed, type: :boolean, default: true, banner: 'load seed data (migrations must be run)'
|
|
10
10
|
class_option :sample, type: :boolean, default: true, banner: 'load sample data (migrations must be run)'
|
|
11
11
|
class_option :auto_accept, type: :boolean
|
|
@@ -35,7 +35,7 @@ module Spree
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def add_files
|
|
38
|
-
template 'config/initializers/
|
|
38
|
+
template 'config/initializers/solidus.rb', 'config/initializers/solidus.rb'
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def additional_tweaks
|
|
@@ -152,11 +152,11 @@ Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
|
|
|
152
152
|
def install_routes
|
|
153
153
|
insert_into_file File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n" do
|
|
154
154
|
<<-ROUTES
|
|
155
|
-
# This line mounts
|
|
155
|
+
# This line mounts Solidus's routes at the root of your application.
|
|
156
156
|
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
|
|
157
157
|
# If you would like to change where this engine is mounted, simply change the :at option to something different.
|
|
158
158
|
#
|
|
159
|
-
# We ask that you don't use the :as option here, as
|
|
159
|
+
# We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
|
|
160
160
|
mount Spree::Core::Engine, at: '/'
|
|
161
161
|
|
|
162
162
|
ROUTES
|
|
@@ -173,7 +173,7 @@ Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
|
|
|
173
173
|
def complete
|
|
174
174
|
unless options[:quiet]
|
|
175
175
|
puts "*" * 50
|
|
176
|
-
puts "
|
|
176
|
+
puts "Solidus has been installed successfully. You're all ready to go!"
|
|
177
177
|
puts " "
|
|
178
178
|
puts "Enjoy!"
|
|
179
179
|
end
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
@gateway_mapping = gateway_mapping
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def up
|
|
19
|
+
gateway_mapping.inject(0) do |count, mapping|
|
|
20
|
+
count + update(from: mapping[0], to: mapping[1])
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def down
|
|
25
|
+
gateway_mapping.inject(0) do |count, mapping|
|
|
26
|
+
count + update(from: mapping[1], to: mapping[0])
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def update(from:, to:)
|
|
33
|
+
ActiveRecord::Base.connection.update <<-SQL.strip_heredoc
|
|
34
|
+
UPDATE spree_payment_methods SET type = '#{to}' WHERE type = '#{from}';
|
|
35
|
+
SQL
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -14,7 +14,6 @@ module Spree
|
|
|
14
14
|
helper_method :simple_current_order
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
# Used in the link_to_cart helper.
|
|
18
17
|
def simple_current_order
|
|
19
18
|
return @simple_current_order if @simple_current_order
|
|
20
19
|
|
|
@@ -24,9 +23,10 @@ module Spree
|
|
|
24
23
|
@simple_current_order.last_ip_address = ip_address
|
|
25
24
|
return @simple_current_order
|
|
26
25
|
else
|
|
27
|
-
@simple_current_order = Spree::Order.new
|
|
26
|
+
@simple_current_order = Spree::Order.new(current_order_params)
|
|
28
27
|
end
|
|
29
28
|
end
|
|
29
|
+
deprecate simple_current_order: :current_order, deprecator: Spree::Deprecation
|
|
30
30
|
|
|
31
31
|
# The current incomplete order from the guest_token for use in cart and during checkout
|
|
32
32
|
def current_order(options = {})
|
|
@@ -34,10 +34,10 @@ module Spree
|
|
|
34
34
|
|
|
35
35
|
return @current_order if @current_order
|
|
36
36
|
|
|
37
|
-
@current_order = find_order_by_token_or_user(options
|
|
37
|
+
@current_order = find_order_by_token_or_user(options)
|
|
38
38
|
|
|
39
39
|
if options[:create_order_if_necessary] && (@current_order.nil? || @current_order.completed?)
|
|
40
|
-
@current_order = Spree::Order.new(
|
|
40
|
+
@current_order = Spree::Order.new(new_order_params)
|
|
41
41
|
@current_order.user ||= try_spree_current_user
|
|
42
42
|
# See issue https://github.com/spree/spree/issues/3346 for reasons why this line is here
|
|
43
43
|
@current_order.created_by ||= try_spree_current_user
|
|
@@ -45,7 +45,7 @@ module Spree
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
if @current_order
|
|
48
|
-
@current_order.
|
|
48
|
+
@current_order.record_ip_address(ip_address)
|
|
49
49
|
return @current_order
|
|
50
50
|
end
|
|
51
51
|
end
|
|
@@ -79,11 +79,16 @@ module Spree
|
|
|
79
79
|
{ currency: current_pricing_options.currency, guest_token: cookies.signed[:guest_token], store_id: current_store.id, user_id: try_spree_current_user.try(:id) }
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
def new_order_params
|
|
83
|
+
current_order_params.merge(last_ip_address: ip_address)
|
|
84
|
+
end
|
|
85
|
+
|
|
82
86
|
def find_order_by_token_or_user(options = {}, with_adjustments = false)
|
|
83
87
|
options[:lock] ||= false
|
|
84
88
|
|
|
85
89
|
# Find any incomplete orders for the guest_token
|
|
86
90
|
if with_adjustments
|
|
91
|
+
Spree::Deprecation.warn "The second argument to find_order_by_token_or_user is deprecated, and will be removed in a future version."
|
|
87
92
|
order = Spree::Order.incomplete.includes(:adjustments).lock(options[:lock]).find_by(current_order_params)
|
|
88
93
|
else
|
|
89
94
|
order = Spree::Order.incomplete.lock(options[:lock]).find_by(current_order_params)
|
|
@@ -4,20 +4,12 @@ module Spree
|
|
|
4
4
|
module Store
|
|
5
5
|
extend ActiveSupport::Concern
|
|
6
6
|
|
|
7
|
-
# @!attribute [rw] current_store_class
|
|
8
|
-
# @!scope class
|
|
9
|
-
# Extension point for overriding how the current store is chosen.
|
|
10
|
-
# Defaults to checking headers and server name
|
|
11
|
-
# @return [#store] class used to help find the current store
|
|
12
7
|
included do
|
|
13
|
-
class_attribute :current_store_class
|
|
14
|
-
self.current_store_class = Spree::Core::CurrentStore
|
|
15
|
-
|
|
16
8
|
helper_method :current_store
|
|
17
9
|
end
|
|
18
10
|
|
|
19
11
|
def current_store
|
|
20
|
-
@current_store ||=
|
|
12
|
+
@current_store ||= Spree::Config.current_store_selector_class.new(request).store
|
|
21
13
|
end
|
|
22
14
|
end
|
|
23
15
|
end
|
|
@@ -6,24 +6,16 @@ module Spree
|
|
|
6
6
|
class CurrentStore
|
|
7
7
|
def initialize(request)
|
|
8
8
|
@request = request
|
|
9
|
+
@current_store_selector = Spree::Config.current_store_selector_class.new(request)
|
|
10
|
+
Spree::Deprecation.warn "Using Spree::Core::CurrentStore is deprecated. Use Spree::Config.current_store_selector_class instead", caller
|
|
9
11
|
end
|
|
10
12
|
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
13
|
+
# Delegate store selection to Spree::Config.current_store_selector_class
|
|
14
|
+
# Using this class is deprecated.
|
|
15
|
+
#
|
|
14
16
|
# @return [Spree::Store]
|
|
15
17
|
def store
|
|
16
|
-
|
|
17
|
-
Spree::Store.current(store_key)
|
|
18
|
-
else
|
|
19
|
-
Spree::Store.default
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def store_key
|
|
26
|
-
@request.headers['HTTP_SPREE_STORE'] || @request.env['SERVER_NAME']
|
|
18
|
+
@current_store_selector.store
|
|
27
19
|
end
|
|
28
20
|
end
|
|
29
21
|
end
|
data/lib/spree/core/engine.rb
CHANGED
|
@@ -43,8 +43,8 @@ module Spree
|
|
|
43
43
|
|
|
44
44
|
initializer "spree.register.payment_methods", before: :load_config_initializers do |app|
|
|
45
45
|
app.config.spree.payment_methods = %w[
|
|
46
|
-
Spree::
|
|
47
|
-
Spree::
|
|
46
|
+
Spree::PaymentMethod::BogusCreditCard
|
|
47
|
+
Spree::PaymentMethod::SimpleBogusCreditCard
|
|
48
48
|
Spree::PaymentMethod::StoreCredit
|
|
49
49
|
Spree::PaymentMethod::Check
|
|
50
50
|
]
|
|
@@ -67,9 +67,10 @@ module Spree
|
|
|
67
67
|
]
|
|
68
68
|
|
|
69
69
|
app.config.spree.calculators.promotion_actions_create_item_adjustments = %w[
|
|
70
|
-
Spree::Calculator::
|
|
70
|
+
Spree::Calculator::DistributedAmount
|
|
71
71
|
Spree::Calculator::FlatRate
|
|
72
72
|
Spree::Calculator::FlexiRate
|
|
73
|
+
Spree::Calculator::PercentOnLineItem
|
|
73
74
|
Spree::Calculator::TieredPercent
|
|
74
75
|
]
|
|
75
76
|
|
|
@@ -54,7 +54,7 @@ module Spree
|
|
|
54
54
|
shipments_hash.each do |s|
|
|
55
55
|
shipment = Shipment.new
|
|
56
56
|
shipment.tracking = s[:tracking]
|
|
57
|
-
shipment.stock_location = Spree::StockLocation.
|
|
57
|
+
shipment.stock_location = Spree::StockLocation.find_by(admin_name: s[:stock_location]) || Spree::StockLocation.find_by!(name: s[:stock_location])
|
|
58
58
|
|
|
59
59
|
inventory_units = s[:inventory_units] || []
|
|
60
60
|
inventory_units.each do |iu|
|
|
@@ -87,7 +87,7 @@ module Spree
|
|
|
87
87
|
order.shipments << shipment
|
|
88
88
|
shipment.save!
|
|
89
89
|
|
|
90
|
-
shipping_method = Spree::ShippingMethod.
|
|
90
|
+
shipping_method = Spree::ShippingMethod.find_by(name: s[:shipping_method]) || Spree::ShippingMethod.find_by!(admin_name: s[:shipping_method])
|
|
91
91
|
rate = shipment.shipping_rates.create!(shipping_method: shipping_method,
|
|
92
92
|
cost: s[:cost])
|
|
93
93
|
shipment.selected_shipping_rate_id = rate.id
|
|
@@ -131,7 +131,7 @@ module Spree
|
|
|
131
131
|
# Order API should be using state as that's the normal payment field.
|
|
132
132
|
# spree_wombat serializes payment state as status so imported orders should fall back to status field.
|
|
133
133
|
payment.state = p[:state] || p[:status] || 'completed'
|
|
134
|
-
payment.payment_method = Spree::PaymentMethod.
|
|
134
|
+
payment.payment_method = Spree::PaymentMethod.find_by!(name: p[:payment_method])
|
|
135
135
|
payment.source = create_source_payment_from_params(p[:source], payment) if p[:source]
|
|
136
136
|
payment.save!
|
|
137
137
|
end
|
|
@@ -154,7 +154,7 @@ module Spree
|
|
|
154
154
|
def self.ensure_variant_id_from_params(hash)
|
|
155
155
|
sku = hash.delete(:sku)
|
|
156
156
|
unless hash[:variant_id].present?
|
|
157
|
-
hash[:variant_id] = Spree::Variant.with_prices.
|
|
157
|
+
hash[:variant_id] = Spree::Variant.with_prices.find_by!(sku: sku).id
|
|
158
158
|
end
|
|
159
159
|
hash
|
|
160
160
|
end
|
data/lib/spree/core/version.rb
CHANGED
data/lib/spree/core.rb
CHANGED
|
@@ -21,7 +21,8 @@ module Spree
|
|
|
21
21
|
# then replace the locale-specific decimal separator with the standard separator if necessary
|
|
22
22
|
number = number.gsub(separator, '.') unless separator == '.'
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
# Handle empty string for ruby 2.4 compatibility
|
|
25
|
+
BigDecimal.new(number.presence || 0)
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
end
|
|
@@ -73,7 +73,8 @@ module Spree
|
|
|
73
73
|
:meta_keywords, :price, :sku, :deleted_at,
|
|
74
74
|
:option_values_hash, :weight, :height, :width, :depth,
|
|
75
75
|
:shipping_category_id, :tax_category_id,
|
|
76
|
-
:taxon_ids, :option_type_ids, :cost_currency, :cost_price
|
|
76
|
+
:taxon_ids, :option_type_ids, :cost_currency, :cost_price
|
|
77
|
+
]
|
|
77
78
|
|
|
78
79
|
@@property_attributes = [:name, :presentation]
|
|
79
80
|
|
|
@@ -81,7 +82,8 @@ module Spree
|
|
|
81
82
|
|
|
82
83
|
@@shipment_attributes = [
|
|
83
84
|
:special_instructions, :stock_location_id, :id, :tracking,
|
|
84
|
-
:selected_shipping_rate_id
|
|
85
|
+
:selected_shipping_rate_id
|
|
86
|
+
]
|
|
85
87
|
|
|
86
88
|
# month / year may be provided by some sources, or others may elect to use one field
|
|
87
89
|
@@source_attributes = [
|
|
@@ -96,10 +98,12 @@ module Spree
|
|
|
96
98
|
@@stock_location_attributes = [
|
|
97
99
|
:name, :active, :address1, :address2, :city, :zipcode,
|
|
98
100
|
:backorderable_default, :state_name, :state_id, :country_id, :phone,
|
|
99
|
-
:propagate_all_variants
|
|
101
|
+
:propagate_all_variants
|
|
102
|
+
]
|
|
100
103
|
|
|
101
104
|
@@stock_movement_attributes = [
|
|
102
|
-
:quantity, :stock_item, :stock_item_id, :originator, :action
|
|
105
|
+
:quantity, :stock_item, :stock_item_id, :originator, :action
|
|
106
|
+
]
|
|
103
107
|
|
|
104
108
|
@@store_attributes = [:name, :url, :seo_title, :meta_keywords,
|
|
105
109
|
:meta_description, :default_currency,
|
|
@@ -109,7 +113,8 @@ module Spree
|
|
|
109
113
|
|
|
110
114
|
@@taxon_attributes = [
|
|
111
115
|
:name, :parent_id, :position, :icon, :description, :permalink, :taxonomy_id,
|
|
112
|
-
:meta_description, :meta_keywords, :meta_title, :child_index
|
|
116
|
+
:meta_description, :meta_keywords, :meta_title, :child_index
|
|
117
|
+
]
|
|
113
118
|
|
|
114
119
|
@@transfer_item_attributes = [:variant_id, :expected_quantity, :received_quantity]
|
|
115
120
|
|
|
@@ -123,6 +128,7 @@ module Spree
|
|
|
123
128
|
:name, :presentation, :cost_price, :lock_version,
|
|
124
129
|
:position, :track_inventory,
|
|
125
130
|
:product_id, :product, :option_values_attributes, :price,
|
|
126
|
-
:weight, :height, :width, :depth, :sku, :cost_currency, option_value_ids: [], options: [:name, :value]
|
|
131
|
+
:weight, :height, :width, :depth, :sku, :cost_currency, option_value_ids: [], options: [:name, :value]
|
|
132
|
+
]
|
|
127
133
|
end
|
|
128
134
|
end
|
|
@@ -29,7 +29,11 @@ FactoryGirl.define do
|
|
|
29
29
|
after(:create) do |adjustment|
|
|
30
30
|
# Set correct tax category, so that adjustment amount is not 0
|
|
31
31
|
if adjustment.adjustable.is_a?(Spree::LineItem)
|
|
32
|
-
|
|
32
|
+
if adjustment.adjustable.tax_category.present?
|
|
33
|
+
adjustment.source.tax_categories = [adjustment.adjustable.tax_category]
|
|
34
|
+
else
|
|
35
|
+
adjustment.source.tax_categories = []
|
|
36
|
+
end
|
|
33
37
|
adjustment.source.save
|
|
34
38
|
adjustment.update!
|
|
35
39
|
end
|
|
@@ -18,10 +18,14 @@ FactoryGirl.define do
|
|
|
18
18
|
line_items_price BigDecimal.new(10)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# TODO: Improve the name of order_with_totals factory.
|
|
21
22
|
factory :order_with_totals do
|
|
22
|
-
after(:
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
after(:build) do |order, evaluator|
|
|
24
|
+
order.line_items << build(
|
|
25
|
+
:line_item,
|
|
26
|
+
order: order,
|
|
27
|
+
price: evaluator.line_items_price
|
|
28
|
+
)
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
@@ -37,7 +41,7 @@ FactoryGirl.define do
|
|
|
37
41
|
stock_location { create(:stock_location) }
|
|
38
42
|
end
|
|
39
43
|
|
|
40
|
-
after(:
|
|
44
|
+
after(:build) do |order, evaluator|
|
|
41
45
|
evaluator.stock_location # must evaluate before creating line items
|
|
42
46
|
|
|
43
47
|
evaluator.line_items_attributes.each do |attributes|
|
|
@@ -52,6 +56,24 @@ FactoryGirl.define do
|
|
|
52
56
|
order.update!
|
|
53
57
|
end
|
|
54
58
|
|
|
59
|
+
factory :completed_order_with_promotion do
|
|
60
|
+
transient do
|
|
61
|
+
promotion nil
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
after(:create) do |order, evaluator|
|
|
65
|
+
promotion = evaluator.promotion || create(:promotion, code: "test")
|
|
66
|
+
promotion_code = promotion.codes.first || create(:promotion_code, promotion: promotion)
|
|
67
|
+
|
|
68
|
+
promotion.activate(order: order, promotion_code: promotion_code)
|
|
69
|
+
order.order_promotions.create!(promotion: promotion, promotion_code: promotion_code)
|
|
70
|
+
|
|
71
|
+
# Complete the order after the promotion has been activated
|
|
72
|
+
order.update_column(:completed_at, Time.current)
|
|
73
|
+
order.update_column(:state, "complete")
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
55
77
|
factory :order_ready_to_complete do
|
|
56
78
|
state 'confirm'
|
|
57
79
|
payment_state 'checkout'
|
|
@@ -75,7 +97,6 @@ FactoryGirl.define do
|
|
|
75
97
|
state 'complete'
|
|
76
98
|
|
|
77
99
|
after(:create) do |order|
|
|
78
|
-
order.refresh_shipment_rates
|
|
79
100
|
order.shipments.each do |shipment|
|
|
80
101
|
shipment.inventory_units.update_all state: 'on_hand', pending: false
|
|
81
102
|
end
|
|
@@ -130,23 +151,4 @@ FactoryGirl.define do
|
|
|
130
151
|
end
|
|
131
152
|
end
|
|
132
153
|
end
|
|
133
|
-
|
|
134
|
-
factory :completed_order_with_promotion, parent: :order_with_line_items, class: "Spree::Order" do
|
|
135
|
-
transient do
|
|
136
|
-
promotion nil
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
after(:create) do |order, evaluator|
|
|
140
|
-
promotion = evaluator.promotion || create(:promotion, code: "test")
|
|
141
|
-
promotion_code = promotion.codes.first || create(:promotion_code, promotion: promotion)
|
|
142
|
-
|
|
143
|
-
promotion.activate(order: order, promotion_code: promotion_code)
|
|
144
|
-
order.order_promotions.create!(promotion: promotion, promotion_code: promotion_code)
|
|
145
|
-
|
|
146
|
-
# Complete the order after the promotion has been activated
|
|
147
|
-
order.refresh_shipment_rates
|
|
148
|
-
order.update_column(:completed_at, Time.current)
|
|
149
|
-
order.update_column(:state, "complete")
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
154
|
end
|