solidus_core 2.1.0.beta1 → 2.1.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/app/mailers/spree/base_mailer.rb +2 -7
- data/app/mailers/spree/carton_mailer.rb +3 -11
- data/app/mailers/spree/order_mailer.rb +3 -12
- data/app/models/concerns/spree/default_price.rb +2 -3
- data/app/models/concerns/spree/user_methods.rb +1 -1
- data/app/models/concerns/spree/user_payment_source.rb +0 -6
- data/app/models/spree/address.rb +0 -9
- data/app/models/spree/adjustment.rb +2 -63
- data/app/models/spree/app_configuration.rb +0 -22
- data/app/models/spree/calculator/flexi_rate.rb +7 -12
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +1 -1
- data/app/models/spree/calculator/tiered_flat_rate.rb +3 -1
- data/app/models/spree/calculator/tiered_percent.rb +3 -1
- data/app/models/spree/country.rb +0 -7
- data/app/models/spree/gateway.rb +0 -9
- data/app/models/spree/order.rb +1 -15
- data/app/models/spree/order/checkout.rb +0 -41
- data/app/models/spree/payment.rb +0 -22
- data/app/models/spree/payment/processing.rb +1 -1
- data/app/models/spree/product/scopes.rb +1 -8
- data/app/models/spree/promotion/actions/create_adjustment.rb +6 -1
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +6 -1
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +6 -1
- data/app/models/spree/refund.rb +1 -1
- data/app/models/spree/store.rb +1 -2
- data/app/models/spree/zone.rb +12 -10
- data/lib/spree/core.rb +0 -10
- data/lib/spree/core/engine.rb +0 -2
- data/lib/spree/core/version.rb +1 -6
- data/spec/mailers/carton_mailer_spec.rb +0 -9
- data/spec/mailers/order_mailer_spec.rb +0 -14
- data/spec/models/spree/calculator/flexi_rate_spec.rb +132 -20
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +4 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +41 -1
- data/spec/models/spree/calculator/tiered_percent_spec.rb +45 -1
- data/spec/models/spree/gateway/bogus_spec.rb +0 -7
- data/spec/models/spree/order/checkout_spec.rb +0 -119
- data/spec/models/spree/order/payment_spec.rb +19 -10
- data/spec/models/spree/order_spec.rb +0 -45
- data/spec/models/spree/payment_spec.rb +56 -63
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +2 -2
- data/spec/models/spree/store_spec.rb +0 -8
- data/spec/models/spree/user_spec.rb +0 -7
- data/spec/models/spree/variant_spec.rb +0 -8
- metadata +2 -4
- data/config/initializers/spree_user.rb +0 -10
- data/lib/spree/core/routes.rb +0 -20
data/app/models/spree/payment.rb
CHANGED
@@ -36,9 +36,6 @@ module Spree
|
|
36
36
|
# invalidate previously entered payments
|
37
37
|
after_create :invalidate_old_payments
|
38
38
|
|
39
|
-
attr_accessor :source_attributes
|
40
|
-
after_initialize :apply_source_attributes
|
41
|
-
|
42
39
|
attr_accessor :request_env
|
43
40
|
|
44
41
|
validates :amount, numericality: true
|
@@ -149,25 +146,6 @@ module Spree
|
|
149
146
|
credit_allowed > 0
|
150
147
|
end
|
151
148
|
|
152
|
-
# When this is a new record without a source, builds a new source based on
|
153
|
-
# this payment's payment method and associates it correctly.
|
154
|
-
#
|
155
|
-
# @see https://github.com/spree/spree/issues/981
|
156
|
-
#
|
157
|
-
# TODO: Move this into upcoming CartUpdate class
|
158
|
-
def apply_source_attributes
|
159
|
-
return unless new_record?
|
160
|
-
return if source_attributes.blank?
|
161
|
-
|
162
|
-
Spree::Deprecation.warn(<<WARN.squish)
|
163
|
-
Building payment sources by assigning source_attributes on payments is
|
164
|
-
deprecated. Instead use either the PaymentCreate class or the
|
165
|
-
OrderUpdateAttributes class.
|
166
|
-
WARN
|
167
|
-
|
168
|
-
PaymentCreate.new(order, { source_attributes: source_attributes }, payment: self, request_env: request_env).build
|
169
|
-
end
|
170
|
-
|
171
149
|
# @return [Array<String>] the actions available on this payment
|
172
150
|
def actions
|
173
151
|
sa = source_actions
|
@@ -56,7 +56,7 @@ module Spree
|
|
56
56
|
gateway_options
|
57
57
|
)
|
58
58
|
money = ::Money.new(amount, currency)
|
59
|
-
capture_events.create!(amount: money.
|
59
|
+
capture_events.create!(amount: money.to_d)
|
60
60
|
update_attributes!(amount: captured_amount)
|
61
61
|
handle_response(response, :complete, :failure)
|
62
62
|
end
|
@@ -172,18 +172,11 @@ module Spree
|
|
172
172
|
end
|
173
173
|
|
174
174
|
# Can't use add_search_scope for this as it needs a default argument
|
175
|
-
def self.available(available_on = nil
|
176
|
-
Spree::Deprecation.warn("The second currency argument on Product.available has no effect, and is deprecated", caller) if currency
|
175
|
+
def self.available(available_on = nil)
|
177
176
|
joins(master: :prices).where("#{Product.quoted_table_name}.available_on <= ?", available_on || Time.current)
|
178
177
|
end
|
179
178
|
search_scopes << :available
|
180
179
|
|
181
|
-
def self.active(currency = nil)
|
182
|
-
Spree::Deprecation.warn("This scope is deprecated, please use .available instead", caller)
|
183
|
-
not_deleted.available(nil, currency)
|
184
|
-
end
|
185
|
-
search_scopes << :active
|
186
|
-
|
187
180
|
add_search_scope :taxons_name_eq do |name|
|
188
181
|
group("spree_products.id").joins(:taxons).where(Taxon.arel_table[:name].eq(name))
|
189
182
|
end
|
@@ -35,7 +35,12 @@ module Spree
|
|
35
35
|
# Ensure a negative amount which does not exceed the sum of the order's
|
36
36
|
# item_total and ship_total
|
37
37
|
def compute_amount(calculable)
|
38
|
-
amount = calculator.compute(calculable)
|
38
|
+
amount = calculator.compute(calculable)
|
39
|
+
if !amount.is_a?(BigDecimal)
|
40
|
+
Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{amount.inspect}, it should return a BigDecimal"
|
41
|
+
end
|
42
|
+
amount ||= BigDecimal.new(0)
|
43
|
+
amount = amount.abs
|
39
44
|
[(calculable.item_total + calculable.ship_total), amount].min * -1
|
40
45
|
end
|
41
46
|
|
@@ -31,7 +31,12 @@ module Spree
|
|
31
31
|
def compute_amount(adjustable)
|
32
32
|
order = adjustable.is_a?(Order) ? adjustable : adjustable.order
|
33
33
|
return 0 unless promotion.line_item_actionable?(order, adjustable)
|
34
|
-
promotion_amount = calculator.compute(adjustable)
|
34
|
+
promotion_amount = calculator.compute(adjustable)
|
35
|
+
if !promotion_amount.is_a?(BigDecimal)
|
36
|
+
Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{promotion_amount.inspect}, it should return a BigDecimal"
|
37
|
+
end
|
38
|
+
promotion_amount ||= BigDecimal.new(0)
|
39
|
+
promotion_amount = promotion_amount.abs
|
35
40
|
[adjustable.amount, promotion_amount].min * -1
|
36
41
|
end
|
37
42
|
|
@@ -52,7 +52,12 @@ module Spree::Promotion::Actions
|
|
52
52
|
# adjustment. +adjustment_amount * 3+ or $15.
|
53
53
|
#
|
54
54
|
def compute_amount(line_item)
|
55
|
-
adjustment_amount = calculator.compute(PartialLineItem.new(line_item))
|
55
|
+
adjustment_amount = calculator.compute(PartialLineItem.new(line_item))
|
56
|
+
if !adjustment_amount.is_a?(BigDecimal)
|
57
|
+
Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{adjustment_amount.inspect}, it should return a BigDecimal"
|
58
|
+
end
|
59
|
+
adjustment_amount ||= BigDecimal.new(0)
|
60
|
+
adjustment_amount = adjustment_amount.abs
|
56
61
|
|
57
62
|
order = line_item.order
|
58
63
|
line_items = actionable_line_items(order)
|
data/app/models/spree/refund.rb
CHANGED
data/app/models/spree/store.rb
CHANGED
@@ -21,8 +21,7 @@ module Spree
|
|
21
21
|
|
22
22
|
scope :by_url, lambda { |url| where("url like ?", "%#{url}%") }
|
23
23
|
|
24
|
-
def self.current(store_key
|
25
|
-
Spree::Deprecation.warn "Spree::Store.current needs a code or URL as an argument. If you want the default store use Spree::Store.default", caller if !store_key
|
24
|
+
def self.current(store_key)
|
26
25
|
current_store = Store.find_by(code: store_key) || Store.by_url(store_key).first if store_key
|
27
26
|
current_store || Store.default
|
28
27
|
end
|
data/app/models/spree/zone.rb
CHANGED
@@ -16,16 +16,18 @@ module Spree
|
|
16
16
|
after_save :remove_previous_default
|
17
17
|
|
18
18
|
scope :with_member_ids, ->(state_ids, country_ids) do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
if !state_ids.present? && !country_ids.present?
|
20
|
+
none
|
21
|
+
else
|
22
|
+
spree_zone_members_table = Spree::ZoneMember.arel_table
|
23
|
+
matching_state =
|
24
|
+
spree_zone_members_table[:zoneable_type].eq("Spree::State").
|
25
|
+
and(spree_zone_members_table[:zoneable_id].in(state_ids))
|
26
|
+
matching_country =
|
27
|
+
spree_zone_members_table[:zoneable_type].eq("Spree::Country").
|
28
|
+
and(spree_zone_members_table[:zoneable_id].in(country_ids))
|
29
|
+
joins(:zone_members).where(matching_state.or(matching_country)).distinct
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
33
|
scope :for_address, ->(address) do
|
data/lib/spree/core.rb
CHANGED
@@ -46,16 +46,6 @@ module Spree
|
|
46
46
|
module Core
|
47
47
|
autoload :ProductFilters, "spree/core/product_filters"
|
48
48
|
|
49
|
-
def self.const_missing(name)
|
50
|
-
case name
|
51
|
-
when :AdjustmentSource, :CalculatedAdjustments, :UserAddress, :UserPaymentSource
|
52
|
-
Spree::Deprecation.warn("Spree::Core::#{name} is deprecated! Use Spree::#{name} instead.", caller)
|
53
|
-
Spree.const_get(name)
|
54
|
-
else
|
55
|
-
super
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
49
|
class GatewayError < RuntimeError; end
|
60
50
|
class DestroyWithOrdersError < StandardError; end
|
61
51
|
end
|
data/lib/spree/core/engine.rb
CHANGED
data/lib/spree/core/version.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
module Spree
|
2
|
-
def self.version
|
3
|
-
Spree::Deprecation.warn("Spree.version does not work and will be removed from solidus. Use Spree.solidus_version instead to determine the solidus version")
|
4
|
-
"2.4.6.beta"
|
5
|
-
end
|
6
|
-
|
7
2
|
def self.solidus_version
|
8
|
-
"2.1.0.
|
3
|
+
"2.1.0.rc1"
|
9
4
|
end
|
10
5
|
|
11
6
|
def self.solidus_gem_version
|
@@ -16,15 +16,6 @@ describe Spree::CartonMailer do
|
|
16
16
|
expect(shipment_email.subject).to eq "#{order.store.name} Shipment Notification ##{order.number}"
|
17
17
|
end
|
18
18
|
|
19
|
-
context "deprecated signature" do
|
20
|
-
it do
|
21
|
-
Spree::Deprecation.silence do
|
22
|
-
mail = Spree::CartonMailer.shipped_email(carton.id)
|
23
|
-
expect(mail.subject).to include "Shipment Notification"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
19
|
context "with resend option" do
|
29
20
|
subject do
|
30
21
|
Spree::CartonMailer.shipped_email(order: order, carton: carton, resend: true).subject
|
@@ -28,20 +28,6 @@ describe Spree::OrderMailer, type: :mailer do
|
|
28
28
|
expect(confirmation_email.body).not_to include(""")
|
29
29
|
end
|
30
30
|
|
31
|
-
it "confirm_email accepts an order id as an alternative to an Order object" do
|
32
|
-
expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
|
33
|
-
Spree::Deprecation.silence do
|
34
|
-
Spree::OrderMailer.confirm_email(order.id).body
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "cancel_email accepts an order id as an alternative to an Order object" do
|
39
|
-
expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
|
40
|
-
Spree::Deprecation.silence do
|
41
|
-
Spree::OrderMailer.cancel_email(order.id).body
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
31
|
context "only shows eligible adjustments in emails" do
|
46
32
|
before do
|
47
33
|
create(
|
@@ -2,43 +2,155 @@ require 'spec_helper'
|
|
2
2
|
require 'shared_examples/calculator_shared_examples'
|
3
3
|
|
4
4
|
describe Spree::Calculator::FlexiRate, type: :model do
|
5
|
-
let(:calculator)
|
5
|
+
let(:calculator) do
|
6
|
+
Spree::Calculator::FlexiRate.new(
|
7
|
+
preferred_first_item: first_item,
|
8
|
+
preferred_additional_item: additional_item,
|
9
|
+
preferred_max_items: max_items
|
10
|
+
)
|
11
|
+
end
|
12
|
+
let(:first_item) { 0 }
|
13
|
+
let(:additional_item) { 0 }
|
14
|
+
let(:max_items) { 0 }
|
6
15
|
|
7
16
|
it_behaves_like 'a calculator with a description'
|
8
17
|
|
9
18
|
let(:order) do
|
10
19
|
mock_model(
|
11
|
-
Spree::Order, quantity:
|
20
|
+
Spree::Order, quantity: quantity
|
12
21
|
)
|
13
22
|
end
|
14
23
|
|
15
24
|
context "compute" do
|
16
|
-
|
17
|
-
|
18
|
-
|
25
|
+
subject { calculator.compute(order) }
|
26
|
+
context "with all amounts 0" do
|
27
|
+
context "with quantity 0" do
|
28
|
+
let(:quantity) { 0 }
|
29
|
+
it { should eq 0 }
|
30
|
+
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
context "with quantity 1" do
|
33
|
+
let(:quantity) { 1 }
|
34
|
+
it { should eq 0 }
|
35
|
+
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
|
37
|
+
context "with quantity 2" do
|
38
|
+
let(:quantity) { 2 }
|
39
|
+
it { should eq 0 }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with quantity 10" do
|
43
|
+
let(:quantity) { 10 }
|
44
|
+
it { should eq 0 }
|
45
|
+
end
|
28
46
|
end
|
29
47
|
|
30
|
-
|
31
|
-
|
32
|
-
|
48
|
+
context "when first_item has a value" do
|
49
|
+
let(:first_item) { 1.23 }
|
50
|
+
|
51
|
+
context "with quantity 0" do
|
52
|
+
let(:quantity) { 0 }
|
53
|
+
it { should eq 0 }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with quantity 1" do
|
57
|
+
let(:quantity) { 1 }
|
58
|
+
it { should eq 1.23 }
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with quantity 2" do
|
62
|
+
let(:quantity) { 2 }
|
63
|
+
it { should eq 1.23 }
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with quantity 10" do
|
67
|
+
let(:quantity) { 10 }
|
68
|
+
it { should eq 1.23 }
|
69
|
+
end
|
33
70
|
end
|
34
71
|
|
35
|
-
|
36
|
-
|
37
|
-
|
72
|
+
context "when additional_items has a value" do
|
73
|
+
let(:additional_item) { 1.23 }
|
74
|
+
|
75
|
+
context "with quantity 0" do
|
76
|
+
let(:quantity) { 0 }
|
77
|
+
it { should eq 0 }
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with quantity 1" do
|
81
|
+
let(:quantity) { 1 }
|
82
|
+
it { should eq 0 }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with quantity 2" do
|
86
|
+
let(:quantity) { 2 }
|
87
|
+
it { should eq 1.23 }
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with quantity 10" do
|
91
|
+
let(:quantity) { 10 }
|
92
|
+
it { should eq 11.07 }
|
93
|
+
end
|
38
94
|
end
|
39
95
|
|
40
|
-
|
41
|
-
|
96
|
+
context "when first_item and additional_items has a value" do
|
97
|
+
let(:first_item) { 1.13 }
|
98
|
+
let(:additional_item) { 2.11 }
|
99
|
+
|
100
|
+
context "with quantity 0" do
|
101
|
+
let(:quantity) { 0 }
|
102
|
+
it { should eq 0 }
|
103
|
+
end
|
104
|
+
|
105
|
+
context "with quantity 1" do
|
106
|
+
let(:quantity) { 1 }
|
107
|
+
it { should eq 1.13 }
|
108
|
+
end
|
109
|
+
|
110
|
+
context "with quantity 2" do
|
111
|
+
let(:quantity) { 2 }
|
112
|
+
it { should eq 3.24 }
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with quantity 10" do
|
116
|
+
let(:quantity) { 10 }
|
117
|
+
it { should eq 20.12 }
|
118
|
+
end
|
119
|
+
|
120
|
+
context "with max_items 5" do
|
121
|
+
let(:max_items) { 5 }
|
122
|
+
|
123
|
+
context "with quantity 0" do
|
124
|
+
let(:quantity) { 0 }
|
125
|
+
it { should eq 0 }
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with quantity 1" do
|
129
|
+
let(:quantity) { 1 }
|
130
|
+
it { should eq 1.13 }
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with quantity 2" do
|
134
|
+
let(:quantity) { 2 }
|
135
|
+
it { should eq 3.24 }
|
136
|
+
end
|
137
|
+
|
138
|
+
context "with quantity 5" do
|
139
|
+
let(:quantity) { 5 }
|
140
|
+
it { should eq 9.57 }
|
141
|
+
end
|
142
|
+
|
143
|
+
context "with quantity 10" do
|
144
|
+
let(:quantity) { 10 }
|
145
|
+
it { should eq 9.57 }
|
146
|
+
end
|
147
|
+
end
|
42
148
|
end
|
43
149
|
end
|
150
|
+
|
151
|
+
it "should allow creation of new object with all the attributes" do
|
152
|
+
attributes = {preferred_first_item: 1, preferred_additional_item: 1, preferred_max_items: 1}
|
153
|
+
calculator = Spree::Calculator::FlexiRate.new(attributes)
|
154
|
+
expect(calculator).to have_attributes(attributes)
|
155
|
+
end
|
44
156
|
end
|
@@ -9,10 +9,50 @@ describe Spree::Calculator::TieredFlatRate, type: :model do
|
|
9
9
|
describe "#valid?" do
|
10
10
|
subject { calculator.valid? }
|
11
11
|
context "when tiers is a hash" do
|
12
|
-
context "and
|
12
|
+
context "and the key is not a positive number" do
|
13
13
|
before { calculator.preferred_tiers = { "nope" => 20 } }
|
14
14
|
it { is_expected.to be false }
|
15
15
|
end
|
16
|
+
|
17
|
+
context "and the key is an integer" do
|
18
|
+
before { calculator.preferred_tiers = { 20 => 20 } }
|
19
|
+
it "converts successfully" do
|
20
|
+
is_expected.to be true
|
21
|
+
expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20') => BigDecimal.new('20') })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "and the key is a float" do
|
26
|
+
before { calculator.preferred_tiers = { 20.5 => 20.5 } }
|
27
|
+
it "converts successfully" do
|
28
|
+
is_expected.to be true
|
29
|
+
expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20.5') => BigDecimal.new('20.5') })
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "and the key is a string number" do
|
34
|
+
before { calculator.preferred_tiers = { "20" => 20 } }
|
35
|
+
it "converts successfully" do
|
36
|
+
is_expected.to be true
|
37
|
+
expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20') => BigDecimal.new('20') })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "and the key is a numeric string with spaces" do
|
42
|
+
before { calculator.preferred_tiers = { " 20 " => 20 } }
|
43
|
+
it "converts successfully" do
|
44
|
+
is_expected.to be true
|
45
|
+
expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20') => BigDecimal.new('20') })
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "and the key is a string number with decimals" do
|
50
|
+
before { calculator.preferred_tiers = { "20.5" => "20.5" } }
|
51
|
+
it "converts successfully" do
|
52
|
+
is_expected.to be true
|
53
|
+
expect(calculator.preferred_tiers).to eq({ BigDecimal.new('20.5') => BigDecimal.new('20.5') })
|
54
|
+
end
|
55
|
+
end
|
16
56
|
end
|
17
57
|
end
|
18
58
|
|