solidus_core 2.11.10 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
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/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/name.rb +2 -20
- data/app/models/spree/address.rb +8 -186
- data/app/models/spree/adjustment.rb +0 -28
- data/app/models/spree/base.rb +0 -53
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -7
- 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/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +2 -45
- data/app/models/spree/order.rb +4 -137
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_updater.rb +2 -11
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method.rb +2 -103
- data/app/models/spree/product/scopes.rb +0 -27
- data/app/models/spree/product.rb +0 -40
- 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.rb +2 -6
- data/app/models/spree/promotion_action.rb +2 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/refund.rb +0 -52
- 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 +3 -22
- 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 +6 -15
- 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/active_storage_attachment.rb +0 -5
- data/app/models/spree/taxon/paperclip_attachment.rb +0 -5
- data/app/models/spree/taxon.rb +0 -11
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/variant.rb +2 -46
- 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 +12 -1
- 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 +6 -65
- 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/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +9 -8
- data/lib/spree/deprecation.rb +1 -1
- 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/event.rb +0 -31
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permitted_attributes.rb +9 -54
- 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/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +7 -14
- 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/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 +8 -49
- 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/bogus.rb +0 -13
- data/app/models/spree/gateway/bogus_simple.rb +0 -13
- data/app/models/spree/gateway.rb +0 -14
- 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 -26
- 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
@@ -28,11 +28,6 @@ module Spree
|
|
28
28
|
validates :amount, numericality: true
|
29
29
|
validates :promotion_code, presence: true, if: :require_promotion_code?
|
30
30
|
|
31
|
-
# We need to use `after_commit` here because otherwise it's too early to
|
32
|
-
# tell if any repair is needed.
|
33
|
-
after_commit :repair_adjustments_associations_on_create, on: [:create]
|
34
|
-
after_commit :repair_adjustments_associations_on_destroy, on: [:destroy]
|
35
|
-
|
36
31
|
scope :not_finalized, -> { where(finalized: false) }
|
37
32
|
scope :finalized, -> { where(finalized: true) }
|
38
33
|
scope :cancellation, -> { where(source_type: 'Spree::UnitCancel') }
|
@@ -135,15 +130,6 @@ module Spree
|
|
135
130
|
amount
|
136
131
|
end
|
137
132
|
|
138
|
-
def update!(*args)
|
139
|
-
if args.empty?
|
140
|
-
Spree::Deprecation.warn "Calling adjustment.update! with no arguments to recalculate amounts and eligibility is deprecated, since it conflicts with AR::Base#update! Please use adjustment.recalculate instead"
|
141
|
-
recalculate
|
142
|
-
else
|
143
|
-
super
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
133
|
# Calculates based on attached promotion (if this is a promotion
|
148
134
|
# adjustment) whether this promotion is still eligible.
|
149
135
|
# @api private
|
@@ -161,19 +147,5 @@ module Spree
|
|
161
147
|
def require_promotion_code?
|
162
148
|
promotion? && !source.promotion.apply_automatically && source.promotion.codes.any?
|
163
149
|
end
|
164
|
-
|
165
|
-
def repair_adjustments_associations_on_create
|
166
|
-
if adjustable.adjustments.loaded? && !adjustable.adjustments.include?(self) && !destroyed?
|
167
|
-
Spree::Deprecation.warn("Adjustment #{id} was not added to #{adjustable.class} #{adjustable.id}. Add adjustments via `adjustable.adjustments.create!`. Partial call stack: #{caller.select { |line| line =~ %r(/(app|spec)/) }}.", caller)
|
168
|
-
adjustable.adjustments.proxy_association.add_to_target(self)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def repair_adjustments_associations_on_destroy
|
173
|
-
if adjustable.adjustments.loaded? && adjustable.adjustments.include?(self)
|
174
|
-
Spree::Deprecation.warn("Adjustment #{id} was not removed from #{adjustable.class} #{adjustable.id}. Remove adjustments via `adjustable.adjustments.destroy`. Partial call stack: #{caller.select { |line| line =~ %r(/(app|spec)/) }}.", caller)
|
175
|
-
adjustable.adjustments.proxy_association.target.delete(self)
|
176
|
-
end
|
177
|
-
end
|
178
150
|
end
|
179
151
|
end
|
data/app/models/spree/base.rb
CHANGED
@@ -1,62 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spree/preferences/persistable'
|
4
|
-
|
5
3
|
class Spree::Base < ActiveRecord::Base
|
6
4
|
include Spree::Core::Permalinks
|
7
5
|
include Spree::RansackableAttributes
|
8
6
|
|
9
|
-
def self.preference(*args)
|
10
|
-
Spree::Deprecation.warn <<~WARN
|
11
|
-
#{name} has a `preferences` column, but does not explicitly (de)serialize this column.
|
12
|
-
In order to make #{name} work with future versions of Solidus (and Rails), please add the
|
13
|
-
following line to your class:
|
14
|
-
```
|
15
|
-
class #{name}
|
16
|
-
include Spree::Preferences::Persistable
|
17
|
-
...
|
18
|
-
end
|
19
|
-
```
|
20
|
-
WARN
|
21
|
-
include Spree::Preferences::Persistable
|
22
|
-
preference(*args)
|
23
|
-
end
|
24
|
-
|
25
|
-
def preferences
|
26
|
-
value = read_attribute(:preferences)
|
27
|
-
if !value.is_a?(Hash)
|
28
|
-
Spree::Deprecation.warn <<~WARN
|
29
|
-
#{self.class.name} has a `preferences` column, but does not explicitly (de)serialize this column.
|
30
|
-
In order to make #{self.class.name} work with future versions of Solidus (and Rails), please add the
|
31
|
-
following lines to your class:
|
32
|
-
```
|
33
|
-
class #{self.class.name}
|
34
|
-
include Spree::Preferences::Persistable
|
35
|
-
...
|
36
|
-
end
|
37
|
-
```
|
38
|
-
WARN
|
39
|
-
self.class.include Spree::Preferences::Persistable
|
40
|
-
|
41
|
-
ActiveRecord::Type::Serialized.new(
|
42
|
-
ActiveRecord::Type::Text.new,
|
43
|
-
ActiveRecord::Coders::YAMLColumn.new(:preferences, Hash)
|
44
|
-
).deserialize(value)
|
45
|
-
else
|
46
|
-
value
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
if Kaminari.config.page_method_name != :page
|
51
|
-
def self.page(num)
|
52
|
-
Spree::Deprecation.warn \
|
53
|
-
"Redefining Spree::Base.page for a different kaminari page name is better done inside " \
|
54
|
-
"your own app. This will be removed from future versions of solidus."
|
55
|
-
|
56
|
-
send Kaminari.config.page_method_name, num
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
7
|
self.abstract_class = true
|
61
8
|
|
62
9
|
# Provides a scope that should be included any time products
|
@@ -9,11 +9,6 @@ module Spree
|
|
9
9
|
preference :max_items, :integer, default: 0
|
10
10
|
preference :currency, :string, default: ->{ Spree::Config[:currency] }
|
11
11
|
|
12
|
-
def self.available?(_object)
|
13
|
-
Spree::Deprecation.warn('Spree::Calculator::FlexiRate::available is DEPRECATED. Use the instance method instead.')
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
12
|
def compute(object)
|
18
13
|
items_count = object.quantity
|
19
14
|
items_count = [items_count, preferred_max_items].min unless preferred_max_items.zero?
|
@@ -31,13 +31,6 @@ module Spree
|
|
31
31
|
|
32
32
|
###################################################################
|
33
33
|
|
34
|
-
# Returns all calculators applicable for kind of work
|
35
|
-
def self.calculators
|
36
|
-
Spree::Deprecation.warn("Calling .calculators is deprecated. Please access through Rails.application.config.spree.calculators")
|
37
|
-
|
38
|
-
Spree::Config.environment.calculators
|
39
|
-
end
|
40
|
-
|
41
34
|
def to_s
|
42
35
|
self.class.name.titleize.gsub("Calculator\/", "")
|
43
36
|
end
|
data/app/models/spree/country.rb
CHANGED
@@ -11,12 +11,7 @@ module Spree
|
|
11
11
|
self.whitelisted_ransackable_attributes = %w[name]
|
12
12
|
|
13
13
|
def self.default
|
14
|
-
|
15
|
-
Spree::Deprecation.warn("Setting your default country via its ID is deprecated. Please set your default country via the `default_country_iso` setting.", caller)
|
16
|
-
find_by(id: Spree::Config.default_country_id) || find_by!(iso: Spree::Config.default_country_iso)
|
17
|
-
else
|
18
|
-
find_by!(iso: Spree::Config.default_country_iso)
|
19
|
-
end
|
14
|
+
find_by!(iso: Spree::Config.default_country_iso)
|
20
15
|
end
|
21
16
|
|
22
17
|
def self.available(restrict_to_zone: Spree::Config[:checkout_zone])
|
@@ -21,11 +21,6 @@ module Spree
|
|
21
21
|
|
22
22
|
scope :with_payment_profile, -> { where('gateway_customer_profile_id IS NOT NULL') }
|
23
23
|
|
24
|
-
def self.default
|
25
|
-
Spree::Deprecation.warn("CreditCard.default is deprecated. Please use Spree::Wallet instead.")
|
26
|
-
joins(:wallet_payment_sources).where(spree_wallet_payment_sources: { default: true })
|
27
|
-
end
|
28
|
-
|
29
24
|
# needed for some of the ActiveMerchant gateways (eg. SagePay)
|
30
25
|
alias_attribute :brand, :cc_type
|
31
26
|
|
@@ -46,28 +41,6 @@ module Spree
|
|
46
41
|
'laser' => /^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/
|
47
42
|
}.freeze
|
48
43
|
|
49
|
-
def default
|
50
|
-
Spree::Deprecation.warn("CreditCard#default is deprecated. Please use user.wallet.default_wallet_payment_source instead.", caller)
|
51
|
-
return false if user.nil?
|
52
|
-
user.wallet.default_wallet_payment_source.try!(:payment_source) == self
|
53
|
-
end
|
54
|
-
|
55
|
-
def default=(set_as_default)
|
56
|
-
Spree::Deprecation.warn("CreditCard#default= is deprecated. Please use user.wallet.default_wallet_payment_source= instead.", caller)
|
57
|
-
if user.nil?
|
58
|
-
raise "Cannot set 'default' on a credit card without a user"
|
59
|
-
elsif set_as_default # setting this card as default
|
60
|
-
wallet_payment_source = user.wallet.add(self)
|
61
|
-
user.wallet.default_wallet_payment_source = wallet_payment_source
|
62
|
-
true
|
63
|
-
else # removing this card as default
|
64
|
-
if user.wallet.default_wallet_payment_source.try!(:payment_source) == self
|
65
|
-
user.wallet.default_wallet_payment_source = nil
|
66
|
-
end
|
67
|
-
false
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
44
|
def address_attributes=(attributes)
|
72
45
|
self.address = Spree::Address.immutable_merge(address, attributes)
|
73
46
|
end
|
@@ -20,8 +20,7 @@ module Spree
|
|
20
20
|
self.whitelisted_ransackable_attributes = ['number']
|
21
21
|
|
22
22
|
extend DisplayMoney
|
23
|
-
money_methods :
|
24
|
-
deprecate display_pre_tax_total: :display_total_excluding_vat, deprecator: Spree::Deprecation
|
23
|
+
money_methods :total, :total_excluding_vat, :amount
|
25
24
|
|
26
25
|
delegate :currency, to: :order
|
27
26
|
delegate :id, to: :order, prefix: true, allow_nil: true
|
@@ -33,8 +32,6 @@ module Spree
|
|
33
32
|
def total_excluding_vat
|
34
33
|
return_items.sum(&:total_excluding_vat)
|
35
34
|
end
|
36
|
-
alias pre_tax_total total_excluding_vat
|
37
|
-
deprecate pre_tax_total: :total_excluding_vat, deprecator: Spree::Deprecation
|
38
35
|
|
39
36
|
def amount
|
40
37
|
return_items.sum(:amount)
|
data/app/models/spree/image.rb
CHANGED
@@ -60,27 +60,6 @@ module Spree
|
|
60
60
|
|
61
61
|
include ::Spree::Config.state_machines.inventory_unit
|
62
62
|
|
63
|
-
# Updates the given inventory units to not be pending.
|
64
|
-
#
|
65
|
-
# @deprecated do not use this, use
|
66
|
-
# Spree::Stock::InventoryUnitsFinalizer.new(inventory_units).run!
|
67
|
-
# @param inventory_units [<Spree::InventoryUnit>] the inventory to be
|
68
|
-
# finalized
|
69
|
-
def self.finalize_units!(inventory_units)
|
70
|
-
Spree::Deprecation.warn(
|
71
|
-
"inventory_units.finalize_units!(inventory_units) is deprecated. Please
|
72
|
-
use Spree::Stock::InventoryUnitsFinalizer.new(inventory_units).run!",
|
73
|
-
caller
|
74
|
-
)
|
75
|
-
|
76
|
-
inventory_units.map do |iu|
|
77
|
-
iu.update_columns(
|
78
|
-
pending: false,
|
79
|
-
updated_at: Time.current
|
80
|
-
)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
63
|
# @return [Spree::StockItem] the first stock item from this shipment's
|
85
64
|
# stock location that is associated with this inventory unit's variant
|
86
65
|
def find_stock_item
|
@@ -10,8 +10,6 @@ module Spree
|
|
10
10
|
# promotion system.
|
11
11
|
#
|
12
12
|
class LineItem < Spree::Base
|
13
|
-
class CurrencyMismatch < StandardError; end
|
14
|
-
|
15
13
|
belongs_to :order, class_name: "Spree::Order", inverse_of: :line_items, touch: true, optional: true
|
16
14
|
belongs_to :variant, -> { with_discarded }, class_name: "Spree::Variant", inverse_of: :line_items, optional: true
|
17
15
|
belongs_to :tax_category, class_name: "Spree::TaxCategory", optional: true
|
@@ -55,20 +53,11 @@ module Spree
|
|
55
53
|
end
|
56
54
|
alias subtotal amount
|
57
55
|
|
58
|
-
# @return [BigDecimal] the amount of this line item, taking into
|
59
|
-
# consideration line item promotions.
|
60
|
-
def discounted_amount
|
61
|
-
amount + promo_total
|
62
|
-
end
|
63
|
-
deprecate discounted_amount: :total_before_tax, deprecator: Spree::Deprecation
|
64
|
-
|
65
56
|
# @return [BigDecimal] the amount of this line item, taking into
|
66
57
|
# consideration all its adjustments.
|
67
58
|
def total
|
68
59
|
amount + adjustment_total
|
69
60
|
end
|
70
|
-
alias final_amount total
|
71
|
-
deprecate final_amount: :total, deprecator: Spree::Deprecation
|
72
61
|
|
73
62
|
# @return [BigDecimal] the amount of this item, taking into consideration
|
74
63
|
# all non-tax adjustments.
|
@@ -81,20 +70,11 @@ module Spree
|
|
81
70
|
def total_excluding_vat
|
82
71
|
total_before_tax - included_tax_total
|
83
72
|
end
|
84
|
-
alias pre_tax_amount total_excluding_vat
|
85
|
-
deprecate pre_tax_amount: :total_excluding_vat, deprecator: Spree::Deprecation
|
86
73
|
|
87
74
|
extend Spree::DisplayMoney
|
88
|
-
money_methods :amount, :
|
75
|
+
money_methods :amount, :price,
|
89
76
|
:included_tax_total, :additional_tax_total,
|
90
77
|
:total, :total_before_tax, :total_excluding_vat
|
91
|
-
deprecate display_discounted_amount: :display_total_before_tax, deprecator: Spree::Deprecation
|
92
|
-
alias display_final_amount display_total
|
93
|
-
deprecate display_final_amount: :display_total, deprecator: Spree::Deprecation
|
94
|
-
alias display_pre_tax_amount display_total_excluding_vat
|
95
|
-
deprecate display_pre_tax_amount: :display_total_excluding_vat, deprecator: Spree::Deprecation
|
96
|
-
alias discounted_money display_discounted_amount
|
97
|
-
deprecate discounted_money: :display_total_before_tax, deprecator: Spree::Deprecation
|
98
78
|
|
99
79
|
# @return [Spree::Money] the price of this line item
|
100
80
|
alias money_price display_price
|
@@ -103,8 +83,6 @@ module Spree
|
|
103
83
|
|
104
84
|
# @return [Spree::Money] the amount of this line item
|
105
85
|
alias money display_amount
|
106
|
-
alias display_total display_amount
|
107
|
-
deprecate display_total: :display_amount, deprecator: Spree::Deprecation
|
108
86
|
|
109
87
|
# Sets price from a `Spree::Money` object
|
110
88
|
#
|
@@ -112,9 +90,6 @@ module Spree
|
|
112
90
|
def money_price=(money)
|
113
91
|
if !money
|
114
92
|
self.price = nil
|
115
|
-
elsif money.currency.iso_code != currency && Spree::Config.raise_with_invalid_currency
|
116
|
-
line_item_errors = ActiveModel::Errors.new(self)
|
117
|
-
raise CurrencyMismatch, line_item_errors.generate_message(:price, :does_not_match_order_currency, locale: :en)
|
118
93
|
else
|
119
94
|
self.price_currency = money.currency.iso_code
|
120
95
|
self.price = money.to_d
|
@@ -156,12 +131,6 @@ module Spree
|
|
156
131
|
Spree::Config.pricing_options_class.from_line_item(self)
|
157
132
|
end
|
158
133
|
|
159
|
-
def currency=(_currency)
|
160
|
-
Spree::Deprecation.warn 'Spree::LineItem#currency= is deprecated ' \
|
161
|
-
'and will take no effect.',
|
162
|
-
caller
|
163
|
-
end
|
164
|
-
|
165
134
|
private
|
166
135
|
|
167
136
|
# Sets the quantity to zero if it is nil or less than zero.
|
@@ -177,25 +146,13 @@ module Spree
|
|
177
146
|
set_pricing_attributes
|
178
147
|
end
|
179
148
|
|
180
|
-
# Set price, cost_price and currency.
|
181
|
-
# did more than just setting the price, hence renamed to #set_pricing_attributes
|
149
|
+
# Set price, cost_price and currency.
|
182
150
|
def set_pricing_attributes
|
183
|
-
# If the legacy method #copy_price has been overridden, handle that gracefully
|
184
|
-
return handle_copy_price_override if respond_to?(:copy_price)
|
185
|
-
|
186
151
|
self.cost_price ||= variant.cost_price
|
187
152
|
self.money_price = variant.price_for(pricing_options) if price.nil?
|
188
153
|
true
|
189
154
|
end
|
190
155
|
|
191
|
-
def handle_copy_price_override
|
192
|
-
copy_price
|
193
|
-
Spree::Deprecation.warn 'You have overridden Spree::LineItem#copy_price. ' \
|
194
|
-
'This method is now called Spree::LineItem#set_pricing_attributes. ' \
|
195
|
-
'Please adjust your override.',
|
196
|
-
caller
|
197
|
-
end
|
198
|
-
|
199
156
|
def update_inventory
|
200
157
|
if (saved_changes? || target_shipment.present?) && order.has_checkout_step?("delivery")
|
201
158
|
Spree::OrderInventory.new(order, self).verify(target_shipment)
|
data/app/models/spree/order.rb
CHANGED
@@ -50,18 +50,13 @@ module Spree
|
|
50
50
|
go_to_state :confirm
|
51
51
|
end
|
52
52
|
|
53
|
-
ransack_alias :bill_address_firstname_or_lastname, :bill_address_firstname_or_bill_address_lastname
|
54
53
|
self.whitelisted_ransackable_associations = %w[shipments user order_promotions promotions bill_address ship_address line_items]
|
55
|
-
self.whitelisted_ransackable_attributes = %w[
|
54
|
+
self.whitelisted_ransackable_attributes = %w[bill_address_name completed_at created_at email number state payment_state shipment_state total store_id]
|
56
55
|
|
57
56
|
attr_reader :coupon_code
|
58
57
|
attr_accessor :temporary_address
|
59
58
|
|
60
59
|
attr_accessor :temporary_payment_source
|
61
|
-
alias_method :temporary_credit_card, :temporary_payment_source
|
62
|
-
alias_method :temporary_credit_card=, :temporary_payment_source=
|
63
|
-
deprecate temporary_credit_card: :temporary_payment_source, deprecator: Spree::Deprecation
|
64
|
-
deprecate :temporary_credit_card= => :temporary_payment_source=, deprecator: Spree::Deprecation
|
65
60
|
|
66
61
|
# Customer info
|
67
62
|
belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true
|
@@ -147,14 +142,9 @@ module Spree
|
|
147
142
|
find_by! number: value
|
148
143
|
end
|
149
144
|
|
150
|
-
delegate :name,
|
151
|
-
alias_method :billing_firstname, :bill_address_firstname
|
152
|
-
alias_method :billing_lastname, :bill_address_lastname
|
145
|
+
delegate :name, to: :bill_address, prefix: true, allow_nil: true
|
153
146
|
alias_method :billing_name, :bill_address_name
|
154
147
|
|
155
|
-
class_attribute :update_hooks
|
156
|
-
self.update_hooks = Set.new
|
157
|
-
|
158
148
|
class_attribute :line_item_comparison_hooks
|
159
149
|
self.line_item_comparison_hooks = Set.new
|
160
150
|
|
@@ -190,15 +180,6 @@ module Spree
|
|
190
180
|
where.not(state: 'canceled')
|
191
181
|
end
|
192
182
|
|
193
|
-
# Use this method in other gems that wish to register their own custom logic
|
194
|
-
# that should be called after Order#update
|
195
|
-
def self.register_update_hook(hook)
|
196
|
-
Spree::Deprecation.warn \
|
197
|
-
"Spree::Order::update_hooks are deprecated. Please remove them " \
|
198
|
-
"and subscribe to `order_recalculated` and/or `order_finalized` event instead", caller(1)
|
199
|
-
update_hooks.add(hook)
|
200
|
-
end
|
201
|
-
|
202
183
|
# Use this method in other gems that wish to register their own custom logic
|
203
184
|
# that should be called when determining if two line items are equal.
|
204
185
|
def self.register_line_item_comparison_hook(hook)
|
@@ -210,12 +191,6 @@ module Spree
|
|
210
191
|
line_items.sum(&:amount)
|
211
192
|
end
|
212
193
|
|
213
|
-
# Sum of all line item amounts after promotions, before added tax
|
214
|
-
def discounted_item_amount
|
215
|
-
line_items.to_a.sum(&:discounted_amount)
|
216
|
-
end
|
217
|
-
deprecate discounted_item_amount: :item_total_before_tax, deprecator: Spree::Deprecation
|
218
|
-
|
219
194
|
def item_total_before_tax
|
220
195
|
line_items.to_a.sum(&:total_before_tax)
|
221
196
|
end
|
@@ -224,8 +199,6 @@ module Spree
|
|
224
199
|
def item_total_excluding_vat
|
225
200
|
line_items.to_a.sum(&:total_excluding_vat)
|
226
201
|
end
|
227
|
-
alias pre_tax_item_amount item_total_excluding_vat
|
228
|
-
deprecate pre_tax_item_amount: :item_total_excluding_vat, deprecator: Spree::Deprecation
|
229
202
|
|
230
203
|
def currency
|
231
204
|
self[:currency] || Spree::Config[:currency]
|
@@ -256,11 +229,6 @@ module Spree
|
|
256
229
|
total > 0
|
257
230
|
end
|
258
231
|
|
259
|
-
def confirmation_required?
|
260
|
-
true
|
261
|
-
end
|
262
|
-
deprecate :confirmation_required?, deprecator: Spree::Deprecation
|
263
|
-
|
264
232
|
def backordered?
|
265
233
|
shipments.any?(&:backordered?)
|
266
234
|
end
|
@@ -282,15 +250,6 @@ module Spree
|
|
282
250
|
updater.update
|
283
251
|
end
|
284
252
|
|
285
|
-
def update!(*args)
|
286
|
-
if args.empty?
|
287
|
-
Spree::Deprecation.warn "Calling order.update! with no arguments as a way to invoke the OrderUpdater is deprecated, since it conflicts with AR::Base#update! Please use order.recalculate instead"
|
288
|
-
recalculate
|
289
|
-
else
|
290
|
-
super
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
253
|
def assign_billing_to_shipping_address
|
295
254
|
self.ship_address = bill_address if bill_address
|
296
255
|
true
|
@@ -336,14 +295,7 @@ module Spree
|
|
336
295
|
assign_attributes(attrs_to_set)
|
337
296
|
end
|
338
297
|
|
339
|
-
def generate_order_number
|
340
|
-
if options
|
341
|
-
Spree::Deprecation.warn \
|
342
|
-
"Passing options to Order#generate_order_number is deprecated. " \
|
343
|
-
"Please add your own instance of the order number generator " \
|
344
|
-
"with your options (#{options.inspect}) and store it as " \
|
345
|
-
"Spree::Config.order_number_generator in your stores config."
|
346
|
-
end
|
298
|
+
def generate_order_number
|
347
299
|
self.number ||= Spree::Config.order_number_generator.generate
|
348
300
|
end
|
349
301
|
|
@@ -384,14 +336,6 @@ module Spree
|
|
384
336
|
}
|
385
337
|
end
|
386
338
|
|
387
|
-
# Creates new tax charges if there are any applicable rates. If prices already
|
388
|
-
# include taxes then price adjustments are created instead.
|
389
|
-
# @deprecated This now happens during #recalculate
|
390
|
-
def create_tax_charge!
|
391
|
-
recalculate
|
392
|
-
end
|
393
|
-
deprecate create_tax_charge!: :recalculate, deprecator: Spree::Deprecation
|
394
|
-
|
395
339
|
def reimbursement_total
|
396
340
|
reimbursements.sum(:total)
|
397
341
|
end
|
@@ -450,18 +394,10 @@ module Spree
|
|
450
394
|
|
451
395
|
updater.update_shipment_state
|
452
396
|
save!
|
453
|
-
updater.run_hooks if update_hooks.any?
|
454
397
|
|
455
398
|
touch :completed_at
|
456
399
|
|
457
400
|
Spree::Event.fire 'order_finalized', order: self
|
458
|
-
|
459
|
-
if method(:deliver_order_confirmation_email).owner != self.class
|
460
|
-
Spree::Deprecation.warn \
|
461
|
-
"deliver_order_confirmation_email has been deprecated and moved to " \
|
462
|
-
"Spree::MailerSubscriber#order_finalized, please move there any customizations.",
|
463
|
-
caller(1)
|
464
|
-
end
|
465
401
|
end
|
466
402
|
|
467
403
|
def fulfill!
|
@@ -470,16 +406,6 @@ module Spree
|
|
470
406
|
save!
|
471
407
|
end
|
472
408
|
|
473
|
-
def deliver_order_confirmation_email
|
474
|
-
Spree::Deprecation.warn \
|
475
|
-
"deliver_order_confirmation_email has been deprecated and moved to " \
|
476
|
-
"Spree::MailerSubscriber#order_finalized.",
|
477
|
-
caller(1)
|
478
|
-
|
479
|
-
Spree::Config.order_mailer_class.confirm_email(order).deliver_later
|
480
|
-
order.update_column(:confirmation_delivered, true)
|
481
|
-
end
|
482
|
-
|
483
409
|
# Helper methods for checkout steps
|
484
410
|
def paid?
|
485
411
|
%w(paid credit_owed).include?(payment_state)
|
@@ -523,26 +449,6 @@ module Spree
|
|
523
449
|
recalculate
|
524
450
|
end
|
525
451
|
|
526
|
-
alias_method :has_step?, :has_checkout_step?
|
527
|
-
deprecate has_step?: :has_checkout_step?, deprecator: Spree::Deprecation
|
528
|
-
|
529
|
-
def state_changed(name)
|
530
|
-
state = "#{name}_state"
|
531
|
-
if persisted?
|
532
|
-
old_state = send("#{state}_was")
|
533
|
-
new_state = send(state)
|
534
|
-
unless old_state == new_state
|
535
|
-
state_changes.create(
|
536
|
-
previous_state: old_state,
|
537
|
-
next_state: new_state,
|
538
|
-
name: name,
|
539
|
-
user_id: user_id
|
540
|
-
)
|
541
|
-
end
|
542
|
-
end
|
543
|
-
end
|
544
|
-
deprecate :state_changed, deprecator: Spree::Deprecation
|
545
|
-
|
546
452
|
def coupon_code=(code)
|
547
453
|
@coupon_code = begin
|
548
454
|
code.strip.downcase
|
@@ -584,7 +490,7 @@ module Spree
|
|
584
490
|
raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_shipments_not_pending'))
|
585
491
|
else
|
586
492
|
shipments.destroy_all
|
587
|
-
|
493
|
+
shipments.push(*Spree::Config.stock.coordinator_class.new(self).shipments)
|
588
494
|
end
|
589
495
|
end
|
590
496
|
|
@@ -599,8 +505,6 @@ module Spree
|
|
599
505
|
Spree::PromotionHandler::Shipping.new(self).activate
|
600
506
|
recalculate
|
601
507
|
end
|
602
|
-
alias_method :apply_free_shipping_promotions, :apply_shipping_promotions
|
603
|
-
deprecate apply_free_shipping_promotions: :apply_shipping_promotions, deprecator: Spree::Deprecation
|
604
508
|
|
605
509
|
# Clean shipments and make order back to address state
|
606
510
|
#
|
@@ -633,12 +537,6 @@ module Spree
|
|
633
537
|
bill_address == ship_address
|
634
538
|
end
|
635
539
|
|
636
|
-
# @deprecated This now happens during #recalculate
|
637
|
-
def set_shipments_cost
|
638
|
-
recalculate
|
639
|
-
end
|
640
|
-
deprecate set_shipments_cost: :recalculate, deprecator: Spree::Deprecation
|
641
|
-
|
642
540
|
def is_risky?
|
643
541
|
payments.risky.count > 0
|
644
542
|
end
|
@@ -669,11 +567,6 @@ module Spree
|
|
669
567
|
payments.offset_payment.exists? # how old versions of spree stored refunds
|
670
568
|
end
|
671
569
|
|
672
|
-
def token
|
673
|
-
Spree::Deprecation.warn("Spree::Order#token is DEPRECATED, please use #guest_token instead.", caller)
|
674
|
-
guest_token
|
675
|
-
end
|
676
|
-
|
677
570
|
def tax_total
|
678
571
|
additional_tax_total + included_tax_total
|
679
572
|
end
|
@@ -778,11 +671,6 @@ module Spree
|
|
778
671
|
end
|
779
672
|
end
|
780
673
|
|
781
|
-
alias_method :assign_default_user_addresses!, :assign_default_user_addresses
|
782
|
-
deprecate assign_default_user_addresses!: :assign_default_user_addresses, deprecator: Spree::Deprecation
|
783
|
-
alias_method :assign_default_addresses!, :assign_default_user_addresses
|
784
|
-
deprecate assign_default_addresses!: :assign_default_user_addresses, deprecator: Spree::Deprecation
|
785
|
-
|
786
674
|
def persist_user_address!
|
787
675
|
if !temporary_address && user && user.respond_to?(:persist_order_address) && bill_address_id
|
788
676
|
user.persist_order_address(self)
|
@@ -794,8 +682,6 @@ module Spree
|
|
794
682
|
add_payment_sources_to_wallet_class.new(self).
|
795
683
|
add_to_wallet
|
796
684
|
end
|
797
|
-
alias_method :persist_user_credit_card, :add_payment_sources_to_wallet
|
798
|
-
deprecate persist_user_credit_card: :add_payment_sources_to_wallet, deprecator: Spree::Deprecation
|
799
685
|
|
800
686
|
def add_default_payment_from_wallet
|
801
687
|
builder = Spree::Config.default_payment_builder_class.new(self)
|
@@ -810,8 +696,6 @@ module Spree
|
|
810
696
|
end
|
811
697
|
end
|
812
698
|
end
|
813
|
-
alias_method :assign_default_credit_card, :add_default_payment_from_wallet
|
814
|
-
deprecate assign_default_credit_card: :add_default_payment_from_wallet, deprecator: Spree::Deprecation
|
815
699
|
|
816
700
|
def record_ip_address(ip_address)
|
817
701
|
if new_record?
|
@@ -857,23 +741,6 @@ module Spree
|
|
857
741
|
end
|
858
742
|
end
|
859
743
|
|
860
|
-
# In case a existing credit card is provided it needs to build the payment
|
861
|
-
# attributes from scratch so we can set the amount. example payload:
|
862
|
-
#
|
863
|
-
# {
|
864
|
-
# "order": {
|
865
|
-
# "existing_card": "2"
|
866
|
-
# }
|
867
|
-
# }
|
868
|
-
#
|
869
|
-
def update_params_payment_source
|
870
|
-
Spree::Deprecation.warn('update_params_payment_source is deprecated. Please use set_payment_parameters_amount instead.', caller)
|
871
|
-
if @updating_params[:order] && (@updating_params[:order][:payments_attributes] || @updating_params[:order][:existing_card])
|
872
|
-
@updating_params[:order][:payments_attributes] ||= [{}]
|
873
|
-
@updating_params[:order][:payments_attributes].first[:amount] = total
|
874
|
-
end
|
875
|
-
end
|
876
|
-
|
877
744
|
def associate_store
|
878
745
|
self.store ||= Spree::Store.default
|
879
746
|
end
|