solidus_core 1.3.0.beta1 → 1.3.0.rc1
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/Gemfile +1 -1
- data/app/assets/images/noimage/large.png +0 -0
- data/app/assets/images/noimage/mini.png +0 -0
- data/app/assets/images/noimage/product.png +0 -0
- data/app/assets/images/noimage/small.png +0 -0
- data/app/models/spree/app_configuration.rb +9 -9
- data/app/models/spree/country.rb +1 -0
- data/app/models/spree/line_item.rb +7 -1
- data/app/models/spree/payment_method.rb +1 -1
- data/app/models/spree/preferences/preferable.rb +1 -0
- data/app/models/spree/preferences/statically_configurable.rb +2 -2
- data/app/models/spree/price.rb +30 -2
- data/app/models/spree/product.rb +4 -1
- data/app/models/spree/stock/inventory_unit_builder.rb +2 -2
- data/app/models/spree/tax/tax_location.rb +4 -0
- data/app/models/spree/tax_rate.rb +2 -11
- data/app/models/spree/variant/price_selector.rb +35 -0
- data/app/models/spree/variant/pricing_options.rb +69 -4
- data/app/models/spree/variant/vat_price_generator.rb +58 -0
- data/app/models/spree/variant.rb +38 -16
- data/config/locales/en.yml +22 -1
- data/db/migrate/20140410141842_add_many_missing_indexes.rb +15 -13
- data/db/migrate/20140410150358_correct_some_polymorphic_index_and_add_more_missing.rb +40 -38
- data/db/migrate/20141217215630_update_product_slug_index.rb +4 -2
- data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +2 -10
- data/db/migrate/20151219020209_add_stock_item_unique_index.rb +2 -2
- data/db/migrate/20160509181311_add_country_iso_to_prices.rb +8 -0
- data/lib/spree/core/class_constantizer.rb +31 -0
- data/lib/spree/core/engine.rb +55 -59
- data/lib/spree/core/environment/calculators.rb +6 -1
- data/lib/spree/core/environment.rb +5 -2
- data/lib/spree/core/environment_extension.rb +16 -12
- data/lib/spree/core/price_migrator.rb +32 -0
- data/lib/spree/core/search/base.rb +2 -2
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +4 -0
- data/lib/spree/migration_helpers.rb +19 -0
- data/lib/spree/money.rb +41 -15
- data/lib/spree/promo/environment.rb +2 -1
- data/lib/spree/testing_support/controller_requests.rb +22 -7
- data/lib/spree/testing_support/factories/state_factory.rb +7 -0
- data/lib/spree/testing_support/factories/stock_location_factory.rb +4 -1
- data/lib/tasks/migrations/create_vat_prices.rake +11 -0
- data/lib/tasks/upgrade.rake +2 -1
- data/spec/lib/spree/core/class_constantizer_spec.rb +68 -0
- data/spec/lib/spree/core/environment_extension_spec.rb +33 -0
- data/spec/lib/spree/core/price_migrator_spec.rb +356 -0
- data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +9 -0
- data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +9 -0
- data/spec/lib/spree/money_spec.rb +75 -0
- data/spec/models/spree/app_configuration_spec.rb +5 -5
- data/spec/models/spree/country_spec.rb +16 -0
- data/spec/models/spree/line_item_spec.rb +6 -2
- data/spec/models/spree/preferences/preferable_spec.rb +5 -0
- data/spec/models/spree/preferences/statically_configurable_spec.rb +4 -0
- data/spec/models/spree/price_spec.rb +89 -0
- data/spec/models/spree/stock/coordinator_spec.rb +9 -0
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +30 -32
- data/spec/models/spree/tax/tax_location_spec.rb +14 -5
- data/spec/models/spree/tax/taxation_integration_spec.rb +15 -42
- data/spec/models/spree/variant/{pricer_spec.rb → price_selector_spec.rb} +41 -1
- data/spec/models/spree/variant/pricing_options_spec.rb +87 -4
- data/spec/models/spree/variant/vat_price_generator_spec.rb +69 -0
- data/spec/models/spree/variant_spec.rb +57 -8
- metadata +14 -5
- data/app/models/spree/product_scope/scopes.rb +0 -47
- data/app/models/spree/variant/pricer.rb +0 -19
@@ -1,63 +1,65 @@
|
|
1
1
|
class CorrectSomePolymorphicIndexAndAddMoreMissing < ActiveRecord::Migration
|
2
|
+
include Spree::MigrationHelpers
|
3
|
+
|
2
4
|
def change
|
3
|
-
|
4
|
-
|
5
|
+
safe_add_index :spree_addresses, :country_id
|
6
|
+
safe_add_index :spree_addresses, :state_id
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
safe_remove_index :spree_adjustments, [:source_type, :source_id]
|
9
|
+
safe_add_index :spree_adjustments, [:source_id, :source_type]
|
8
10
|
|
9
|
-
|
11
|
+
safe_add_index :spree_inventory_units, :return_authorization_id
|
10
12
|
|
11
|
-
|
13
|
+
safe_add_index :spree_log_entries, [:source_id, :source_type]
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
safe_add_index :spree_orders, :approver_id
|
16
|
+
safe_add_index :spree_orders, :created_by_id
|
17
|
+
safe_add_index :spree_orders, :ship_address_id
|
18
|
+
safe_add_index :spree_orders, :bill_address_id
|
19
|
+
safe_add_index :spree_orders, :considered_risky
|
18
20
|
|
19
|
-
|
21
|
+
safe_add_index :spree_orders_promotions, [:order_id, :promotion_id]
|
20
22
|
|
21
|
-
|
23
|
+
safe_add_index :spree_payments, [:source_id, :source_type]
|
22
24
|
|
23
|
-
|
25
|
+
safe_add_index :spree_product_option_types, :position
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
safe_add_index :spree_product_properties, :position
|
28
|
+
safe_add_index :spree_product_properties, :property_id
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
safe_add_index :spree_promotion_action_line_items, :promotion_action_id
|
31
|
+
safe_add_index :spree_promotion_action_line_items, :variant_id
|
30
32
|
|
31
|
-
|
33
|
+
safe_add_index :spree_promotion_rules, :promotion_id
|
32
34
|
|
33
|
-
|
35
|
+
safe_add_index :spree_promotions, :advertise
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
safe_add_index :spree_return_authorizations, :number
|
38
|
+
safe_add_index :spree_return_authorizations, :order_id
|
39
|
+
safe_add_index :spree_return_authorizations, :stock_location_id
|
38
40
|
|
39
|
-
|
41
|
+
safe_add_index :spree_shipments, :address_id
|
40
42
|
|
41
|
-
|
43
|
+
safe_add_index :spree_shipping_methods, :tax_category_id
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
safe_add_index :spree_state_changes, [:stateful_id, :stateful_type]
|
46
|
+
safe_add_index :spree_state_changes, :user_id
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
safe_add_index :spree_stock_locations, :country_id
|
49
|
+
safe_add_index :spree_stock_locations, :state_id
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
safe_add_index :spree_tax_rates, :deleted_at
|
52
|
+
safe_add_index :spree_tax_rates, :tax_category_id
|
53
|
+
safe_add_index :spree_tax_rates, :zone_id
|
52
54
|
|
53
|
-
|
55
|
+
safe_add_index :spree_taxonomies, :position
|
54
56
|
|
55
|
-
|
57
|
+
safe_add_index :spree_taxons, :position
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
+
safe_add_index :spree_variants, :position
|
60
|
+
safe_add_index :spree_variants, :track_inventory
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
+
safe_add_index :spree_zone_members, :zone_id
|
63
|
+
safe_add_index :spree_zone_members, [:zoneable_id, :zoneable_type]
|
62
64
|
end
|
63
65
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class UpdateProductSlugIndex < ActiveRecord::Migration
|
2
|
+
include Spree::MigrationHelpers
|
3
|
+
|
2
4
|
def change
|
3
|
-
|
4
|
-
|
5
|
+
safe_remove_index :spree_products, :slug
|
6
|
+
safe_add_index :spree_products, :slug, unique: true
|
5
7
|
end
|
6
8
|
end
|
@@ -4,6 +4,8 @@
|
|
4
4
|
# migration deletes any of the indexes left around in stores using the
|
5
5
|
# out-dated version of that migration
|
6
6
|
class RemoveUnnecessaryIndexes < ActiveRecord::Migration
|
7
|
+
include Spree::MigrationHelpers
|
8
|
+
|
7
9
|
def up
|
8
10
|
safe_remove_index :spree_credit_cards, :address_id
|
9
11
|
safe_remove_index :spree_gateways, :active
|
@@ -59,14 +61,4 @@ class RemoveUnnecessaryIndexes < ActiveRecord::Migration
|
|
59
61
|
safe_add_index :spree_variants, :deleted_at
|
60
62
|
safe_add_index :spree_zones, :default_tax
|
61
63
|
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def safe_remove_index(table, column)
|
66
|
-
remove_index(table, column) if index_exists?(table, column)
|
67
|
-
end
|
68
|
-
|
69
|
-
def safe_add_index(table, column)
|
70
|
-
add_index(table, column) if column_exists?(table, column)
|
71
|
-
end
|
72
64
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class AddStockItemUniqueIndex < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
# Add a database-level uniqueness constraint for databases that support it
|
4
|
-
# (postgres
|
5
|
-
if connection.
|
4
|
+
# (postgres and sqlite > 3.8)
|
5
|
+
if connection.supports_partial_index?
|
6
6
|
add_index 'spree_stock_items', ['variant_id', 'stock_location_id'], where: 'deleted_at is null', unique: true
|
7
7
|
end
|
8
8
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module Core
|
3
|
+
module ClassConstantizer
|
4
|
+
class Set
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@collection = ::Set.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(klass)
|
12
|
+
@collection << klass.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def concat(klasses)
|
16
|
+
klasses.each do |klass|
|
17
|
+
self << klass
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
delegate :clear, :empty?, to: :@collection
|
22
|
+
|
23
|
+
def each
|
24
|
+
@collection.each do |klass|
|
25
|
+
yield klass.constantize
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/spree/core/engine.rb
CHANGED
@@ -17,102 +17,98 @@ module Spree
|
|
17
17
|
Spree::Config = app.config.spree.preferences # legacy access
|
18
18
|
end
|
19
19
|
|
20
|
-
initializer "spree.default_permissions" do |_app|
|
20
|
+
initializer "spree.default_permissions", before: :load_config_initializers do |_app|
|
21
21
|
Spree::RoleConfiguration.configure do |config|
|
22
22
|
config.assign_permissions :default, [Spree::PermissionSets::DefaultCustomer]
|
23
23
|
config.assign_permissions :admin, [Spree::PermissionSets::SuperUser]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
initializer "spree.register.calculators" do |app|
|
28
|
-
app.config.spree.calculators.shipping_methods = [
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
initializer "spree.register.calculators", before: :load_config_initializers do |app|
|
28
|
+
app.config.spree.calculators.shipping_methods = %w[
|
29
|
+
Spree::Calculator::Shipping::FlatPercentItemTotal
|
30
|
+
Spree::Calculator::Shipping::FlatRate
|
31
|
+
Spree::Calculator::Shipping::FlexiRate
|
32
|
+
Spree::Calculator::Shipping::PerItem
|
33
|
+
Spree::Calculator::Shipping::PriceSack
|
34
|
+
]
|
34
35
|
|
35
|
-
app.config.spree.calculators.tax_rates = [
|
36
|
-
|
36
|
+
app.config.spree.calculators.tax_rates = %w[
|
37
|
+
Spree::Calculator::DefaultTax
|
38
|
+
]
|
37
39
|
end
|
38
40
|
|
39
|
-
initializer "spree.register.stock_splitters" do |app|
|
40
|
-
app.config.spree.stock_splitters = [
|
41
|
-
Spree::Stock::Splitter::ShippingCategory
|
41
|
+
initializer "spree.register.stock_splitters", before: :load_config_initializers do |app|
|
42
|
+
app.config.spree.stock_splitters = %w[
|
43
|
+
Spree::Stock::Splitter::ShippingCategory
|
42
44
|
Spree::Stock::Splitter::Backordered
|
43
45
|
]
|
44
46
|
end
|
45
47
|
|
46
|
-
initializer "spree.register.payment_methods" do |app|
|
47
|
-
app.config.spree.payment_methods = [
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
initializer "spree.register.payment_methods", before: :load_config_initializers do |app|
|
49
|
+
app.config.spree.payment_methods = %w[
|
50
|
+
Spree::Gateway::Bogus
|
51
|
+
Spree::Gateway::BogusSimple
|
52
|
+
Spree::PaymentMethod::StoreCredit
|
53
|
+
Spree::PaymentMethod::Check
|
54
|
+
]
|
52
55
|
end
|
53
56
|
|
54
57
|
# We need to define promotions rules here so extensions and existing apps
|
55
58
|
# can add their custom classes on their initializer files
|
56
|
-
initializer 'spree.promo.environment' do |app|
|
57
|
-
app.config.spree.add_class('promotions')
|
59
|
+
initializer 'spree.promo.environment', before: :load_config_initializers do |app|
|
58
60
|
app.config.spree.promotions = Spree::Promo::Environment.new
|
59
61
|
app.config.spree.promotions.rules = []
|
60
62
|
end
|
61
63
|
|
62
|
-
initializer 'spree.promo.register.promotion.calculators' do |app|
|
63
|
-
app.config.spree.calculators.
|
64
|
-
|
65
|
-
Spree::Calculator::
|
66
|
-
Spree::Calculator::
|
67
|
-
Spree::Calculator::
|
68
|
-
Spree::Calculator::TieredPercent,
|
64
|
+
initializer 'spree.promo.register.promotion.calculators', before: :load_config_initializers do |app|
|
65
|
+
app.config.spree.calculators.promotion_actions_create_adjustments = %w[
|
66
|
+
Spree::Calculator::FlatPercentItemTotal
|
67
|
+
Spree::Calculator::FlatRate
|
68
|
+
Spree::Calculator::FlexiRate
|
69
|
+
Spree::Calculator::TieredPercent
|
69
70
|
Spree::Calculator::TieredFlatRate
|
70
71
|
]
|
71
72
|
|
72
|
-
app.config.spree.calculators.
|
73
|
-
|
74
|
-
Spree::Calculator::
|
75
|
-
Spree::Calculator::
|
76
|
-
Spree::Calculator::FlexiRate,
|
73
|
+
app.config.spree.calculators.promotion_actions_create_item_adjustments = %w[
|
74
|
+
Spree::Calculator::PercentOnLineItem
|
75
|
+
Spree::Calculator::FlatRate
|
76
|
+
Spree::Calculator::FlexiRate
|
77
77
|
Spree::Calculator::TieredPercent
|
78
78
|
]
|
79
79
|
|
80
|
-
app.config.spree.calculators.
|
81
|
-
|
82
|
-
Spree::Calculator::PercentOnLineItem,
|
80
|
+
app.config.spree.calculators.promotion_actions_create_quantity_adjustments = %w[
|
81
|
+
Spree::Calculator::PercentOnLineItem
|
83
82
|
Spree::Calculator::FlatRate
|
84
83
|
]
|
85
84
|
end
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
Spree::Promotion::Rules::
|
94
|
-
Spree::Promotion::Rules::
|
95
|
-
Spree::Promotion::Rules::
|
96
|
-
Spree::Promotion::Rules::
|
97
|
-
Spree::Promotion::Rules::
|
98
|
-
Spree::Promotion::Rules::OneUsePerUser,
|
99
|
-
Spree::Promotion::Rules::Taxon,
|
100
|
-
Spree::Promotion::Rules::NthOrder,
|
101
|
-
Spree::Promotion::Rules::OptionValue,
|
86
|
+
initializer 'spree.promo.register.promotion.rules', before: :load_config_initializers do |app|
|
87
|
+
app.config.spree.promotions.rules = %w[
|
88
|
+
Spree::Promotion::Rules::ItemTotal
|
89
|
+
Spree::Promotion::Rules::Product
|
90
|
+
Spree::Promotion::Rules::User
|
91
|
+
Spree::Promotion::Rules::FirstOrder
|
92
|
+
Spree::Promotion::Rules::UserLoggedIn
|
93
|
+
Spree::Promotion::Rules::OneUsePerUser
|
94
|
+
Spree::Promotion::Rules::Taxon
|
95
|
+
Spree::Promotion::Rules::NthOrder
|
96
|
+
Spree::Promotion::Rules::OptionValue
|
102
97
|
Spree::Promotion::Rules::FirstRepeatPurchaseSince
|
103
98
|
]
|
104
99
|
end
|
105
100
|
|
106
|
-
initializer 'spree.promo.register.promotions.actions' do |app|
|
107
|
-
app.config.spree.promotions.actions = [
|
108
|
-
Promotion::Actions::CreateAdjustment
|
109
|
-
Promotion::Actions::CreateItemAdjustments
|
110
|
-
Promotion::Actions::CreateQuantityAdjustments
|
111
|
-
Promotion::Actions::FreeShipping
|
101
|
+
initializer 'spree.promo.register.promotions.actions', before: :load_config_initializers do |app|
|
102
|
+
app.config.spree.promotions.actions = %w[
|
103
|
+
Spree::Promotion::Actions::CreateAdjustment
|
104
|
+
Spree::Promotion::Actions::CreateItemAdjustments
|
105
|
+
Spree::Promotion::Actions::CreateQuantityAdjustments
|
106
|
+
Spree::Promotion::Actions::FreeShipping
|
107
|
+
]
|
112
108
|
end
|
113
109
|
|
114
110
|
# filter sensitive information during logging
|
115
|
-
initializer "spree.params.filter" do |app|
|
111
|
+
initializer "spree.params.filter", before: :load_config_initializers do |app|
|
116
112
|
app.config.filter_parameters += [
|
117
113
|
:password,
|
118
114
|
:password_confirmation,
|
@@ -120,7 +116,7 @@ module Spree
|
|
120
116
|
:verification_value]
|
121
117
|
end
|
122
118
|
|
123
|
-
initializer "spree.core.checking_migrations" do |_app|
|
119
|
+
initializer "spree.core.checking_migrations", before: :load_config_initializers do |_app|
|
124
120
|
Migrations.new(config, engine_name).check
|
125
121
|
end
|
126
122
|
end
|
@@ -4,7 +4,12 @@ module Spree
|
|
4
4
|
class Calculators
|
5
5
|
include EnvironmentExtension
|
6
6
|
|
7
|
-
|
7
|
+
add_class_set :shipping_methods
|
8
|
+
add_class_set :tax_rates
|
9
|
+
|
10
|
+
add_class_set :promotion_actions_create_adjustments
|
11
|
+
add_class_set :promotion_actions_create_item_adjustments
|
12
|
+
add_class_set :promotion_actions_create_quantity_adjustments
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
@@ -3,12 +3,15 @@ module Spree
|
|
3
3
|
class Environment
|
4
4
|
include EnvironmentExtension
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
add_class_set :payment_methods
|
7
|
+
add_class_set :stock_splitters
|
8
|
+
|
9
|
+
attr_accessor :calculators, :preferences, :promotions
|
8
10
|
|
9
11
|
def initialize
|
10
12
|
@calculators = Calculators.new
|
11
13
|
@preferences = Spree::AppConfiguration.new
|
14
|
+
@promotions = Spree::Promo::Environment.new
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
@@ -1,24 +1,28 @@
|
|
1
|
+
require 'spree/core/class_constantizer'
|
2
|
+
|
1
3
|
module Spree
|
2
4
|
module Core
|
3
5
|
module EnvironmentExtension
|
4
6
|
extend ActiveSupport::Concern
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
class_methods do
|
9
|
+
def add_class_set(name)
|
10
|
+
define_method(name) do
|
11
|
+
set = instance_variable_get("@#{name}")
|
12
|
+
set = send("#{name}=", []) unless set
|
13
|
+
set
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
define_method("#{name}=") do |klasses|
|
17
|
+
set = ClassConstantizer::Set.new
|
18
|
+
set.concat(klasses)
|
19
|
+
instance_variable_set("@#{name}", set)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
def create_method(name, &block)
|
21
|
-
self.class.send(:define_method, name, &block)
|
24
|
+
def add_class(name)
|
25
|
+
singleton_class.send(:add_class_set, name)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Spree
|
2
|
+
# This class performs a data migration. It's usually run from
|
3
|
+
# the `solidus:migrations:create_vat_prices` rake task.
|
4
|
+
class PriceMigrator
|
5
|
+
# Migrate all variant's prices.
|
6
|
+
def self.migrate_default_vat_prices
|
7
|
+
# We need to tag the exisiting prices as "default", so that the VatPriceGenerator knows
|
8
|
+
# that they include the default zone's VAT.
|
9
|
+
Spree::Config.admin_vat_country_iso = Spree::Zone.default_tax.countries.first.iso
|
10
|
+
# If we don't remove this ivar, the above line stays without effect because of caching.
|
11
|
+
Spree::Config.remove_instance_variable(:@default_pricing_options)
|
12
|
+
Spree::Variant.find_each do |variant|
|
13
|
+
new(variant).migrate_vat_prices
|
14
|
+
end
|
15
|
+
# This line stops all weird code paths that generate refunds from happening.
|
16
|
+
Spree::Zone.default_tax.update(default_tax: false)
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :variant
|
20
|
+
|
21
|
+
def initialize(variant)
|
22
|
+
@variant = variant
|
23
|
+
end
|
24
|
+
|
25
|
+
def migrate_vat_prices
|
26
|
+
# With a default tax zone, all prices include VAT by default. Let's tell them which one!
|
27
|
+
variant.prices.update_all(country_iso: Spree::Config.admin_vat_country_iso)
|
28
|
+
Spree::Variant::VatPriceGenerator.new(variant).run
|
29
|
+
variant.save
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -30,7 +30,7 @@ module Spree
|
|
30
30
|
curr_page = page || 1
|
31
31
|
|
32
32
|
unless Spree::Config.show_products_without_price
|
33
|
-
@products = @products.joins(:prices).merge(Spree::Price.where(pricing_options.
|
33
|
+
@products = @products.joins(:prices).merge(Spree::Price.where(pricing_options.search_arguments)).uniq
|
34
34
|
end
|
35
35
|
@products = @products.page(curr_page).per(per_page)
|
36
36
|
end
|
@@ -70,7 +70,7 @@ module Spree
|
|
70
70
|
# separate queries most of the time but opt for a join as soon as any
|
71
71
|
# `where` constraints affecting joined tables are added to the search;
|
72
72
|
# which is the case as soon as a taxon is added to the base scope.
|
73
|
-
scope = scope.preload(master: :
|
73
|
+
scope = scope.preload(master: :currently_valid_prices)
|
74
74
|
scope = scope.preload(master: :images) if include_images
|
75
75
|
scope
|
76
76
|
end
|
data/lib/spree/core/version.rb
CHANGED
data/lib/spree/core.rb
CHANGED
@@ -63,11 +63,13 @@ end
|
|
63
63
|
|
64
64
|
require 'spree/core/version'
|
65
65
|
|
66
|
+
require 'spree/core/class_constantizer'
|
66
67
|
require 'spree/core/environment_extension'
|
67
68
|
require 'spree/core/environment/calculators'
|
68
69
|
require 'spree/core/environment'
|
69
70
|
require 'spree/promo/environment'
|
70
71
|
require 'spree/migrations'
|
72
|
+
require 'spree/migration_helpers'
|
71
73
|
require 'spree/core/engine'
|
72
74
|
|
73
75
|
require 'spree/i18n'
|
@@ -97,3 +99,5 @@ require 'spree/deprecation'
|
|
97
99
|
|
98
100
|
require 'spree/mailer_previews/order_preview'
|
99
101
|
require 'spree/mailer_previews/carton_preview'
|
102
|
+
|
103
|
+
require 'spree/core/price_migrator'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Spree
|
2
|
+
module MigrationHelpers
|
3
|
+
def safe_remove_index(table, column)
|
4
|
+
remove_index(table, column) if index_exists?(table, column)
|
5
|
+
end
|
6
|
+
|
7
|
+
def safe_add_index(table, column, options = {})
|
8
|
+
if columns_exist?(table, column) && !index_exists?(table, column, options)
|
9
|
+
add_index(table, column, options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def columns_exist?(table, columns)
|
16
|
+
Array.wrap(columns).all? { |column| column_exists?(table, column) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/spree/money.rb
CHANGED
@@ -6,11 +6,18 @@ module Spree
|
|
6
6
|
# Spree::Money is a relatively thin wrapper around Monetize which handles
|
7
7
|
# formatting via Spree::Config.
|
8
8
|
class Money
|
9
|
+
RUBY_NUMERIC_STRING = /\A-?\d+(\.\d+)?\z/
|
10
|
+
|
9
11
|
class <<self
|
10
12
|
attr_accessor :default_formatting_rules
|
11
13
|
|
12
|
-
def
|
13
|
-
new(
|
14
|
+
def parse(amount, currency = Spree::Config[:currency])
|
15
|
+
new(parse_to_money(amount, currency))
|
16
|
+
end
|
17
|
+
|
18
|
+
# @api private
|
19
|
+
def parse_to_money(amount, currency)
|
20
|
+
::Monetize.parse(amount, currency)
|
14
21
|
end
|
15
22
|
end
|
16
23
|
self.default_formatting_rules = {
|
@@ -23,9 +30,33 @@ module Spree
|
|
23
30
|
|
24
31
|
delegate :cents, :currency, :to_d, :zero?, to: :money
|
25
32
|
|
26
|
-
# @param amount [#to_s] the value of the money object
|
27
|
-
# @param options [Hash] the options for
|
28
|
-
|
33
|
+
# @param amount [Money, #to_s] the value of the money object
|
34
|
+
# @param options [Hash] the default options for formatting the money object See #format
|
35
|
+
def initialize(amount, options = {})
|
36
|
+
if amount.is_a?(::Money)
|
37
|
+
@money = amount
|
38
|
+
else
|
39
|
+
currency = (options[:currency] || Spree::Config[:currency])
|
40
|
+
if amount.to_s =~ RUBY_NUMERIC_STRING
|
41
|
+
@money = Monetize.from_string(amount, currency)
|
42
|
+
else
|
43
|
+
@money = Spree::Money.parse_to_money(amount, currency)
|
44
|
+
Spree::Deprecation.warn <<-WARN.squish, caller
|
45
|
+
Spree::Money was initialized with #{amount.inspect}, which will not be supported in the future.
|
46
|
+
Instead use Spree::Money.new(#{@money.to_s.inspect}, options) or Spree::Money.parse(#{amount.inspect})
|
47
|
+
WARN
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@options = Spree::Money.default_formatting_rules.merge(options)
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [String] the value of this money object formatted according to
|
54
|
+
# its options
|
55
|
+
def to_s
|
56
|
+
format
|
57
|
+
end
|
58
|
+
|
59
|
+
# @param options [Hash, String] the options for formatting the money object
|
29
60
|
# @option options [Boolean] with_currency when true, show the currency
|
30
61
|
# @option options [Boolean] no_cents when true, round to the closest dollar
|
31
62
|
# @option options [String] decimal_mark the mark for delimiting the
|
@@ -36,15 +67,10 @@ module Spree
|
|
36
67
|
# value comes before the currency symbol
|
37
68
|
# @option options [:before, :after] symbol_position the position of the
|
38
69
|
# currency symbol
|
39
|
-
def initialize(amount, options = {})
|
40
|
-
@money = Monetize.parse([amount, (options[:currency] || Spree::Config[:currency])].join)
|
41
|
-
@options = Spree::Money.default_formatting_rules.merge(options)
|
42
|
-
end
|
43
|
-
|
44
70
|
# @return [String] the value of this money object formatted according to
|
45
71
|
# its options
|
46
|
-
def
|
47
|
-
@money.format(@options)
|
72
|
+
def format(options = {})
|
73
|
+
@money.format(@options.merge(options))
|
48
74
|
end
|
49
75
|
|
50
76
|
# @note If you pass in options, ensure you pass in the html: true as well.
|
@@ -52,7 +78,7 @@ module Spree
|
|
52
78
|
# @return [String] the value of this money object formatted according to
|
53
79
|
# its options and any additional options, by default as html.
|
54
80
|
def to_html(options = { html: true })
|
55
|
-
output =
|
81
|
+
output = format(options)
|
56
82
|
if options[:html]
|
57
83
|
# 1) prevent blank, breaking spaces
|
58
84
|
# 2) prevent escaping of HTML character entities
|
@@ -76,12 +102,12 @@ module Spree
|
|
76
102
|
|
77
103
|
def -(other)
|
78
104
|
raise TypeError, "Can't subtract #{other.class} to Spree::Money" if !other.respond_to?(:money)
|
79
|
-
self.class.
|
105
|
+
self.class.new(@money - other.money)
|
80
106
|
end
|
81
107
|
|
82
108
|
def +(other)
|
83
109
|
raise TypeError, "Can't add #{other.class} to Spree::Money" if !other.respond_to?(:money)
|
84
|
-
self.class.
|
110
|
+
self.class.new(@money + other.money)
|
85
111
|
end
|
86
112
|
end
|
87
113
|
end
|