solidus_core 2.0.3 → 2.1.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 +62 -3
- data/app/assets/javascripts/spree.js.coffee.erb +4 -1
- data/app/helpers/spree/base_helper.rb +7 -48
- data/app/models/spree/address.rb +5 -1
- data/app/models/spree/adjustment.rb +3 -3
- data/app/models/spree/app_configuration.rb +13 -0
- data/app/models/spree/calculator.rb +3 -2
- data/app/models/spree/calculator/default_tax.rb +6 -10
- data/app/models/spree/calculator/flat_percent_item_total.rb +0 -4
- data/app/models/spree/calculator/flat_rate.rb +0 -4
- data/app/models/spree/calculator/flexi_rate.rb +0 -4
- data/app/models/spree/calculator/free_shipping.rb +0 -3
- data/app/models/spree/calculator/percent_on_line_item.rb +0 -4
- data/app/models/spree/calculator/percent_per_item.rb +0 -4
- data/app/models/spree/calculator/price_sack.rb +0 -4
- data/app/models/spree/calculator/returns/default_refund_amount.rb +0 -3
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +0 -4
- data/app/models/spree/calculator/shipping/flat_rate.rb +0 -4
- data/app/models/spree/calculator/shipping/flexi_rate.rb +0 -4
- data/app/models/spree/calculator/shipping/per_item.rb +0 -4
- data/app/models/spree/calculator/shipping/price_sack.rb +0 -4
- data/app/models/spree/calculator/tiered_flat_rate.rb +0 -4
- data/app/models/spree/calculator/tiered_percent.rb +0 -4
- data/app/models/spree/credit_card.rb +27 -14
- data/app/models/spree/gateway.rb +4 -0
- data/app/models/spree/inventory_unit.rb +2 -0
- data/app/models/spree/line_item.rb +31 -26
- data/app/models/spree/option_type.rb +0 -3
- data/app/models/spree/order.rb +28 -31
- data/app/models/spree/order/checkout.rb +0 -2
- data/app/models/spree/order_contents.rb +0 -45
- data/app/models/spree/order_merger.rb +6 -6
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +91 -13
- data/app/models/spree/payment.rb +9 -2
- data/app/models/spree/payment/processing.rb +15 -9
- data/app/models/spree/payment_method.rb +48 -5
- data/app/models/spree/price.rb +7 -9
- data/app/models/spree/product.rb +1 -25
- data/app/models/spree/promotion.rb +22 -14
- data/app/models/spree/promotion/actions/create_adjustment.rb +12 -1
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +15 -1
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +5 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +14 -0
- data/app/models/spree/promotion/rules/taxon.rb +7 -2
- data/app/models/spree/promotion/rules/user_role.rb +43 -0
- data/app/models/spree/promotion_action.rb +19 -2
- data/app/models/spree/promotion_handler/coupon.rb +1 -4
- data/app/models/spree/promotion_handler/free_shipping.rb +22 -17
- data/app/models/spree/promotion_rule_role.rb +6 -0
- data/app/models/spree/property.rb +0 -3
- data/app/models/spree/return_authorization.rb +2 -0
- data/app/models/spree/shipment.rb +5 -21
- data/app/models/spree/shipping_method.rb +23 -2
- data/app/models/spree/shipping_rate.rb +3 -0
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock_location.rb +3 -0
- data/app/models/spree/store.rb +7 -0
- data/app/models/spree/tax/item_adjuster.rb +27 -12
- data/app/models/spree/tax/order_adjuster.rb +2 -5
- data/app/models/spree/tax/tax_helpers.rb +4 -8
- data/app/models/spree/tax_rate.rb +1 -15
- data/app/models/spree/taxon.rb +0 -3
- data/app/models/spree/transfer_item.rb +1 -1
- data/app/models/spree/user_class_handle.rb +14 -9
- data/app/models/spree/variant/pricing_options.rb +1 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/zone.rb +20 -13
- data/config/locales/en.yml +144 -62
- data/db/migrate/20120831092320_spree_one_two.rb +0 -7
- data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +0 -2
- data/db/migrate/20160924135758_remove_is_default_from_prices.rb +5 -0
- data/db/migrate/20161009141333_remove_currency_from_line_items.rb +5 -0
- data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +28 -0
- data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +20 -0
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +4 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +0 -2
- data/lib/spree/core.rb +0 -5
- data/lib/spree/core/controller_helpers/pricing.rb +2 -1
- data/lib/spree/core/engine.rb +14 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/deprecation.rb +1 -1
- data/lib/spree/localized_number.rb +3 -2
- data/lib/spree/permission_sets/configuration_display.rb +0 -1
- data/lib/spree/permission_sets/configuration_management.rb +0 -1
- data/lib/spree/permission_sets/product_display.rb +0 -1
- data/lib/spree/permission_sets/product_management.rb +0 -1
- data/lib/spree/permission_sets/user_management.rb +2 -4
- data/lib/spree/permitted_attributes.rb +3 -2
- data/lib/spree/testing_support/capybara_ext.rb +0 -12
- data/lib/spree/testing_support/factories/address_factory.rb +1 -1
- data/lib/spree/testing_support/factories/line_item_factory.rb +0 -1
- data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +8 -1
- data/lib/spree/testing_support/factories/user_factory.rb +2 -2
- data/solidus_core.gemspec +4 -3
- data/spec/helpers/base_helper_spec.rb +0 -40
- data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +16 -0
- data/spec/lib/spree/core/importer/order_spec.rb +27 -18
- data/spec/lib/spree/core/price_migrator_spec.rb +3 -1
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +16 -0
- data/spec/lib/spree/core/unreturned_item_charger_spec.rb +0 -2
- data/spec/lib/tasks/exchanges_spec.rb +4 -2
- data/spec/lib/tasks/migrations/create_vat_prices_spec.rb +5 -3
- data/spec/models/spree/adjustment_spec.rb +136 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +13 -7
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +3 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/free_shipping_spec.rb +6 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +9 -4
- data/spec/models/spree/calculator/percent_per_item_spec.rb +10 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +3 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +3 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +4 -1
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +3 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +3 -0
- data/spec/models/spree/credit_card_spec.rb +27 -1
- data/spec/models/spree/line_item_spec.rb +58 -65
- data/spec/models/spree/order/checkout_spec.rb +2 -1
- data/spec/models/spree/order/payment_spec.rb +9 -10
- data/spec/models/spree/order/tax_spec.rb +22 -7
- data/spec/models/spree/order/updating_spec.rb +1 -3
- data/spec/models/spree/order_cancellations_spec.rb +6 -4
- data/spec/models/spree/order_contents_spec.rb +34 -50
- data/spec/models/spree/order_inventory_spec.rb +3 -5
- data/spec/models/spree/order_merger_spec.rb +20 -0
- data/spec/models/spree/order_spec.rb +28 -64
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +251 -0
- data/spec/models/spree/payment_method_spec.rb +178 -28
- data/spec/models/spree/payment_spec.rb +35 -19
- data/spec/models/spree/permission_sets/configuration_display.rb +0 -4
- data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -2
- data/spec/models/spree/permission_sets/product_display_spec.rb +0 -4
- data/spec/models/spree/permission_sets/product_management_spec.rb +0 -2
- data/spec/models/spree/permission_sets/user_management_spec.rb +9 -2
- data/spec/models/spree/price_spec.rb +16 -1
- data/spec/models/spree/product_spec.rb +0 -75
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +20 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +39 -15
- data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +203 -22
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +22 -3
- data/spec/models/spree/promotion/rules/taxon_spec.rb +26 -0
- data/spec/models/spree/promotion/rules/user_role_spec.rb +86 -0
- data/spec/models/spree/promotion_action_spec.rb +38 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +36 -33
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +21 -22
- data/spec/models/spree/promotion_spec.rb +46 -6
- data/spec/models/spree/reimbursement_spec.rb +1 -1
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +2 -2
- data/spec/models/spree/shipment_spec.rb +68 -50
- data/spec/models/spree/shipping_method_spec.rb +41 -0
- data/spec/models/spree/shipping_rate_spec.rb +9 -3
- data/spec/models/spree/stock/estimator_spec.rb +4 -2
- data/spec/models/spree/store_credit_spec.rb +3 -3
- data/spec/models/spree/tax/item_adjuster_spec.rb +31 -21
- data/spec/models/spree/tax/order_adjuster_spec.rb +6 -10
- data/spec/models/spree/tax/taxation_integration_spec.rb +19 -0
- data/spec/models/spree/tax_rate_spec.rb +5 -26
- data/spec/models/spree/transfer_item_spec.rb +11 -0
- data/spec/models/spree/variant/pricing_options_spec.rb +7 -17
- data/spec/models/spree/variant_spec.rb +2 -4
- data/spec/models/spree/zone_spec.rb +60 -20
- data/spec/shared_examples/calculator_shared_examples.rb +8 -0
- metadata +19 -24
- data/app/models/spree/item_adjustments.rb +0 -89
- data/app/models/spree/option_type_prototype.rb +0 -6
- data/app/models/spree/property_prototype.rb +0 -6
- data/app/models/spree/prototype.rb +0 -14
- data/app/models/spree/prototype_taxon.rb +0 -6
- data/app/models/spree/tracker.rb +0 -8
- data/db/migrate/20150128032538_remove_environment_from_tracker.rb +0 -6
- data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +0 -1
- data/lib/spree/core/delegate_belongs_to.rb +0 -94
- data/lib/spree/testing_support/factories/prototype_factory.rb +0 -8
- data/lib/spree/testing_support/factories/tracker_factory.rb +0 -6
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -24
- data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +0 -12
- data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +0 -12
- data/spec/models/spree/item_adjustments_spec.rb +0 -306
- data/spec/models/spree/tracker_spec.rb +0 -21
|
@@ -8,10 +8,6 @@ module Spree
|
|
|
8
8
|
preference :discount_amount, :decimal, default: 0
|
|
9
9
|
preference :currency, :string, default: ->{ Spree::Config[:currency] }
|
|
10
10
|
|
|
11
|
-
def self.description
|
|
12
|
-
Spree.t(:shipping_price_sack)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
11
|
def compute_package(package)
|
|
16
12
|
compute_from_price(total(package.contents))
|
|
17
13
|
end
|
|
@@ -14,10 +14,6 @@ module Spree
|
|
|
14
14
|
|
|
15
15
|
validate :preferred_tiers_content
|
|
16
16
|
|
|
17
|
-
def self.description
|
|
18
|
-
Spree.t(:tiered_flat_rate)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
17
|
def compute(object)
|
|
22
18
|
_base, amount = preferred_tiers.sort.reverse.detect{ |b, _| object.amount >= b }
|
|
23
19
|
amount || preferred_base_amount
|
|
@@ -18,10 +18,6 @@ module Spree
|
|
|
18
18
|
}
|
|
19
19
|
validate :preferred_tiers_content
|
|
20
20
|
|
|
21
|
-
def self.description
|
|
22
|
-
Spree.t(:tiered_percent)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
21
|
def compute(object)
|
|
26
22
|
order = object.is_a?(Order) ? object : object.order
|
|
27
23
|
_base, percent = preferred_tiers.sort.reverse.detect{ |b, _| order.item_total >= b }
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
module Spree
|
|
2
|
+
# The default `source` of a `Spree::Payment`.
|
|
3
|
+
#
|
|
2
4
|
class CreditCard < Spree::Base
|
|
3
5
|
belongs_to :payment_method
|
|
4
6
|
belongs_to :user, class_name: Spree.user_class, foreign_key: 'user_id'
|
|
@@ -11,10 +13,8 @@ module Spree
|
|
|
11
13
|
|
|
12
14
|
accepts_nested_attributes_for :address
|
|
13
15
|
|
|
14
|
-
attr_reader :number
|
|
15
|
-
attr_accessor :encrypted_data,
|
|
16
|
-
:imported,
|
|
17
|
-
:verification_value
|
|
16
|
+
attr_reader :number, :verification_value
|
|
17
|
+
attr_accessor :encrypted_data, :imported
|
|
18
18
|
|
|
19
19
|
validates :month, :year, numericality: { only_integer: true }, if: :require_card_numbers?, on: :create
|
|
20
20
|
validates :number, presence: true, if: :require_card_numbers?, on: :create, unless: :imported
|
|
@@ -27,14 +27,22 @@ module Spree
|
|
|
27
27
|
# needed for some of the ActiveMerchant gateways (eg. SagePay)
|
|
28
28
|
alias_attribute :brand, :cc_type
|
|
29
29
|
|
|
30
|
+
# Taken from ActiveMerchant
|
|
31
|
+
# https://github.com/activemerchant/active_merchant/blob/2f2acd4696e8de76057b5ed670b9aa022abc1187/lib/active_merchant/billing/credit_card_methods.rb#L5
|
|
30
32
|
CARD_TYPES = {
|
|
31
|
-
visa
|
|
32
|
-
master
|
|
33
|
-
|
|
34
|
-
american_express
|
|
35
|
-
|
|
36
|
-
jcb
|
|
37
|
-
|
|
33
|
+
'visa' => /^4\d{12}(\d{3})?(\d{3})?$/,
|
|
34
|
+
'master' => /^(5[1-5]\d{4}|677189|222[1-9]\d{2}|22[3-9]\d{3}|2[3-6]\d{4}|27[01]\d{3}|2720\d{2})\d{10}$/,
|
|
35
|
+
'discover' => /^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/,
|
|
36
|
+
'american_express' => /^3[47]\d{13}$/,
|
|
37
|
+
'diners_club' => /^3(0[0-5]|[68]\d)\d{11}$/,
|
|
38
|
+
'jcb' => /^35(28|29|[3-8]\d)\d{12}$/,
|
|
39
|
+
'switch' => /^6759\d{12}(\d{2,3})?$/,
|
|
40
|
+
'solo' => /^6767\d{12}(\d{2,3})?$/,
|
|
41
|
+
'dankort' => /^5019\d{12}$/,
|
|
42
|
+
'maestro' => /^(5[06-8]|6\d)\d{10,17}$/,
|
|
43
|
+
'forbrugsforeningen' => /^600722\d{10}$/,
|
|
44
|
+
'laser' => /^(6304|6706|6709|6771(?!89))\d{8}(\d{4}|\d{6,7})?$/
|
|
45
|
+
}.freeze
|
|
38
46
|
|
|
39
47
|
def address_attributes=(attributes)
|
|
40
48
|
self.address = Address.immutable_merge(address, attributes)
|
|
@@ -70,6 +78,10 @@ module Spree
|
|
|
70
78
|
end
|
|
71
79
|
end
|
|
72
80
|
|
|
81
|
+
def verification_value=(value)
|
|
82
|
+
@verification_value = value.to_s.gsub(/\s/, '')
|
|
83
|
+
end
|
|
84
|
+
|
|
73
85
|
# Sets the credit card type, converting it to the preferred internal
|
|
74
86
|
# representation from jquery.payment's representation when appropriate.
|
|
75
87
|
#
|
|
@@ -88,15 +100,16 @@ module Spree
|
|
|
88
100
|
|
|
89
101
|
# Sets the last digits field based on the assigned credit card number.
|
|
90
102
|
def set_last_digits
|
|
91
|
-
verification_value.to_s.gsub!(/\s/, '')
|
|
92
103
|
self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1)
|
|
93
104
|
end
|
|
94
105
|
|
|
95
106
|
# @return [String] the credit card type if it can be determined from the
|
|
96
107
|
# number, otherwise the empty string
|
|
97
108
|
def try_type_from_number
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
CARD_TYPES.each do |type, pattern|
|
|
110
|
+
return type if number =~ pattern
|
|
111
|
+
end
|
|
112
|
+
''
|
|
100
113
|
end
|
|
101
114
|
|
|
102
115
|
# @return [Boolean] true when a verification value is present
|
data/app/models/spree/gateway.rb
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
module Spree
|
|
2
|
+
# A concrete implementation of `Spree::PaymentMethod` intended to provide a
|
|
3
|
+
# base for extension. See https://github.com/solidusio/solidus_gateway/ for
|
|
4
|
+
# offically supported payment gateway implementations.
|
|
5
|
+
#
|
|
2
6
|
class Gateway < PaymentMethod
|
|
3
7
|
delegate :authorize, :purchase, :capture, :void, :credit, to: :provider
|
|
4
8
|
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
module Spree
|
|
2
|
+
# Variants placed in the Order at a particular price.
|
|
3
|
+
#
|
|
4
|
+
# `Spree::LineItem` is an ActiveRecord model which records which `Spree::Variant`
|
|
5
|
+
# a customer has chosen to place in their order. It also acts as the permenent
|
|
6
|
+
# record of the customer's order by recording relevant price, taxation, and inventory
|
|
7
|
+
# concerns. Line items can also have adjustments placed on them as part of the
|
|
8
|
+
# promotion system.
|
|
9
|
+
#
|
|
2
10
|
class LineItem < Spree::Base
|
|
11
|
+
class CurrencyMismatch < StandardError; end
|
|
12
|
+
|
|
3
13
|
belongs_to :order, class_name: "Spree::Order", inverse_of: :line_items, touch: true
|
|
4
14
|
belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant", inverse_of: :line_items
|
|
5
15
|
belongs_to :tax_category, class_name: "Spree::TaxCategory"
|
|
@@ -21,9 +31,6 @@ module Spree
|
|
|
21
31
|
greater_than: -1
|
|
22
32
|
}
|
|
23
33
|
validates :price, numericality: true
|
|
24
|
-
validate :ensure_proper_currency
|
|
25
|
-
|
|
26
|
-
after_create :update_tax_charge
|
|
27
34
|
|
|
28
35
|
after_save :update_inventory
|
|
29
36
|
|
|
@@ -31,10 +38,7 @@ module Spree
|
|
|
31
38
|
before_destroy :destroy_inventory_units
|
|
32
39
|
|
|
33
40
|
delegate :name, :description, :sku, :should_track_inventory?, to: :variant
|
|
34
|
-
|
|
35
|
-
# @return [Spree::Product, nil] the product associated with this line
|
|
36
|
-
# item, if there is one
|
|
37
|
-
delegate :product, to: :variant
|
|
41
|
+
delegate :currency, to: :order, allow_nil: true
|
|
38
42
|
|
|
39
43
|
attr_accessor :target_shipment
|
|
40
44
|
|
|
@@ -80,13 +84,19 @@ module Spree
|
|
|
80
84
|
# @return [Spree::Money] the amount of this line item
|
|
81
85
|
alias money display_amount
|
|
82
86
|
alias display_total display_amount
|
|
87
|
+
deprecate display_total: :display_amount, deprecator: Spree::Deprecation
|
|
83
88
|
|
|
84
|
-
# Sets price
|
|
89
|
+
# Sets price from a `Spree::Money` object
|
|
85
90
|
#
|
|
86
|
-
# @param [Spree::Money] money - the money object to obtain price
|
|
91
|
+
# @param [Spree::Money] money - the money object to obtain price from
|
|
87
92
|
def money_price=(money)
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
if !money
|
|
94
|
+
self.price = nil
|
|
95
|
+
elsif money.currency.iso_code != currency
|
|
96
|
+
raise CurrencyMismatch, "Line item price currency must match order currency!"
|
|
97
|
+
else
|
|
98
|
+
self.price = money.to_d
|
|
99
|
+
end
|
|
90
100
|
end
|
|
91
101
|
|
|
92
102
|
# @return [Boolean] true when it is possible to supply the required
|
|
@@ -111,7 +121,10 @@ module Spree
|
|
|
111
121
|
|
|
112
122
|
assign_attributes options
|
|
113
123
|
|
|
114
|
-
#
|
|
124
|
+
# When price is part of the options we are not going to fetch
|
|
125
|
+
# it from the variant. Please note that this always allows to set
|
|
126
|
+
# a price for this line item, even if there is no existing price
|
|
127
|
+
# for the associated line item in the order currency.
|
|
115
128
|
unless options.key?(:price) || options.key?('price')
|
|
116
129
|
self.money_price = variant.price_for(pricing_options)
|
|
117
130
|
end
|
|
@@ -121,6 +134,12 @@ module Spree
|
|
|
121
134
|
Spree::Config.pricing_options_class.from_line_item(self)
|
|
122
135
|
end
|
|
123
136
|
|
|
137
|
+
def currency=(_currency)
|
|
138
|
+
Spree::Deprecation.warn 'Spree::LineItem#currency= is deprecated ' \
|
|
139
|
+
'and will take no effect.',
|
|
140
|
+
caller
|
|
141
|
+
end
|
|
142
|
+
|
|
124
143
|
private
|
|
125
144
|
|
|
126
145
|
# Sets the quantity to zero if it is nil or less than zero.
|
|
@@ -142,7 +161,6 @@ module Spree
|
|
|
142
161
|
# If the legacy method #copy_price has been overridden, handle that gracefully
|
|
143
162
|
return handle_copy_price_override if respond_to?(:copy_price)
|
|
144
163
|
|
|
145
|
-
self.currency ||= order.currency
|
|
146
164
|
self.cost_price ||= variant.cost_price
|
|
147
165
|
self.money_price = variant.price_for(pricing_options) if price.nil?
|
|
148
166
|
true
|
|
@@ -165,18 +183,5 @@ module Spree
|
|
|
165
183
|
def destroy_inventory_units
|
|
166
184
|
inventory_units.destroy_all
|
|
167
185
|
end
|
|
168
|
-
|
|
169
|
-
def update_tax_charge
|
|
170
|
-
Spree::Tax::ItemAdjuster.new(self).adjust!
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
def ensure_proper_currency
|
|
174
|
-
if currency != order.currency
|
|
175
|
-
Spree::Deprecation.warn "The line items currency is different from it's order currency. " \
|
|
176
|
-
"This behavior is not supported anymore and will be deleted soon.",
|
|
177
|
-
caller
|
|
178
|
-
errors.add(:currency, :must_match_order_currency)
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
186
|
end
|
|
182
187
|
end
|
|
@@ -13,9 +13,6 @@ module Spree
|
|
|
13
13
|
has_many :product_option_types, dependent: :destroy, inverse_of: :option_type
|
|
14
14
|
has_many :products, through: :product_option_types
|
|
15
15
|
|
|
16
|
-
has_many :option_type_prototypes
|
|
17
|
-
has_many :prototypes, through: :option_type_prototypes
|
|
18
|
-
|
|
19
16
|
validates :name, presence: true, uniqueness: { allow_blank: true }
|
|
20
17
|
validates :presentation, presence: true
|
|
21
18
|
|
data/app/models/spree/order.rb
CHANGED
|
@@ -2,6 +2,23 @@ require 'spree/core/validators/email'
|
|
|
2
2
|
require 'spree/order/checkout'
|
|
3
3
|
|
|
4
4
|
module Spree
|
|
5
|
+
# The customers cart until completed, then acts as permenent record of the transaction.
|
|
6
|
+
#
|
|
7
|
+
# `Spree::Order` is the heart of the Solidus system, as it acts as the customer's
|
|
8
|
+
# cart as they shop. Once an order is complete, it serves as the
|
|
9
|
+
# permenent record of their purchase. It has many responsibilities:
|
|
10
|
+
#
|
|
11
|
+
# * Records and validates attributes like `total` and relationships like
|
|
12
|
+
# `Spree::LineItem` as an ActiveRecord model.
|
|
13
|
+
#
|
|
14
|
+
# * Implements a customizable state machine to manage the lifecycle of an order.
|
|
15
|
+
#
|
|
16
|
+
# * Implements business logic to provide a single interface for quesitons like
|
|
17
|
+
# `checkout_allowed?` or `payment_required?`.
|
|
18
|
+
#
|
|
19
|
+
# * Implements an interface for mutating the order with methods like
|
|
20
|
+
# `empty!` and `fulfill!`.
|
|
21
|
+
#
|
|
5
22
|
class Order < Spree::Base
|
|
6
23
|
ORDER_NUMBER_LENGTH = 9
|
|
7
24
|
ORDER_NUMBER_LETTERS = false
|
|
@@ -93,7 +110,7 @@ module Spree
|
|
|
93
110
|
before_create :link_by_email
|
|
94
111
|
|
|
95
112
|
validates :email, presence: true, if: :require_email
|
|
96
|
-
validates :email, email: true,
|
|
113
|
+
validates :email, email: true, allow_blank: true
|
|
97
114
|
validates :number, presence: true, uniqueness: { allow_blank: true }
|
|
98
115
|
validates :store_id, presence: true
|
|
99
116
|
|
|
@@ -210,8 +227,10 @@ module Spree
|
|
|
210
227
|
# Returns the relevant zone (if any) to be used for taxation purposes.
|
|
211
228
|
# Uses default tax zone unless there is a specific match
|
|
212
229
|
def tax_zone
|
|
213
|
-
|
|
230
|
+
Zone.match(tax_address) || Zone.default_tax
|
|
214
231
|
end
|
|
232
|
+
deprecate tax_zone: "Please use Spree::Order#tax_address instead.",
|
|
233
|
+
deprecator: Spree::Deprecation
|
|
215
234
|
|
|
216
235
|
# Returns the address for taxation based on configuration
|
|
217
236
|
def tax_address
|
|
@@ -331,9 +350,11 @@ module Spree
|
|
|
331
350
|
|
|
332
351
|
# Creates new tax charges if there are any applicable rates. If prices already
|
|
333
352
|
# include taxes then price adjustments are created instead.
|
|
353
|
+
# @deprecated This now happens during #update!
|
|
334
354
|
def create_tax_charge!
|
|
335
|
-
Spree::
|
|
355
|
+
Spree::Config.tax_adjuster_class.new(self).adjust!
|
|
336
356
|
end
|
|
357
|
+
deprecate create_tax_charge!: :update!, deprecator: Spree::Deprecation
|
|
337
358
|
|
|
338
359
|
def outstanding_balance
|
|
339
360
|
# If reimbursement has happened add it back to total to prevent balance_due payment state
|
|
@@ -414,12 +435,10 @@ module Spree
|
|
|
414
435
|
end
|
|
415
436
|
|
|
416
437
|
def available_payment_methods
|
|
417
|
-
@available_payment_methods ||=
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
uniq.
|
|
422
|
-
sort_by(&:position)
|
|
438
|
+
@available_payment_methods ||= Spree::PaymentMethod
|
|
439
|
+
.available_to_store(store)
|
|
440
|
+
.available_to_users
|
|
441
|
+
.sort_by(&:position)
|
|
423
442
|
end
|
|
424
443
|
|
|
425
444
|
def insufficient_stock_lines
|
|
@@ -572,11 +591,6 @@ module Spree
|
|
|
572
591
|
!approved?
|
|
573
592
|
end
|
|
574
593
|
|
|
575
|
-
def reload(options = nil)
|
|
576
|
-
remove_instance_variable(:@tax_zone) if defined?(@tax_zone)
|
|
577
|
-
super
|
|
578
|
-
end
|
|
579
|
-
|
|
580
594
|
def quantity
|
|
581
595
|
line_items.sum(:quantity)
|
|
582
596
|
end
|
|
@@ -689,23 +703,6 @@ module Spree
|
|
|
689
703
|
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency: currency })
|
|
690
704
|
end
|
|
691
705
|
|
|
692
|
-
def payments_attributes=(attributes)
|
|
693
|
-
validate_payments_attributes(attributes)
|
|
694
|
-
super(attributes)
|
|
695
|
-
end
|
|
696
|
-
|
|
697
|
-
def validate_payments_attributes(attributes)
|
|
698
|
-
attributes = Array.wrap(attributes)
|
|
699
|
-
# Ensure the payment methods specified are allowed for this user
|
|
700
|
-
payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
|
|
701
|
-
attributes.each do |payment_attributes|
|
|
702
|
-
payment_method_id = payment_attributes[:payment_method_id]
|
|
703
|
-
|
|
704
|
-
# raise RecordNotFound unless it is an allowed payment method
|
|
705
|
-
payment_methods.find(payment_method_id) if payment_method_id
|
|
706
|
-
end
|
|
707
|
-
end
|
|
708
|
-
|
|
709
706
|
private
|
|
710
707
|
|
|
711
708
|
def associate_store
|
|
@@ -78,7 +78,6 @@ module Spree
|
|
|
78
78
|
|
|
79
79
|
after_transition to: :complete, do: :add_payment_sources_to_wallet
|
|
80
80
|
before_transition to: :payment, do: :set_shipments_cost
|
|
81
|
-
before_transition to: :payment, do: :create_tax_charge!
|
|
82
81
|
before_transition to: :payment, do: :assign_default_credit_card
|
|
83
82
|
|
|
84
83
|
before_transition to: :confirm, do: :add_store_credit_payments
|
|
@@ -90,7 +89,6 @@ module Spree
|
|
|
90
89
|
before_transition from: :cart, do: :ensure_line_items_present
|
|
91
90
|
|
|
92
91
|
if states[:address]
|
|
93
|
-
before_transition from: :address, do: :create_tax_charge!
|
|
94
92
|
before_transition to: :address, do: :assign_default_addresses!
|
|
95
93
|
before_transition from: :address, do: :persist_user_address!
|
|
96
94
|
end
|
|
@@ -35,21 +35,7 @@ module Spree
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def update_cart(params)
|
|
38
|
-
# We need old_tax_address / new_tax_address because we can't rely on methods
|
|
39
|
-
# offered by ActiveRecord::Dirty to determine if tax_address was updated
|
|
40
|
-
# because if we update the address, a new record will be created
|
|
41
|
-
# by the Address.factory instead of the old record being updated
|
|
42
|
-
|
|
43
|
-
old_tax_address = order.tax_address
|
|
44
|
-
|
|
45
38
|
if order.update_attributes(params)
|
|
46
|
-
|
|
47
|
-
new_tax_address = order.tax_address
|
|
48
|
-
|
|
49
|
-
if should_recalculate_taxes?(old_tax_address, new_tax_address)
|
|
50
|
-
order.create_tax_charge!
|
|
51
|
-
end
|
|
52
|
-
|
|
53
39
|
unless order.completed?
|
|
54
40
|
order.line_items = order.line_items.select { |li| li.quantity > 0 }
|
|
55
41
|
# Update totals, then check if the order is eligible for any cart promotions.
|
|
@@ -84,36 +70,6 @@ module Spree
|
|
|
84
70
|
|
|
85
71
|
private
|
|
86
72
|
|
|
87
|
-
def should_recalculate_taxes?(old_address, new_address)
|
|
88
|
-
# Related to Solidus issue #894
|
|
89
|
-
# This is needed because if you update the shipping_address
|
|
90
|
-
# from the backend on an order that completed checkout,
|
|
91
|
-
# Taxes were not being recalculated if the Order tax zone
|
|
92
|
-
# was updated
|
|
93
|
-
#
|
|
94
|
-
# Possible cases:
|
|
95
|
-
#
|
|
96
|
-
# Case 1:
|
|
97
|
-
#
|
|
98
|
-
# If old_address is a TaxLocation it means that the order has not passed
|
|
99
|
-
# the address checkout state so taxes will be computed by the Order
|
|
100
|
-
# state machine, so we do not calculate taxes here.
|
|
101
|
-
#
|
|
102
|
-
# Case 2 :
|
|
103
|
-
# If new_address is a TaxLocation, but old_address is not, it means that
|
|
104
|
-
# an order has somehow lost his TaxAddress. Since it's not supposed to happen,
|
|
105
|
-
# we do not compute taxes.
|
|
106
|
-
#
|
|
107
|
-
# Case 3
|
|
108
|
-
# Both old_address and new_address are Spree::Address so the order
|
|
109
|
-
# has completed the checkout or that a registered user has updated his
|
|
110
|
-
# default addresses. We need to recalculate the taxes.
|
|
111
|
-
|
|
112
|
-
return if old_address.is_a?(Spree::Tax::TaxLocation) || new_address.is_a?(Spree::Tax::TaxLocation)
|
|
113
|
-
|
|
114
|
-
old_address.try!(:taxation_attributes) != new_address.try!(:taxation_attributes)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
73
|
def after_add_or_remove(line_item, options = {})
|
|
118
74
|
reload_totals
|
|
119
75
|
shipment = options[:shipment]
|
|
@@ -137,7 +93,6 @@ module Spree
|
|
|
137
93
|
line_item ||= order.line_items.new(
|
|
138
94
|
quantity: 0,
|
|
139
95
|
variant: variant,
|
|
140
|
-
currency: order.currency
|
|
141
96
|
)
|
|
142
97
|
|
|
143
98
|
line_item.quantity += quantity.to_i
|