spree_core 2.3.10 → 2.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/spree/adjustment.rb +1 -1
- data/app/models/spree/order.rb +9 -3
- data/app/models/spree/order_updater.rb +0 -5
- data/app/models/spree/payment.rb +5 -0
- data/app/models/spree/promotion_handler/cart.rb +18 -14
- data/app/models/spree/stock/availability_validator.rb +10 -6
- data/app/models/spree/stock_item.rb +5 -1
- data/app/models/spree/stock_movement.rb +6 -1
- data/app/models/spree/tax_rate.rb +5 -1
- data/config/initializers/user_class_extensions.rb +4 -0
- data/db/migrate/20150515211137_fix_adjustment_order_id.rb +70 -0
- data/lib/spree/core/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 220579fa75f0cf4f04ad3c1688427f6ac85bd9f7
|
4
|
+
data.tar.gz: 4b695dfd6914c69725d8efab2b49b053ea1498ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4753626212fc08dfd1a242773210b59e38f9da5a927da31344da74a14b24fe9a676bfacb182f1d576fc71109d9c524b970b7f458402393bb9cd5570ea07f7b46
|
7
|
+
data.tar.gz: 67a816dbd5d27061e1918cdcf0cd431c63b843ff944ad01d567751d9790f5d113f84b47528be164480045760d17964d4aae3583d831d66460f6927ec9fe82c8a
|
@@ -24,7 +24,7 @@ module Spree
|
|
24
24
|
class Adjustment < Spree::Base
|
25
25
|
belongs_to :adjustable, polymorphic: true, touch: true
|
26
26
|
belongs_to :source, polymorphic: true
|
27
|
-
belongs_to :order, class_name:
|
27
|
+
belongs_to :order, class_name: 'Spree::Order', inverse_of: :all_adjustments
|
28
28
|
|
29
29
|
validates :adjustable, presence: true
|
30
30
|
validates :order, presence: true
|
data/app/models/spree/order.rb
CHANGED
@@ -46,6 +46,11 @@ module Spree
|
|
46
46
|
has_many :inventory_units, inverse_of: :order
|
47
47
|
has_many :products, through: :variants
|
48
48
|
has_many :variants, through: :line_items
|
49
|
+
has_many :all_adjustments,
|
50
|
+
class_name: 'Spree::Adjustment',
|
51
|
+
foreign_key: :order_id,
|
52
|
+
dependent: :destroy,
|
53
|
+
inverse_of: :order
|
49
54
|
|
50
55
|
has_and_belongs_to_many :promotions, join_table: 'spree_orders_promotions'
|
51
56
|
|
@@ -115,9 +120,10 @@ module Spree
|
|
115
120
|
self.update_hooks.add(hook)
|
116
121
|
end
|
117
122
|
|
118
|
-
|
119
|
-
|
120
|
-
|
123
|
+
# Use this method in other gems that wish to register their own custom logic
|
124
|
+
# that should be called when determining if two line items are equal.
|
125
|
+
def self.register_line_item_comparison_hook(hook)
|
126
|
+
self.line_item_comparison_hooks.add(hook)
|
121
127
|
end
|
122
128
|
|
123
129
|
# For compatiblity with Calculator::PriceSack
|
data/app/models/spree/payment.rb
CHANGED
@@ -16,6 +16,7 @@ module Spree
|
|
16
16
|
has_many :state_changes, as: :stateful
|
17
17
|
has_many :capture_events, :class_name => 'Spree::PaymentCaptureEvent'
|
18
18
|
|
19
|
+
validates_presence_of :payment_method
|
19
20
|
before_validation :validate_source
|
20
21
|
before_create :set_unique_identifier
|
21
22
|
|
@@ -157,6 +158,10 @@ module Spree
|
|
157
158
|
amount - capture_events.sum(:amount)
|
158
159
|
end
|
159
160
|
|
161
|
+
def editable?
|
162
|
+
checkout? || pending?
|
163
|
+
end
|
164
|
+
|
160
165
|
private
|
161
166
|
|
162
167
|
def validate_source
|
@@ -29,22 +29,26 @@ module Spree
|
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
|
-
def promotions
|
33
|
-
promo_table = Promotion.arel_table
|
34
|
-
join_table = Arel::Table.new(:spree_orders_promotions)
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
def promotions
|
34
|
+
# AR cannot bind raw ASTs to prepared statements. There always must be a manager around.
|
35
|
+
# Also Postgresql requires an aliased table for `SELECT * FROM (subexpression) AS alias`.
|
36
|
+
# And Sqlite3 cannot work on outher parenthesis from `(left UNION right)`.
|
37
|
+
# So this construct makes both happy.
|
38
|
+
select = Arel::SelectManager.new(
|
39
|
+
Promotion,
|
40
|
+
Promotion.arel_table.create_table_alias(
|
41
|
+
order.promotions.active.union(Promotion.active.where(code: nil, path: nil)),
|
42
|
+
Promotion.table_name
|
43
|
+
),
|
44
|
+
)
|
45
|
+
select.project(Arel.star)
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
).or(join_table[:order_id].eq(order.id))
|
46
|
-
).distinct
|
47
|
-
end
|
47
|
+
Promotion.find_by_sql(
|
48
|
+
select,
|
49
|
+
order.promotions.bind_values
|
50
|
+
)
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -5,16 +5,20 @@ module Spree
|
|
5
5
|
unit_count = line_item.inventory_units.size
|
6
6
|
return if unit_count >= line_item.quantity
|
7
7
|
quantity = line_item.quantity - unit_count
|
8
|
+
return if quantity.zero?
|
8
9
|
|
9
10
|
quantifier = Stock::Quantifier.new(line_item.variant)
|
10
11
|
|
11
|
-
|
12
|
-
variant = line_item.variant
|
13
|
-
display_name = %Q{#{variant.name}}
|
14
|
-
display_name += %Q{ (#{variant.options_text})} unless variant.options_text.blank?
|
12
|
+
return if quantifier.can_supply?(quantity)
|
15
13
|
|
16
|
-
|
17
|
-
|
14
|
+
variant = line_item.variant
|
15
|
+
display_name = "#{variant.name}"
|
16
|
+
display_name += " (#{variant.options_text})" unless variant.options_text.blank?
|
17
|
+
|
18
|
+
line_item.errors[:quantity] << Spree.t(
|
19
|
+
:selected_quantity_not_available,
|
20
|
+
item: display_name.inspect
|
21
|
+
)
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -8,7 +8,11 @@ module Spree
|
|
8
8
|
|
9
9
|
validates_presence_of :stock_location, :variant
|
10
10
|
validates_uniqueness_of :variant_id, scope: [:stock_location_id, :deleted_at]
|
11
|
-
|
11
|
+
|
12
|
+
validates_numericality_of :count_on_hand,
|
13
|
+
greater_than_or_equal_to: 0,
|
14
|
+
less_than_or_equal_to: 2**31 - 1,
|
15
|
+
only_integer: true, if: :verify_count_on_hand?
|
12
16
|
|
13
17
|
delegate :weight, :should_track_inventory?, to: :variant
|
14
18
|
|
@@ -6,7 +6,12 @@ module Spree
|
|
6
6
|
after_create :update_stock_item_quantity
|
7
7
|
|
8
8
|
validates :stock_item, presence: true
|
9
|
-
validates :quantity, presence: true
|
9
|
+
validates :quantity, presence: true, numericality: {
|
10
|
+
greater_than_or_equal_to: -2**31,
|
11
|
+
less_than_or_equal_to: 2**31-1,
|
12
|
+
only_integer: true,
|
13
|
+
allow_nil: true
|
14
|
+
}
|
10
15
|
|
11
16
|
scope :recent, -> { order('created_at DESC') }
|
12
17
|
|
@@ -78,7 +78,11 @@ module Spree
|
|
78
78
|
rates = self.match(order_tax_zone)
|
79
79
|
tax_categories = rates.map(&:tax_category)
|
80
80
|
relevant_items, non_relevant_items = items.partition { |item| tax_categories.include?(item.tax_category) }
|
81
|
-
|
81
|
+
|
82
|
+
if relevant_items.present?
|
83
|
+
Spree::Adjustment.where(adjustable: relevant_items).tax.destroy_all # using destroy_all to ensure adjustment destroy callback fires.
|
84
|
+
end
|
85
|
+
|
82
86
|
relevant_items.each do |item|
|
83
87
|
relevant_rates = rates.select { |rate| rate.tax_category == item.tax_category }
|
84
88
|
store_pre_tax_amount(item, relevant_rates)
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class FixAdjustmentOrderId < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
say 'Populate order_id from adjustable_id where appropriate'
|
4
|
+
execute(<<-SQL.squish)
|
5
|
+
UPDATE
|
6
|
+
spree_adjustments
|
7
|
+
SET
|
8
|
+
order_id = adjustable_id
|
9
|
+
WHERE
|
10
|
+
adjustable_type = 'Spree::Order'
|
11
|
+
;
|
12
|
+
SQL
|
13
|
+
|
14
|
+
# Submitter of change does not care about MySQL, as it is not officially supported.
|
15
|
+
# Still spree officials decided to provide a working code path for MySQL users, hence
|
16
|
+
# submitter made a AR code path he could validate on PostgreSQL.
|
17
|
+
#
|
18
|
+
# Whoever runs a big enough MySQL installation where the AR solution hurts:
|
19
|
+
# Will have to write a better MySQL specific equivalent.
|
20
|
+
if Spree::Order.connection.adapter_name.eql?('MySQL')
|
21
|
+
Spree::Adjustment.where(adjustable_type: 'Spree::LineItem').find_each do |adjustment|
|
22
|
+
adjustment.update_columns(order_id: Spree::LineItem.find(adjustment.adjustable_id).order_id)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
execute(<<-SQL.squish)
|
26
|
+
UPDATE
|
27
|
+
spree_adjustments
|
28
|
+
SET
|
29
|
+
order_id =
|
30
|
+
(SELECT order_id FROM spree_line_items WHERE spree_line_items.id = spree_adjustments.adjustable_id)
|
31
|
+
WHERE
|
32
|
+
adjustable_type = 'Spree::LineItem'
|
33
|
+
SQL
|
34
|
+
end
|
35
|
+
|
36
|
+
say 'Fix schema for spree_adjustments order_id column'
|
37
|
+
change_table :spree_adjustments do |t|
|
38
|
+
t.change :order_id, :integer, null: false
|
39
|
+
end
|
40
|
+
|
41
|
+
# Improved schema for postgresql, uncomment if you like it:
|
42
|
+
#
|
43
|
+
# # Negated Logical implication.
|
44
|
+
# #
|
45
|
+
# # When adjustable_type is 'Spree::Order' (p) the adjustable_id must be order_id (q).
|
46
|
+
# #
|
47
|
+
# # When adjustable_type is NOT 'Spree::Order' the adjustable id allowed to be any value (including of order_id in
|
48
|
+
# # case foreign keys match). XOR does not work here.
|
49
|
+
# #
|
50
|
+
# # Postgresql does not have an operator for logical implication. So we need to build the following truth table
|
51
|
+
# # via AND with OR:
|
52
|
+
# #
|
53
|
+
# # p q | CHECK = !(p -> q)
|
54
|
+
# # -----------
|
55
|
+
# # t t | t
|
56
|
+
# # t f | f
|
57
|
+
# # f t | t
|
58
|
+
# # f f | t
|
59
|
+
# #
|
60
|
+
# # According to de-morgans law the logical implication q -> p is equivalent to !p || q
|
61
|
+
# #
|
62
|
+
# execute(<<-SQL.squish)
|
63
|
+
# ALTER TABLE ONLY spree_adjustments
|
64
|
+
# ADD CONSTRAINT fk_spree_adjustments FOREIGN KEY (order_id)
|
65
|
+
# REFERENCES spree_orders(id) ON UPDATE RESTRICT ON DELETE RESTRICT,
|
66
|
+
# ADD CONSTRAINT check_spree_adjustments_order_id CHECK
|
67
|
+
# (adjustable_type <> 'Spree::Order' OR order_id = adjustable_id);
|
68
|
+
# SQL
|
69
|
+
end
|
70
|
+
end
|
data/lib/spree/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Schofield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.0.0.rc.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: aws-sdk
|
56
|
+
name: aws-sdk-v1
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.64.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.64.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: cancancan
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -244,16 +244,16 @@ dependencies:
|
|
244
244
|
name: rails
|
245
245
|
requirement: !ruby/object:Gem::Requirement
|
246
246
|
requirements:
|
247
|
-
- -
|
247
|
+
- - "~>"
|
248
248
|
- !ruby/object:Gem::Version
|
249
|
-
version: 4.1.
|
249
|
+
version: 4.1.11
|
250
250
|
type: :runtime
|
251
251
|
prerelease: false
|
252
252
|
version_requirements: !ruby/object:Gem::Requirement
|
253
253
|
requirements:
|
254
|
-
- -
|
254
|
+
- - "~>"
|
255
255
|
- !ruby/object:Gem::Version
|
256
|
-
version: 4.1.
|
256
|
+
version: 4.1.11
|
257
257
|
- !ruby/object:Gem::Dependency
|
258
258
|
name: ransack
|
259
259
|
requirement: !ruby/object:Gem::Requirement
|
@@ -622,6 +622,7 @@ files:
|
|
622
622
|
- db/migrate/20141101231208_fix_adjustment_order_presence.rb
|
623
623
|
- db/migrate/20141105213646_update_classifications_positions.rb
|
624
624
|
- db/migrate/20141120135441_add_guest_token_index_to_spree_orders.rb
|
625
|
+
- db/migrate/20150515211137_fix_adjustment_order_id.rb
|
625
626
|
- db/seeds.rb
|
626
627
|
- lib/generators/spree/custom_user/custom_user_generator.rb
|
627
628
|
- lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt
|