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/address.rb
CHANGED
@@ -14,45 +14,24 @@ module Spree
|
|
14
14
|
belongs_to :country, class_name: "Spree::Country", optional: true
|
15
15
|
belongs_to :state, class_name: "Spree::State", optional: true
|
16
16
|
|
17
|
-
validates :address1, :city, :country_id, presence: true
|
17
|
+
validates :address1, :city, :country_id, :name, presence: true
|
18
18
|
validates :zipcode, presence: true, if: :require_zipcode?
|
19
19
|
validates :phone, presence: true, if: :require_phone?
|
20
20
|
|
21
|
-
validate :validate_name
|
22
|
-
|
23
21
|
validate do
|
24
|
-
|
25
|
-
begin
|
26
|
-
@silence_state_deprecations = true
|
27
|
-
state_validate
|
28
|
-
validate_state_matches_country
|
29
|
-
ensure
|
30
|
-
@silence_state_deprecations = false
|
31
|
-
end
|
32
|
-
else
|
33
|
-
self.class.state_validator_class.new(self).perform
|
34
|
-
end
|
22
|
+
self.class.state_validator_class.new(self).perform
|
35
23
|
end
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
DB_ONLY_ATTRS = %w(id updated_at created_at)
|
42
|
-
TAXATION_ATTRS = %w(state_id country_id zipcode)
|
43
|
-
LEGACY_NAME_ATTRS = %w(firstname lastname full_name)
|
25
|
+
self.ignored_columns = %w(firstname lastname)
|
26
|
+
DB_ONLY_ATTRS = %w(id updated_at created_at).freeze
|
27
|
+
TAXATION_ATTRS = %w(state_id country_id zipcode).freeze
|
44
28
|
|
45
|
-
self.
|
29
|
+
self.allowed_ransackable_attributes = %w[name]
|
46
30
|
|
47
31
|
scope :with_values, ->(attributes) do
|
48
32
|
where(value_attributes(attributes))
|
49
33
|
end
|
50
34
|
|
51
|
-
Spree::Deprecation.deprecate_methods(
|
52
|
-
Spree::Address,
|
53
|
-
LEGACY_NAME_ATTRS.product([:name]).to_h
|
54
|
-
)
|
55
|
-
|
56
35
|
# @return [Address] an address with default attributes
|
57
36
|
def self.build_default(*args, &block)
|
58
37
|
where(country: Spree::Country.default).build(*args, &block)
|
@@ -84,23 +63,7 @@ module Spree
|
|
84
63
|
# @return [Hash] hash of attributes contributing to value equality with optional merge
|
85
64
|
def self.value_attributes(base_attributes, merge_attributes = {})
|
86
65
|
base = base_attributes.stringify_keys.merge(merge_attributes.stringify_keys)
|
87
|
-
|
88
|
-
name_from_attributes = Spree::Address::Name.from_attributes(base)
|
89
|
-
if base['firstname'].presence || base['first_name'].presence
|
90
|
-
base['firstname'] = name_from_attributes.first_name
|
91
|
-
end
|
92
|
-
if base['lastname'].presence || base['last_name'].presence
|
93
|
-
base['lastname'] = name_from_attributes.last_name
|
94
|
-
end
|
95
|
-
|
96
|
-
virtual_name = name_from_attributes.value
|
97
|
-
if base['name'].blank? && virtual_name.present?
|
98
|
-
base['name'] = virtual_name
|
99
|
-
end
|
100
|
-
|
101
|
-
excluded_attributes = DB_ONLY_ATTRS + %w(first_name last_name)
|
102
|
-
|
103
|
-
base.except(*excluded_attributes)
|
66
|
+
base.except(*DB_ONLY_ATTRS)
|
104
67
|
end
|
105
68
|
|
106
69
|
# @return [Hash] hash of attributes contributing to value equality
|
@@ -126,36 +89,7 @@ module Spree
|
|
126
89
|
# @return [Boolean] true if the two addresses have the same address fields
|
127
90
|
def ==(other_address)
|
128
91
|
return false unless other_address && other_address.respond_to?(:value_attributes)
|
129
|
-
|
130
|
-
value_attributes.except(*LEGACY_NAME_ATTRS) == other_address.value_attributes.except(*LEGACY_NAME_ATTRS)
|
131
|
-
else
|
132
|
-
value_attributes == other_address.value_attributes
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# @deprecated Do not use this. Use Address.== instead.
|
137
|
-
def same_as?(other_address)
|
138
|
-
Spree::Deprecation.warn("Address#same_as? is deprecated. It's equivalent to Address.==", caller)
|
139
|
-
self == other_address
|
140
|
-
end
|
141
|
-
|
142
|
-
# @deprecated Do not use this. Use Address.== instead.
|
143
|
-
def same_as(other_address)
|
144
|
-
Spree::Deprecation.warn("Address#same_as is deprecated. It's equivalent to Address.==", caller)
|
145
|
-
self == other_address
|
146
|
-
end
|
147
|
-
|
148
|
-
# @deprecated Do not use this
|
149
|
-
def empty?
|
150
|
-
Spree::Deprecation.warn("Address#empty? is deprecated.", caller)
|
151
|
-
attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_, value| value.nil? }
|
152
|
-
end
|
153
|
-
|
154
|
-
# This exists because the default Object#blank?, checks empty? if it is
|
155
|
-
# defined, and we have defined empty.
|
156
|
-
# This should be removed once empty? is removed
|
157
|
-
def blank?
|
158
|
-
false
|
92
|
+
value_attributes == other_address.value_attributes
|
159
93
|
end
|
160
94
|
|
161
95
|
# @return [Hash] an ActiveMerchant compatible address hash
|
@@ -202,117 +136,5 @@ module Spree
|
|
202
136
|
def country_iso
|
203
137
|
country && country.iso
|
204
138
|
end
|
205
|
-
|
206
|
-
before_save :set_name_from_firstname_and_lastname
|
207
|
-
|
208
|
-
def set_name_from_firstname_and_lastname
|
209
|
-
name_from_firstname_and_lastname = Spree::Address::Name.from_attributes(attributes.except(:name, 'name'))
|
210
|
-
|
211
|
-
if read_attribute(:name).blank? && name_from_firstname_and_lastname.present?
|
212
|
-
write_attribute(:name, name_from_firstname_and_lastname)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
# @return [String] the full name on this address
|
217
|
-
def name
|
218
|
-
self[:name] || begin
|
219
|
-
Spree::Address::Name.new(
|
220
|
-
read_attribute(:firstname),
|
221
|
-
read_attribute(:lastname)
|
222
|
-
).value
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def name=(value)
|
227
|
-
return if value.nil?
|
228
|
-
|
229
|
-
write_attribute(:name, value)
|
230
|
-
name_from_value = Spree::Address::Name.new(value)
|
231
|
-
write_attribute(:firstname, name_from_value.first_name)
|
232
|
-
write_attribute(:lastname, name_from_value.last_name)
|
233
|
-
end
|
234
|
-
|
235
|
-
def as_json(options = {})
|
236
|
-
if Spree::Config.use_combined_first_and_last_name_in_address
|
237
|
-
super(options.merge(except: LEGACY_NAME_ATTRS)).tap do |hash|
|
238
|
-
hash['name'] = name
|
239
|
-
end
|
240
|
-
else
|
241
|
-
super
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
private
|
246
|
-
|
247
|
-
def validate_name
|
248
|
-
return if name.present?
|
249
|
-
|
250
|
-
name_attribute = if Spree::Config.use_combined_first_and_last_name_in_address
|
251
|
-
:name
|
252
|
-
else
|
253
|
-
:firstname
|
254
|
-
end
|
255
|
-
errors.add(name_attribute, :blank)
|
256
|
-
end
|
257
|
-
|
258
|
-
def state_validate
|
259
|
-
unless @silence_state_deprecations
|
260
|
-
Spree::Deprecation.warn \
|
261
|
-
"#{self.class}#state_validate private method has been deprecated" \
|
262
|
-
" and will be removed in Solidus v3." \
|
263
|
-
" Check https://github.com/solidusio/solidus/pull/3129 for more details.",
|
264
|
-
caller
|
265
|
-
end
|
266
|
-
|
267
|
-
# Skip state validation without country (also required)
|
268
|
-
# or when disabled by preference
|
269
|
-
return if country.blank? || !Spree::Config[:address_requires_state]
|
270
|
-
return unless country.states_required
|
271
|
-
|
272
|
-
# ensure associated state belongs to country
|
273
|
-
if state.present?
|
274
|
-
if state.country == country
|
275
|
-
self.state_name = nil # not required as we have a valid state and country combo
|
276
|
-
elsif state_name.present?
|
277
|
-
self.state = nil
|
278
|
-
else
|
279
|
-
errors.add(:state, :invalid)
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
# ensure state_name belongs to country without states, or that it matches a predefined state name/abbr
|
284
|
-
if state_name.present?
|
285
|
-
if country.states.present?
|
286
|
-
states = country.states.with_name_or_abbr(state_name)
|
287
|
-
|
288
|
-
if states.size == 1
|
289
|
-
self.state = states.first
|
290
|
-
self.state_name = nil
|
291
|
-
else
|
292
|
-
errors.add(:state, :invalid)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
# ensure at least one state field is populated
|
298
|
-
errors.add :state, :blank if state.blank? && state_name.blank?
|
299
|
-
end
|
300
|
-
|
301
|
-
def validate_state_matches_country
|
302
|
-
unless @silence_state_deprecations
|
303
|
-
Spree::Deprecation.warn \
|
304
|
-
"#{self.class}#validate_state_matches_country private method has been deprecated" \
|
305
|
-
" and will be removed in Solidus v3." \
|
306
|
-
" Check https://github.com/solidusio/solidus/pull/3129 for more details.",
|
307
|
-
caller
|
308
|
-
end
|
309
|
-
|
310
|
-
return unless country
|
311
|
-
|
312
|
-
self.state = nil if country.states.empty?
|
313
|
-
if state && state.country != country
|
314
|
-
errors.add(:state, :does_not_match_country)
|
315
|
-
end
|
316
|
-
end
|
317
139
|
end
|
318
140
|
end
|
@@ -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') }
|
@@ -60,12 +55,14 @@ module Spree
|
|
60
55
|
#
|
61
56
|
# @param excluded_orders [Array<Spree::Order>] Orders to exclude from query
|
62
57
|
# @return [ActiveRecord::Relation] Scoped Adjustments
|
63
|
-
def self.in_completed_orders(excluded_orders: [])
|
64
|
-
joins(:order)
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
def self.in_completed_orders(excluded_orders: [], exclude_canceled: false)
|
59
|
+
result = joins(:order)
|
60
|
+
.merge(Spree::Order.complete)
|
61
|
+
.where.not(spree_orders: { id: excluded_orders })
|
62
|
+
.distinct
|
63
|
+
exclude_canceled ? result.merge(Spree::Order.not_canceled) : result
|
68
64
|
end
|
65
|
+
deprecate :in_completed_orders, "Please don't use this and rather go through Spree::Promotion#discounted_orders"
|
69
66
|
|
70
67
|
def finalize!
|
71
68
|
update!(finalized: true)
|
@@ -135,15 +132,6 @@ module Spree
|
|
135
132
|
amount
|
136
133
|
end
|
137
134
|
|
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
135
|
# Calculates based on attached promotion (if this is a promotion
|
148
136
|
# adjustment) whether this promotion is still eligible.
|
149
137
|
# @api private
|
@@ -161,19 +149,5 @@ module Spree
|
|
161
149
|
def require_promotion_code?
|
162
150
|
promotion? && !source.promotion.apply_automatically && source.promotion.codes.any?
|
163
151
|
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
152
|
end
|
179
153
|
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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_dependency 'spree/calculator'
|
4
|
+
|
5
|
+
module Spree
|
6
|
+
# Very simple tax rate calculator. Can be used to apply a flat fee to any
|
7
|
+
# type of item, including an order.
|
8
|
+
class Calculator::FlatFee < Calculator
|
9
|
+
alias_method :rate, :calculable
|
10
|
+
|
11
|
+
# Amount is fixed regardles of what it's being applied to.
|
12
|
+
def compute(_object)
|
13
|
+
rate.active? ? rate.amount : 0
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :compute_order, :compute
|
17
|
+
alias_method :compute_shipment, :compute
|
18
|
+
alias_method :compute_line_item, :compute
|
19
|
+
alias_method :compute_shipping_rate, :compute
|
20
|
+
end
|
21
|
+
end
|
@@ -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/carton.rb
CHANGED
data/app/models/spree/country.rb
CHANGED
@@ -8,15 +8,10 @@ module Spree
|
|
8
8
|
|
9
9
|
validates :name, :iso_name, presence: true
|
10
10
|
|
11
|
-
self.
|
11
|
+
self.allowed_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
|
@@ -124,7 +97,7 @@ module Spree
|
|
124
97
|
|
125
98
|
# Sets the last digits field based on the assigned credit card number.
|
126
99
|
def set_last_digits
|
127
|
-
self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4
|
100
|
+
self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..)
|
128
101
|
end
|
129
102
|
|
130
103
|
# @return [String] the credit card type if it can be determined from the
|
@@ -17,11 +17,10 @@ module Spree
|
|
17
17
|
|
18
18
|
accepts_nested_attributes_for :return_items
|
19
19
|
|
20
|
-
self.
|
20
|
+
self.allowed_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)
|
@@ -43,7 +40,8 @@ module Spree
|
|
43
40
|
# Temporarily tie a customer_return to one order
|
44
41
|
def order
|
45
42
|
return nil if return_items.blank?
|
46
|
-
|
43
|
+
|
44
|
+
return_items.first.inventory_unit&.order
|
47
45
|
end
|
48
46
|
|
49
47
|
def fully_reimbursed?
|
@@ -68,7 +66,7 @@ module Spree
|
|
68
66
|
end
|
69
67
|
|
70
68
|
def return_items_belong_to_same_order
|
71
|
-
if return_items.reject{ |return_item| return_item.inventory_unit
|
69
|
+
if return_items.reject{ |return_item| return_item.inventory_unit&.order_id == order_id }.any?
|
72
70
|
errors.add(:base, I18n.t('spree.return_items_cannot_be_associated_with_multiple_orders'))
|
73
71
|
end
|
74
72
|
end
|
@@ -12,13 +12,8 @@ module Spree::Image::ActiveStorageAttachment
|
|
12
12
|
validate :supported_content_type
|
13
13
|
|
14
14
|
has_attachment :attachment,
|
15
|
-
styles:
|
16
|
-
|
17
|
-
small: '400x400>',
|
18
|
-
product: '680x680>',
|
19
|
-
large: '1200x1200>'
|
20
|
-
},
|
21
|
-
default_style: :product
|
15
|
+
styles: Spree::Config.product_image_styles,
|
16
|
+
default_style: Spree::Config.product_image_style_default
|
22
17
|
|
23
18
|
def supported_content_type
|
24
19
|
unless attachment.content_type.in?(Spree::Config.allowed_image_mime_types)
|
@@ -7,8 +7,8 @@ module Spree::Image::PaperclipAttachment
|
|
7
7
|
validate :no_attachment_errors
|
8
8
|
|
9
9
|
has_attached_file :attachment,
|
10
|
-
styles:
|
11
|
-
default_style:
|
10
|
+
styles: Spree::Config.product_image_styles,
|
11
|
+
default_style: Spree::Config.product_image_style_default,
|
12
12
|
default_url: 'noimage/:style.png',
|
13
13
|
url: '/spree/products/:id/:style/:basename.:extension',
|
14
14
|
path: ':rails_root/public/spree/products/:id/:style/:basename.:extension',
|
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
|