solidus_core 2.11.10 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -2
- data/app/assets/javascripts/spree.js.erb +0 -51
- data/app/controllers/spree/base_controller.rb +1 -1
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/helpers/spree/products_helper.rb +2 -2
- data/app/helpers/spree/store_helper.rb +0 -11
- data/app/mailers/spree/carton_mailer.rb +1 -5
- data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
- data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
- 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/default_price.rb +39 -10
- data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
- data/app/models/concerns/spree/soft_deletable.rb +2 -4
- data/app/models/concerns/spree/user_address_book.rb +10 -37
- data/app/models/concerns/spree/user_methods.rb +38 -13
- 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 +7 -33
- data/app/models/spree/base.rb +0 -53
- data/app/models/spree/calculator/flat_fee.rb +21 -0
- data/app/models/spree/calculator/flexi_rate.rb +0 -5
- data/app/models/spree/calculator.rb +0 -7
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/country.rb +2 -7
- data/app/models/spree/credit_card.rb +1 -28
- data/app/models/spree/customer_return.rb +5 -7
- data/app/models/spree/image/active_storage_attachment.rb +2 -7
- data/app/models/spree/image/paperclip_attachment.rb +2 -2
- data/app/models/spree/image.rb +0 -7
- data/app/models/spree/inventory_unit.rb +0 -21
- data/app/models/spree/line_item.rb +6 -49
- data/app/models/spree/log_entry.rb +74 -1
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_value.rb +10 -1
- data/app/models/spree/order/number_generator.rb +7 -1
- data/app/models/spree/order.rb +82 -170
- data/app/models/spree/order_cancellations.rb +4 -24
- data/app/models/spree/order_contents.rb +2 -1
- data/app/models/spree/order_inventory.rb +1 -1
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_promotion.rb +1 -1
- data/app/models/spree/order_shipping.rb +6 -9
- data/app/models/spree/order_taxation.rb +6 -4
- data/app/models/spree/order_updater.rb +17 -16
- data/app/models/spree/payment/cancellation.rb +1 -1
- data/app/models/spree/payment/processing.rb +58 -55
- data/app/models/spree/payment.rb +0 -3
- data/app/models/spree/payment_create.rb +1 -13
- data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
- data/app/models/spree/payment_method/credit_card.rb +1 -3
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
- data/app/models/spree/payment_method.rb +26 -110
- data/app/models/spree/price.rb +3 -3
- data/app/models/spree/product/scopes.rb +24 -33
- data/app/models/spree/product.rb +15 -42
- data/app/models/spree/product_property.rb +1 -1
- data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
- data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
- data/app/models/spree/promotion/rules/item_total.rb +50 -6
- data/app/models/spree/promotion/rules/product.rb +20 -8
- data/app/models/spree/promotion/rules/store.rb +4 -0
- data/app/models/spree/promotion/rules/taxon.rb +6 -15
- data/app/models/spree/promotion/rules/user.rb +4 -0
- data/app/models/spree/promotion.rb +39 -32
- data/app/models/spree/promotion_action.rb +6 -9
- data/app/models/spree/promotion_code/batch_builder.rb +0 -14
- data/app/models/spree/promotion_code.rb +11 -7
- data/app/models/spree/promotion_handler/cart.rb +26 -6
- data/app/models/spree/promotion_rule.rb +5 -0
- data/app/models/spree/property.rb +1 -1
- data/app/models/spree/refund.rb +8 -52
- data/app/models/spree/reimbursement.rb +5 -43
- 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 +2 -5
- data/app/models/spree/return_item.rb +4 -24
- data/app/models/spree/shipment.rb +3 -56
- data/app/models/spree/shipping_method.rb +0 -25
- data/app/models/spree/shipping_rate.rb +0 -2
- data/app/models/spree/shipping_rate_tax.rb +1 -1
- data/app/models/spree/state.rb +1 -5
- data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
- data/app/models/spree/stock/availability.rb +11 -3
- data/app/models/spree/stock/quantifier.rb +12 -8
- data/app/models/spree/stock/simple_coordinator.rb +8 -26
- data/app/models/spree/stock/splitter/base.rb +2 -7
- data/app/models/spree/stock_item.rb +2 -8
- data/app/models/spree/stock_location.rb +2 -2
- data/app/models/spree/stock_movement.rb +2 -2
- data/app/models/spree/store.rb +0 -12
- data/app/models/spree/store_credit.rb +14 -1
- data/app/models/spree/store_credit_category.rb +0 -32
- data/app/models/spree/store_credit_prioritizer.rb +17 -0
- data/app/models/spree/tax/item_tax.rb +3 -2
- data/app/models/spree/tax/order_tax.rb +3 -1
- data/app/models/spree/tax/tax_helpers.rb +2 -2
- data/app/models/spree/tax/tax_location.rb +4 -7
- data/app/models/spree/tax_calculator/default.rb +31 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
- data/app/models/spree/tax_rate.rb +9 -27
- data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
- data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
- data/app/models/spree/taxon.rb +1 -12
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/user_address.rb +0 -5
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
- data/app/models/spree/variant/price_selector.rb +34 -4
- data/app/models/spree/variant.rb +52 -66
- data/app/models/spree/zone.rb +1 -1
- data/app/subscribers/spree/mailer_subscriber.rb +4 -0
- data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
- data/config/i18n-tasks.yml +134 -0
- data/config/locales/en.yml +406 -263
- data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
- data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
- data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
- data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
- data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
- data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
- data/db/seeds.rb +4 -1
- data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
- data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
- data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
- data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
- data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
- data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
- data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
- data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
- data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
- data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
- data/lib/generators/solidus/install/install_generator.rb +247 -149
- data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
- data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
- data/lib/generators/solidus/update/update_generator.rb +112 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
- data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
- data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
- data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
- data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
- 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 +134 -64
- data/lib/spree/bus.rb +20 -0
- data/lib/spree/core/class_constantizer.rb +2 -0
- data/lib/spree/core/controller_helpers/auth.rb +10 -15
- data/lib/spree/core/controller_helpers/current_host.rb +5 -3
- data/lib/spree/core/controller_helpers/order.rb +12 -32
- 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/search.rb +1 -1
- data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
- data/lib/spree/core/engine.rb +54 -50
- data/lib/spree/core/environment_extension.rb +0 -9
- data/lib/spree/core/product_filters.rb +1 -41
- data/lib/spree/core/role_configuration.rb +0 -14
- data/lib/spree/core/search/base.rb +18 -35
- data/lib/spree/core/state_machines/order.rb +2 -2
- data/lib/spree/core/state_machines.rb +2 -11
- data/lib/spree/core/stock_configuration.rb +18 -0
- data/lib/spree/core/validators/email.rb +5 -3
- data/lib/spree/core/version.rb +5 -1
- data/lib/spree/core/versioned_value.rb +75 -0
- data/lib/spree/core.rb +40 -11
- 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 +7 -7
- data/lib/spree/event.rb +1 -32
- data/lib/spree/i18n.rb +0 -22
- data/lib/spree/migrations.rb +13 -11
- data/lib/spree/money.rb +3 -18
- data/lib/spree/permission_sets/default_customer.rb +8 -1
- data/lib/spree/permitted_attributes.rb +17 -59
- data/lib/spree/preferences/configuration.rb +84 -0
- data/lib/spree/preferences/preferable.rb +13 -0
- data/lib/spree/preferences/preferable_class_methods.rb +37 -4
- data/lib/spree/preferences/preference_differentiator.rb +29 -0
- data/lib/spree/preferences/static_model_preferences.rb +25 -10
- data/lib/spree/rails_compatibility.rb +106 -0
- data/lib/spree/testing_support/blacklist_urls.rb +1 -1
- data/lib/spree/testing_support/bus_helpers.rb +101 -0
- data/lib/spree/testing_support/capybara_ext.rb +0 -30
- data/lib/spree/testing_support/common_rake.rb +71 -23
- data/lib/spree/testing_support/controller_requests.rb +0 -82
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/database.yml +42 -22
- data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
- data/lib/spree/testing_support/dummy_app.rb +47 -34
- data/lib/spree/testing_support/factories/address_factory.rb +9 -6
- data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
- data/lib/spree/testing_support/factories/country_factory.rb +1 -2
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +8 -5
- data/lib/spree/testing_support/factories/product_factory.rb +4 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
- data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
- data/lib/spree/testing_support/factories/state_factory.rb +8 -2
- data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
- data/lib/spree/testing_support/factories/user_factory.rb +6 -0
- data/lib/spree/testing_support/factory_bot.rb +2 -2
- data/lib/spree/testing_support/order_walkthrough.rb +6 -8
- data/lib/spree/testing_support/preferences.rb +0 -25
- data/lib/spree/testing_support/silence_deprecations.rb +9 -0
- data/lib/tasks/colorado_delivery_fee.rake +28 -0
- data/lib/tasks/payment_method.rake +29 -0
- data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
- data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
- data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
- data/solidus_core.gemspec +14 -7
- metadata +127 -78
- 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/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
- data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
- data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +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
- data/lib/tasks/upgrade.rake +0 -13
data/app/models/spree/order.rb
CHANGED
@@ -38,9 +38,21 @@ module Spree
|
|
38
38
|
class CannotRebuildShipments < StandardError; end
|
39
39
|
|
40
40
|
extend Spree::DisplayMoney
|
41
|
-
money_methods
|
42
|
-
:
|
43
|
-
:
|
41
|
+
money_methods(
|
42
|
+
:outstanding_balance,
|
43
|
+
:item_total,
|
44
|
+
:adjustment_total,
|
45
|
+
:included_tax_total,
|
46
|
+
:additional_tax_total,
|
47
|
+
:tax_total,
|
48
|
+
:shipment_total,
|
49
|
+
:total,
|
50
|
+
:order_total_after_store_credit,
|
51
|
+
:total_available_store_credit,
|
52
|
+
:item_total_before_tax,
|
53
|
+
:shipment_total_before_tax,
|
54
|
+
:item_total_excluding_vat
|
55
|
+
)
|
44
56
|
alias :display_ship_total :display_shipment_total
|
45
57
|
|
46
58
|
checkout_flow do
|
@@ -50,18 +62,13 @@ module Spree
|
|
50
62
|
go_to_state :confirm
|
51
63
|
end
|
52
64
|
|
53
|
-
|
54
|
-
self.
|
55
|
-
self.whitelisted_ransackable_attributes = %w[bill_address_firstname_or_lastname completed_at created_at email number state payment_state shipment_state total store_id]
|
65
|
+
self.allowed_ransackable_associations = %w[shipments user order_promotions promotions bill_address ship_address line_items]
|
66
|
+
self.allowed_ransackable_attributes = %w[completed_at created_at email number state payment_state shipment_state total store_id]
|
56
67
|
|
57
68
|
attr_reader :coupon_code
|
58
69
|
attr_accessor :temporary_address
|
59
70
|
|
60
71
|
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
72
|
|
66
73
|
# Customer info
|
67
74
|
belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true
|
@@ -107,7 +114,7 @@ module Spree
|
|
107
114
|
# Returns
|
108
115
|
has_many :return_authorizations, dependent: :destroy, inverse_of: :order
|
109
116
|
has_many :return_items, through: :inventory_units
|
110
|
-
has_many :customer_returns, through: :return_items
|
117
|
+
has_many :customer_returns, -> { distinct }, through: :return_items
|
111
118
|
has_many :reimbursements, inverse_of: :order
|
112
119
|
has_many :refunds, through: :payments
|
113
120
|
|
@@ -133,7 +140,7 @@ module Spree
|
|
133
140
|
before_create :create_token
|
134
141
|
before_create :link_by_email
|
135
142
|
|
136
|
-
validates :email, presence: true, if: :
|
143
|
+
validates :email, presence: true, if: :email_required?
|
137
144
|
validates :email, 'spree/email' => true, allow_blank: true
|
138
145
|
validates :guest_token, presence: { allow_nil: true }
|
139
146
|
validates :number, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
|
@@ -147,14 +154,9 @@ module Spree
|
|
147
154
|
find_by! number: value
|
148
155
|
end
|
149
156
|
|
150
|
-
delegate :name,
|
151
|
-
alias_method :billing_firstname, :bill_address_firstname
|
152
|
-
alias_method :billing_lastname, :bill_address_lastname
|
157
|
+
delegate :name, to: :bill_address, prefix: true, allow_nil: true
|
153
158
|
alias_method :billing_name, :bill_address_name
|
154
159
|
|
155
|
-
class_attribute :update_hooks
|
156
|
-
self.update_hooks = Set.new
|
157
|
-
|
158
160
|
class_attribute :line_item_comparison_hooks
|
159
161
|
self.line_item_comparison_hooks = Set.new
|
160
162
|
|
@@ -190,15 +192,6 @@ module Spree
|
|
190
192
|
where.not(state: 'canceled')
|
191
193
|
end
|
192
194
|
|
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
195
|
# Use this method in other gems that wish to register their own custom logic
|
203
196
|
# that should be called when determining if two line items are equal.
|
204
197
|
def self.register_line_item_comparison_hook(hook)
|
@@ -210,22 +203,18 @@ module Spree
|
|
210
203
|
line_items.sum(&:amount)
|
211
204
|
end
|
212
205
|
|
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
206
|
def item_total_before_tax
|
220
207
|
line_items.to_a.sum(&:total_before_tax)
|
221
208
|
end
|
222
209
|
|
210
|
+
def shipment_total_before_tax
|
211
|
+
shipments.to_a.sum(&:total_before_tax)
|
212
|
+
end
|
213
|
+
|
223
214
|
# Sum of all line item amounts pre-tax
|
224
215
|
def item_total_excluding_vat
|
225
216
|
line_items.to_a.sum(&:total_excluding_vat)
|
226
217
|
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
218
|
|
230
219
|
def currency
|
231
220
|
self[:currency] || Spree::Config[:currency]
|
@@ -256,11 +245,6 @@ module Spree
|
|
256
245
|
total > 0
|
257
246
|
end
|
258
247
|
|
259
|
-
def confirmation_required?
|
260
|
-
true
|
261
|
-
end
|
262
|
-
deprecate :confirmation_required?, deprecator: Spree::Deprecation
|
263
|
-
|
264
248
|
def backordered?
|
265
249
|
shipments.any?(&:backordered?)
|
266
250
|
end
|
@@ -271,7 +255,7 @@ module Spree
|
|
271
255
|
ship_address
|
272
256
|
else
|
273
257
|
bill_address
|
274
|
-
end || store
|
258
|
+
end || store&.default_cart_tax_location
|
275
259
|
end
|
276
260
|
|
277
261
|
def updater
|
@@ -282,15 +266,6 @@ module Spree
|
|
282
266
|
updater.update
|
283
267
|
end
|
284
268
|
|
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
269
|
def assign_billing_to_shipping_address
|
295
270
|
self.ship_address = bill_address if bill_address
|
296
271
|
true
|
@@ -310,15 +285,15 @@ module Spree
|
|
310
285
|
end
|
311
286
|
|
312
287
|
def contents
|
313
|
-
@contents ||= Spree::
|
288
|
+
@contents ||= Spree::Config.order_contents_class.new(self)
|
314
289
|
end
|
315
290
|
|
316
291
|
def shipping
|
317
|
-
@shipping ||= Spree::
|
292
|
+
@shipping ||= Spree::Config.order_shipping_class.new(self)
|
318
293
|
end
|
319
294
|
|
320
295
|
def cancellations
|
321
|
-
@cancellations ||= Spree::
|
296
|
+
@cancellations ||= Spree::Config.order_cancellations_class.new(self)
|
322
297
|
end
|
323
298
|
|
324
299
|
# Associates the specified user with the order.
|
@@ -336,14 +311,7 @@ module Spree
|
|
336
311
|
assign_attributes(attrs_to_set)
|
337
312
|
end
|
338
313
|
|
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
|
314
|
+
def generate_order_number
|
347
315
|
self.number ||= Spree::Config.order_number_generator.generate
|
348
316
|
end
|
349
317
|
|
@@ -384,14 +352,6 @@ module Spree
|
|
384
352
|
}
|
385
353
|
end
|
386
354
|
|
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
355
|
def reimbursement_total
|
396
356
|
reimbursements.sum(:total)
|
397
357
|
end
|
@@ -435,33 +395,16 @@ module Spree
|
|
435
395
|
Spree::CreditCard.where(id: credit_card_ids)
|
436
396
|
end
|
437
397
|
|
438
|
-
#
|
439
|
-
#
|
398
|
+
# TODO: Remove on Solidus 4.0
|
399
|
+
# @api private
|
440
400
|
def finalize!
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
shipment.finalize!
|
449
|
-
end
|
450
|
-
|
451
|
-
updater.update_shipment_state
|
452
|
-
save!
|
453
|
-
updater.run_hooks if update_hooks.any?
|
454
|
-
|
455
|
-
touch :completed_at
|
456
|
-
|
457
|
-
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
|
401
|
+
Spree::Deprecation.warn <<~MSG
|
402
|
+
Calling `Spree::Order#finalize!` is discouraged. Instead, use
|
403
|
+
`Spree::Order#complete!`, which goes through all the needed safety
|
404
|
+
checks before finalizing an order. This method will be removed
|
405
|
+
altogether on Solidus 4.0.
|
406
|
+
MSG
|
407
|
+
finalize
|
465
408
|
end
|
466
409
|
|
467
410
|
def fulfill!
|
@@ -470,16 +413,6 @@ module Spree
|
|
470
413
|
save!
|
471
414
|
end
|
472
415
|
|
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
416
|
# Helper methods for checkout steps
|
484
417
|
def paid?
|
485
418
|
%w(paid credit_owed).include?(payment_state)
|
@@ -523,26 +456,6 @@ module Spree
|
|
523
456
|
recalculate
|
524
457
|
end
|
525
458
|
|
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
459
|
def coupon_code=(code)
|
547
460
|
@coupon_code = begin
|
548
461
|
code.strip.downcase
|
@@ -584,12 +497,13 @@ module Spree
|
|
584
497
|
raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_shipments_not_pending'))
|
585
498
|
else
|
586
499
|
shipments.destroy_all
|
587
|
-
|
500
|
+
shipments.push(*Spree::Config.stock.coordinator_class.new(self).shipments)
|
588
501
|
end
|
589
502
|
end
|
590
503
|
|
591
504
|
def create_shipments_for_line_item(line_item)
|
592
|
-
units = Spree::
|
505
|
+
units = Spree::Config.stock.inventory_unit_builder_class.new(self).missing_units_for_line_item(line_item)
|
506
|
+
|
593
507
|
Spree::Config.stock.coordinator_class.new(self, units).shipments.each do |shipment|
|
594
508
|
shipments << shipment
|
595
509
|
end
|
@@ -599,8 +513,6 @@ module Spree
|
|
599
513
|
Spree::PromotionHandler::Shipping.new(self).activate
|
600
514
|
recalculate
|
601
515
|
end
|
602
|
-
alias_method :apply_free_shipping_promotions, :apply_shipping_promotions
|
603
|
-
deprecate apply_free_shipping_promotions: :apply_shipping_promotions, deprecator: Spree::Deprecation
|
604
516
|
|
605
517
|
# Clean shipments and make order back to address state
|
606
518
|
#
|
@@ -622,7 +534,7 @@ module Spree
|
|
622
534
|
state: 'cart',
|
623
535
|
updated_at: Time.current
|
624
536
|
)
|
625
|
-
next
|
537
|
+
self.next
|
626
538
|
end
|
627
539
|
|
628
540
|
def refresh_shipment_rates
|
@@ -633,12 +545,6 @@ module Spree
|
|
633
545
|
bill_address == ship_address
|
634
546
|
end
|
635
547
|
|
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
548
|
def is_risky?
|
643
549
|
payments.risky.count > 0
|
644
550
|
end
|
@@ -669,11 +575,6 @@ module Spree
|
|
669
575
|
payments.offset_payment.exists? # how old versions of spree stored refunds
|
670
576
|
end
|
671
577
|
|
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
578
|
def tax_total
|
678
579
|
additional_tax_total + included_tax_total
|
679
580
|
end
|
@@ -695,8 +596,9 @@ module Spree
|
|
695
596
|
|
696
597
|
if matching_store_credits.any?
|
697
598
|
payment_method = Spree::PaymentMethod::StoreCredit.first
|
599
|
+
sorter = Spree::Config.store_credit_prioritizer_class.new(matching_store_credits, self)
|
698
600
|
|
699
|
-
|
601
|
+
sorter.call.each do |credit|
|
700
602
|
break if remaining_total.zero?
|
701
603
|
next if credit.amount_remaining.zero?
|
702
604
|
|
@@ -778,11 +680,6 @@ module Spree
|
|
778
680
|
end
|
779
681
|
end
|
780
682
|
|
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
683
|
def persist_user_address!
|
787
684
|
if !temporary_address && user && user.respond_to?(:persist_order_address) && bill_address_id
|
788
685
|
user.persist_order_address(self)
|
@@ -794,8 +691,6 @@ module Spree
|
|
794
691
|
add_payment_sources_to_wallet_class.new(self).
|
795
692
|
add_to_wallet
|
796
693
|
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
694
|
|
800
695
|
def add_default_payment_from_wallet
|
801
696
|
builder = Spree::Config.default_payment_builder_class.new(self)
|
@@ -810,8 +705,6 @@ module Spree
|
|
810
705
|
end
|
811
706
|
end
|
812
707
|
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
708
|
|
816
709
|
def record_ip_address(ip_address)
|
817
710
|
if new_record?
|
@@ -857,21 +750,25 @@ module Spree
|
|
857
750
|
end
|
858
751
|
end
|
859
752
|
|
860
|
-
#
|
861
|
-
#
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
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
|
753
|
+
# Finalizes an in progress order after checkout is complete.
|
754
|
+
# Called after transition to complete state when payments will have been processed
|
755
|
+
def finalize
|
756
|
+
# lock all adjustments (coupon promotions, etc.)
|
757
|
+
all_adjustments.each(&:finalize!)
|
758
|
+
|
759
|
+
# update payment and shipment(s) states, and save
|
760
|
+
updater.update_payment_state
|
761
|
+
shipments.each do |shipment|
|
762
|
+
shipment.update_state
|
763
|
+
shipment.finalize!
|
874
764
|
end
|
765
|
+
|
766
|
+
updater.update_shipment_state
|
767
|
+
save!
|
768
|
+
|
769
|
+
touch :completed_at
|
770
|
+
|
771
|
+
Spree::Bus.publish :order_finalized, order: self
|
875
772
|
end
|
876
773
|
|
877
774
|
def associate_store
|
@@ -883,15 +780,23 @@ module Spree
|
|
883
780
|
end
|
884
781
|
|
885
782
|
# Determine if email is required (we don't want validation errors before we hit the checkout)
|
886
|
-
def
|
783
|
+
def email_required?
|
887
784
|
true unless new_record? || ['cart', 'address'].include?(state)
|
888
785
|
end
|
889
786
|
|
787
|
+
def require_email
|
788
|
+
Spree::Deprecation.warn "Use email_required? instead", caller(1)
|
789
|
+
email_required?
|
790
|
+
end
|
791
|
+
|
890
792
|
def ensure_inventory_units
|
891
793
|
if has_checkout_step?("delivery")
|
892
|
-
inventory_validator = Spree::
|
794
|
+
inventory_validator = Spree::Config.stock.inventory_validator_class.new
|
795
|
+
|
796
|
+
errors = line_items.map { |line_item|
|
797
|
+
inventory_validator.validate(line_item)
|
798
|
+
}.compact
|
893
799
|
|
894
|
-
errors = line_items.map { |line_item| inventory_validator.validate(line_item) }.compact
|
895
800
|
raise InsufficientStock if errors.any?
|
896
801
|
end
|
897
802
|
end
|
@@ -909,8 +814,15 @@ module Spree
|
|
909
814
|
end
|
910
815
|
|
911
816
|
def validate_line_item_availability
|
912
|
-
availability_validator = Spree::
|
913
|
-
|
817
|
+
availability_validator = Spree::Config.stock.availability_validator_class.new
|
818
|
+
|
819
|
+
# NOTE: This code assumes that the availability validator will return
|
820
|
+
# true for success and false for failure. This is not normally the
|
821
|
+
# behaviour of validators, as the framework only cares about the
|
822
|
+
# population of the errors, not the return value of the validate method.
|
823
|
+
raise InsufficientStock unless line_items.all? { |line_item|
|
824
|
+
availability_validator.validate(line_item)
|
825
|
+
}
|
914
826
|
end
|
915
827
|
|
916
828
|
def ensure_line_items_present
|
@@ -23,16 +23,10 @@ class Spree::OrderCancellations
|
|
23
23
|
# @api public
|
24
24
|
#
|
25
25
|
# @param [Array<InventoryUnit>] inventory_units the inventory units to be short shipped
|
26
|
-
# @param [Spree.user_class] whodunnit (deprecated) the system or person that is short shipping the inventory unit
|
27
26
|
# @param [Spree.user_class] created_by the system or person that is short shipping the inventory unit
|
28
27
|
#
|
29
28
|
# @return [Array<UnitCancel>] the units that have been canceled due to short shipping
|
30
|
-
def short_ship(inventory_units,
|
31
|
-
if whodunnit
|
32
|
-
created_by ||= whodunnit
|
33
|
-
Spree::Deprecation.warn("Calling #short_ship on #{self} with whodunnit is deprecated, use created_by instead")
|
34
|
-
end
|
35
|
-
|
29
|
+
def short_ship(inventory_units, created_by: nil)
|
36
30
|
if inventory_units.map(&:order_id).uniq != [@order.id]
|
37
31
|
raise ArgumentError, "Not all inventory units belong to this order"
|
38
32
|
end
|
@@ -65,16 +59,10 @@ class Spree::OrderCancellations
|
|
65
59
|
#
|
66
60
|
# @param [InventoryUnit] inventory_unit the inventory unit to be canceled
|
67
61
|
# @param [String] reason the reason that you are canceling the inventory unit
|
68
|
-
# @param [Spree.user_class] whodunnit (deprecated) the system or person that is canceling the inventory unit
|
69
62
|
# @param [Spree.user_class] created_by the system or person that is canceling the inventory unit
|
70
63
|
#
|
71
64
|
# @return [UnitCancel] the unit that has been canceled
|
72
|
-
def cancel_unit(inventory_unit, reason: Spree::UnitCancel::DEFAULT_REASON,
|
73
|
-
if whodunnit
|
74
|
-
created_by ||= whodunnit
|
75
|
-
Spree::Deprecation.warn("Calling #cancel_unit on #{self} with whodunnit is deprecated, use created_by instead")
|
76
|
-
end
|
77
|
-
|
65
|
+
def cancel_unit(inventory_unit, reason: Spree::UnitCancel::DEFAULT_REASON, created_by: nil)
|
78
66
|
unit_cancel = nil
|
79
67
|
|
80
68
|
Spree::OrderMutex.with_lock!(@order) do
|
@@ -96,10 +84,7 @@ class Spree::OrderCancellations
|
|
96
84
|
# @param [Array<InventoryUnit>] inventory_units the inventory units to be reimbursed
|
97
85
|
# @param [Spree.user_class] created_by the user that is performing this action
|
98
86
|
# @return [Reimbursement] the reimbursement for inventory being canceled
|
99
|
-
def reimburse_units(inventory_units, created_by:
|
100
|
-
unless created_by
|
101
|
-
Spree::Deprecation.warn("Calling #reimburse_units on #{self} without created_by is deprecated")
|
102
|
-
end
|
87
|
+
def reimburse_units(inventory_units, created_by:)
|
103
88
|
reimbursement = nil
|
104
89
|
|
105
90
|
Spree::OrderMutex.with_lock!(@order) do
|
@@ -113,12 +98,7 @@ class Spree::OrderCancellations
|
|
113
98
|
|
114
99
|
private
|
115
100
|
|
116
|
-
def short_ship_unit(inventory_unit,
|
117
|
-
if whodunnit
|
118
|
-
created_by ||= whodunnit
|
119
|
-
Spree::Deprecation.warn("Calling #short_ship_unit on #{self} with whodunnit is deprecated, use created_by instead")
|
120
|
-
end
|
121
|
-
|
101
|
+
def short_ship_unit(inventory_unit, created_by: nil)
|
122
102
|
unit_cancel = Spree::UnitCancel.create!(
|
123
103
|
inventory_unit: inventory_unit,
|
124
104
|
reason: Spree::UnitCancel::SHORT_SHIP,
|
@@ -42,8 +42,8 @@ module Spree
|
|
42
42
|
# If we do not update first, then the item total will be wrong and ItemTotal
|
43
43
|
# promotion rules would not be triggered.
|
44
44
|
reload_totals
|
45
|
-
PromotionHandler::Cart.new(order).activate
|
46
45
|
order.ensure_updated_shipments
|
46
|
+
PromotionHandler::Cart.new(order).activate
|
47
47
|
end
|
48
48
|
reload_totals
|
49
49
|
true
|
@@ -89,6 +89,7 @@ module Spree
|
|
89
89
|
line_item ||= order.line_items.new(
|
90
90
|
quantity: 0,
|
91
91
|
variant: variant,
|
92
|
+
adjustments: [],
|
92
93
|
)
|
93
94
|
|
94
95
|
line_item.quantity += quantity.to_i
|
@@ -62,7 +62,7 @@ module Spree
|
|
62
62
|
potential_shipments.detect do |shipment|
|
63
63
|
shipment.include?(variant)
|
64
64
|
end || potential_shipments.detect do |shipment|
|
65
|
-
stock_item =
|
65
|
+
stock_item = variant.stock_items.detect { |stock_item| stock_item.stock_location == shipment.stock_location }
|
66
66
|
if stock_item
|
67
67
|
stock_item.backorderable? || stock_item.count_on_hand >= quantity
|
68
68
|
end
|
@@ -115,8 +115,8 @@ module Spree
|
|
115
115
|
current_line_item.quantity += other_order_line_item.quantity
|
116
116
|
handle_error(current_line_item) unless current_line_item.save
|
117
117
|
else
|
118
|
-
order.line_items
|
119
|
-
handle_error(
|
118
|
+
new_line_item = order.line_items.build(other_order_line_item.attributes.except("id"))
|
119
|
+
handle_error(new_line_item) unless new_line_item.save
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
validates :promotion, presence: true
|
17
17
|
validates :promotion_code, presence: true, if: :require_promotion_code?
|
18
18
|
|
19
|
-
self.
|
19
|
+
self.allowed_ransackable_associations = %w[promotion_code]
|
20
20
|
|
21
21
|
private
|
22
22
|
|
@@ -62,18 +62,15 @@ class Spree::OrderShipping
|
|
62
62
|
end
|
63
63
|
|
64
64
|
inventory_units.map(&:shipment).uniq.each do |shipment|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
# TODO: make OrderShipping#ship_shipment call Shipment#ship! rather than
|
71
|
-
# having Shipment#ship! call OrderShipping#ship_shipment. We only really
|
72
|
-
# need this `update_columns` for the specs, until we make that change.
|
73
|
-
shipment.update_columns(state: 'shipped', shipped_at: Time.current)
|
65
|
+
if shipment.inventory_units.reload.all? { |iu| iu.shipped? || iu.canceled? }
|
66
|
+
shipment.update!(state: "shipped", shipped_at: Time.current, tracking: tracking_number)
|
67
|
+
else
|
68
|
+
shipment.update!(tracking: tracking_number)
|
69
|
+
end
|
74
70
|
end
|
75
71
|
|
76
72
|
send_shipment_emails(carton) if stock_location.fulfillable? && !suppress_mailer # e.g. digital gift cards that aren't actually shipped
|
73
|
+
@order.shipments.reload
|
77
74
|
@order.recalculate
|
78
75
|
|
79
76
|
carton
|
@@ -17,13 +17,15 @@ module Spree
|
|
17
17
|
|
18
18
|
# Apply taxes to the order.
|
19
19
|
#
|
20
|
-
# This method will create or update adjustments on all line
|
21
|
-
# shipments in the order to reflect the appropriate taxes passed
|
22
|
-
# will also remove any now inapplicable tax adjustments.
|
20
|
+
# This method will create or update adjustments on the order and all line
|
21
|
+
# items and shipments in the order to reflect the appropriate taxes passed
|
22
|
+
# in. It will also remove any now inapplicable tax adjustments.
|
23
23
|
#
|
24
24
|
# @param [Spree::Tax::OrderTax] taxes the taxes to apply to the order
|
25
25
|
# @return [void]
|
26
26
|
def apply(taxes)
|
27
|
+
update_adjustments(@order, taxes.order_taxes) if taxes.order_taxes
|
28
|
+
|
27
29
|
@order.line_items.each do |item|
|
28
30
|
taxed_items = taxes.line_item_taxes.select { |element| element.item_id == item.id }
|
29
31
|
update_adjustments(item, taxed_items)
|
@@ -70,7 +72,7 @@ module Spree
|
|
70
72
|
|
71
73
|
tax_adjustment ||= item.adjustments.new(
|
72
74
|
source: tax_item.tax_rate,
|
73
|
-
order_id: item.order_id,
|
75
|
+
order_id: item.is_a?(Spree::Order) ? item.id : item.order_id,
|
74
76
|
label: tax_item.label,
|
75
77
|
included: tax_item.included_in_price
|
76
78
|
)
|