solidus_core 2.11.10 → 3.0.2

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.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree.js.erb +0 -51
  3. data/app/helpers/spree/store_helper.rb +0 -11
  4. data/app/mailers/spree/carton_mailer.rb +1 -5
  5. data/app/models/concerns/spree/adjustment_source.rb +0 -15
  6. data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
  7. data/app/models/concerns/spree/soft_deletable.rb +2 -4
  8. data/app/models/concerns/spree/user_address_book.rb +0 -37
  9. data/app/models/concerns/spree/user_methods.rb +2 -11
  10. data/app/models/spree/ability.rb +0 -37
  11. data/app/models/spree/address/name.rb +2 -20
  12. data/app/models/spree/address.rb +8 -186
  13. data/app/models/spree/adjustment.rb +0 -28
  14. data/app/models/spree/base.rb +0 -53
  15. data/app/models/spree/calculator/flexi_rate.rb +0 -5
  16. data/app/models/spree/calculator.rb +0 -7
  17. data/app/models/spree/country.rb +1 -6
  18. data/app/models/spree/credit_card.rb +0 -27
  19. data/app/models/spree/customer_return.rb +1 -4
  20. data/app/models/spree/image.rb +0 -7
  21. data/app/models/spree/inventory_unit.rb +0 -21
  22. data/app/models/spree/line_item.rb +2 -45
  23. data/app/models/spree/order.rb +4 -137
  24. data/app/models/spree/order_cancellations.rb +4 -24
  25. data/app/models/spree/order_updater.rb +2 -11
  26. data/app/models/spree/payment/cancellation.rb +1 -1
  27. data/app/models/spree/payment.rb +0 -3
  28. data/app/models/spree/payment_create.rb +1 -13
  29. data/app/models/spree/payment_method/credit_card.rb +1 -3
  30. data/app/models/spree/payment_method.rb +2 -103
  31. data/app/models/spree/product/scopes.rb +0 -27
  32. data/app/models/spree/product.rb +0 -40
  33. data/app/models/spree/promotion/actions/create_adjustment.rb +0 -3
  34. data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -3
  35. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
  36. data/app/models/spree/promotion/rules/taxon.rb +2 -15
  37. data/app/models/spree/promotion.rb +2 -6
  38. data/app/models/spree/promotion_action.rb +2 -9
  39. data/app/models/spree/promotion_code/batch_builder.rb +0 -14
  40. data/app/models/spree/refund.rb +0 -52
  41. data/app/models/spree/reimbursement.rb +3 -41
  42. data/app/models/spree/reimbursement_performer.rb +2 -8
  43. data/app/models/spree/reimbursement_type/credit.rb +1 -4
  44. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
  45. data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
  46. data/app/models/spree/return_authorization.rb +1 -4
  47. data/app/models/spree/return_item.rb +3 -22
  48. data/app/models/spree/shipment.rb +1 -54
  49. data/app/models/spree/shipping_method.rb +0 -25
  50. data/app/models/spree/shipping_rate.rb +0 -2
  51. data/app/models/spree/state.rb +0 -4
  52. data/app/models/spree/stock/simple_coordinator.rb +6 -15
  53. data/app/models/spree/stock/splitter/base.rb +2 -7
  54. data/app/models/spree/stock_item.rb +1 -7
  55. data/app/models/spree/store.rb +0 -12
  56. data/app/models/spree/store_credit_category.rb +0 -32
  57. data/app/models/spree/tax_calculator/shipping_rate.rb +1 -12
  58. data/app/models/spree/tax_rate.rb +0 -27
  59. data/app/models/spree/taxon/active_storage_attachment.rb +0 -5
  60. data/app/models/spree/taxon/paperclip_attachment.rb +0 -5
  61. data/app/models/spree/taxon.rb +0 -11
  62. data/app/models/spree/user_address.rb +0 -5
  63. data/app/models/spree/variant.rb +2 -46
  64. data/config/locales/en.yml +0 -8
  65. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
  66. data/lib/generators/solidus/install/install_generator.rb +12 -1
  67. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -39
  68. data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
  69. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
  70. data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
  71. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  72. data/lib/spree/app_configuration.rb +6 -65
  73. data/lib/spree/core/class_constantizer.rb +2 -0
  74. data/lib/spree/core/controller_helpers/auth.rb +1 -14
  75. data/lib/spree/core/controller_helpers/order.rb +2 -22
  76. data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
  77. data/lib/spree/core/controller_helpers/pricing.rb +0 -8
  78. data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
  79. data/lib/spree/core/engine.rb +0 -35
  80. data/lib/spree/core/environment_extension.rb +0 -9
  81. data/lib/spree/core/product_filters.rb +0 -40
  82. data/lib/spree/core/role_configuration.rb +0 -14
  83. data/lib/spree/core/search/base.rb +0 -26
  84. data/lib/spree/core/state_machines.rb +2 -11
  85. data/lib/spree/core/validators/email.rb +1 -1
  86. data/lib/spree/core/version.rb +1 -1
  87. data/lib/spree/core.rb +9 -8
  88. data/lib/spree/deprecation.rb +1 -1
  89. data/lib/spree/event/configuration.rb +0 -5
  90. data/lib/spree/event/subscriber.rb +0 -18
  91. data/lib/spree/event/subscriber_registry.rb +3 -1
  92. data/lib/spree/event.rb +0 -31
  93. data/lib/spree/i18n.rb +0 -22
  94. data/lib/spree/money.rb +3 -18
  95. data/lib/spree/permitted_attributes.rb +9 -54
  96. data/lib/spree/testing_support/capybara_ext.rb +0 -30
  97. data/lib/spree/testing_support/controller_requests.rb +0 -82
  98. data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
  99. data/lib/spree/testing_support/dummy_app.rb +7 -14
  100. data/lib/spree/testing_support/factories/order_factory.rb +0 -1
  101. data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
  102. data/lib/spree/testing_support/order_walkthrough.rb +0 -3
  103. data/lib/spree/testing_support/preferences.rb +0 -25
  104. data/lib/tasks/upgrade.rake +7 -5
  105. data/solidus_core.gemspec +2 -5
  106. metadata +8 -49
  107. data/app/mailers/spree/test_mailer.rb +0 -13
  108. data/app/models/concerns/spree/user_payment_source.rb +0 -26
  109. data/app/models/spree/calculator/free_shipping.rb +0 -22
  110. data/app/models/spree/calculator/percent_per_item.rb +0 -51
  111. data/app/models/spree/calculator/price_sack.rb +0 -28
  112. data/app/models/spree/gateway/bogus.rb +0 -13
  113. data/app/models/spree/gateway/bogus_simple.rb +0 -13
  114. data/app/models/spree/gateway.rb +0 -14
  115. data/app/models/spree/order/checkout.rb +0 -244
  116. data/app/models/spree/order_capturing.rb +0 -50
  117. data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
  118. data/lib/generators/spree/install/install_generator.rb +0 -15
  119. data/lib/solidus/migrations/rename_gateways.rb +0 -41
  120. data/lib/spree/core/current_store.rb +0 -24
  121. data/lib/spree/paranoia_deprecations.rb +0 -41
  122. data/lib/spree/promo/environment.rb +0 -12
  123. data/lib/spree/testing_support/bar_ability.rb +0 -19
  124. data/lib/tasks/core.rake +0 -104
  125. data/lib/tasks/email.rake +0 -12
  126. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
  127. data/lib/tasks/migrations/migrate_address_names.rake +0 -158
  128. data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
  129. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
  130. data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
  131. data/lib/tasks/migrations/rename_gateways.rake +0 -23
  132. data/lib/tasks/order_capturing.rake +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eb3e5a4b41af8809472fc7d7875fd2be9101bc2673b2d289bc32e5f6bc0cabc
4
- data.tar.gz: 48aac9f88550bbaa4ce69271426877fed50459b23c5fe3109bed565e553fe0b3
3
+ metadata.gz: ca6d8d275b71868fa0cbcfd87ea5c540ed14c4db6908e90192012889adc936b9
4
+ data.tar.gz: b9333bbde0b2634d590a9021d2b4c4a2cb398a25099254947b870f94ff0d5992
5
5
  SHA512:
6
- metadata.gz: 7b3adaf152c0e1a8bf34de8bf8577a8a369e51a6acb0215b558f055a1235b1b7499e50778cc040cf08221ee98d79df07d72b9112f61ad3158dd226b5c8af73e1
7
- data.tar.gz: dd950b0d62311e85c9e72cea449650b04d9388c2443e1dbb187bc885bf24f128338fb96e0b0b5eb177b9b444c2bb738b8d59d6bfdb298eb774b7391367e15b2d
6
+ metadata.gz: c56f0af4fbd26a4d486aaeb170d6554d256a7265a33a0a515150822dc8aefa1369e7e4ce8b3e3b60ea2a32318b9f03d9f214d18c6014ff248649d3867cc83a0b
7
+ data.tar.gz: acc8a07396946a959ebda8e0c7953eb7cb6ac656a7e91debd6e0159d0c7a6e896f0406d226fd3e28d6776999fc9797938010cdb952bea32ae819cdd64f435b4e
@@ -22,21 +22,6 @@ Spree.pathFor = function(path) {
22
22
  return locationOrigin + Spree.mountedAt() + path;
23
23
  };
24
24
 
25
- Spree.url = function(uri, query) {
26
- if (console && console.warn) {
27
- console.warn('Spree.url is deprecated, and will be removed from a future Solidus version.');
28
- }
29
- if (uri.path === undefined) {
30
- uri = new Uri(uri);
31
- }
32
- if (query) {
33
- $.each(query, function(key, value) {
34
- return uri.addQueryParam(key, value);
35
- });
36
- }
37
- return uri;
38
- };
39
-
40
25
  Spree.ajax = function(url, options) {
41
26
  if (typeof url === "object") {
42
27
  options = url;
@@ -51,42 +36,6 @@ Spree.ajax = function(url, options) {
51
36
  return $.ajax(url, options);
52
37
  };
53
38
 
54
- /**
55
- * @deprecated Spree.routes will be removed in a future release. Please use Spree.pathFor instead.
56
- * See: https://github.com/solidusio/solidus/issues/3405
57
- */
58
- Spree.routesDeprecationProxy = {
59
- get: function(obj, prop) {
60
- <% if Rails.env != "production" %>
61
- console.log("Spree.routes is deprecated, please use pathFor instead. See: https://github.com/solidusio/solidus/issues/3405");
62
- <% end %>
63
-
64
- return obj[prop]
65
- },
66
-
67
- set: function(obj, prop, value) {
68
- <% if Rails.env != "production" %>
69
- console.log("Spree.routes is deprecated, please use pathFor instead. See: https://github.com/solidusio/solidus/issues/3405");
70
- <% end %>
71
-
72
- obj[prop] = value
73
- return value;
74
- }
75
- };
76
-
77
- var frontend_routes = {
78
- states_search: Spree.pathFor('api/states'),
79
- apply_coupon_code: function(order_id) {
80
- return Spree.pathFor("api/orders/" + order_id + "/coupon_codes");
81
- }
82
- }
83
-
84
- if(typeof Proxy == "function") {
85
- Spree.routes = new Proxy(frontend_routes, Spree.routesDeprecationProxy);
86
- } else {
87
- Spree.routes = frontend_routes
88
- }
89
-
90
39
  Spree.getJSON = function(url, data, success) {
91
40
  if (typeof data === 'function') {
92
41
  success = data;
@@ -8,16 +8,5 @@ module Spree
8
8
  def store_menu?
9
9
  %w{thank_you}.exclude? params[:action]
10
10
  end
11
-
12
- def cache_key_for_taxons
13
- Spree::Deprecation.warn <<-WARN.strip_heredoc
14
- cache_key_for_taxons is deprecated. Rails >= 5 has built-in support for collection cache keys.
15
- Instead in your view use:
16
- cache [I18n.locale, @taxons] do
17
- WARN
18
- max_updated_at = @taxons.maximum(:updated_at).to_i
19
- parts = [@taxon.try(:id), max_updated_at].compact.join("-")
20
- "#{I18n.locale}/taxons/#{parts}"
21
- end
22
11
  end
23
12
  end
@@ -11,11 +11,7 @@ module Spree
11
11
  # @option options resend [Boolean] indicates whether the email is a 'resend' (e.g.
12
12
  # triggered by the admin "resend" button)
13
13
  # @return [Mail::Message]
14
- #
15
- # Note: The signature of this method has changed. The new (non-deprecated)
16
- # signature is:
17
- # def shipped_email(carton:, order:, resend: false)
18
- def shipped_email(options, _deprecated_options = {})
14
+ def shipped_email(options)
19
15
  @order = options.fetch(:order)
20
16
  @carton = options.fetch(:carton)
21
17
  @manifest = @carton.manifest_for_order(@order)
@@ -2,21 +2,6 @@
2
2
 
3
3
  module Spree
4
4
  module AdjustmentSource
5
- def deals_with_adjustments_for_deleted_source
6
- Spree::Deprecation.warn "AdjustmentSource#deals_with_adjustments_for_deleted_source is deprecated. Please use AdjustmentSource#remove_adjustments_from_incomplete_orders instead."
7
-
8
- remove_adjustments_from_incomplete_orders
9
-
10
- # The following is deprecated. As source_type without a source_id isn't
11
- # much better than a source_id that doesn't exist. In Solidus itself the
12
- # relevant classes use `acts_as_paranoid` so it is useful to keep the
13
- # source_id around.
14
- adjustments.
15
- joins(:order).
16
- merge(Spree::Order.complete).
17
- update_all(source_id: nil, updated_at: Time.current)
18
- end
19
-
20
5
  def remove_adjustments_from_incomplete_orders
21
6
  adjustments.
22
7
  joins(:order).
@@ -10,24 +10,6 @@ module Spree
10
10
  validates :calculator, presence: true
11
11
  end
12
12
 
13
- class_methods do
14
- def calculators
15
- Spree::Deprecation.warn("Calling .calculators is deprecated. Please access through Rails.application.config.spree.calculators")
16
-
17
- spree_calculators.send model_name_without_spree_namespace
18
- end
19
-
20
- private
21
-
22
- def model_name_without_spree_namespace
23
- to_s.tableize.tr('/', '_').sub('spree_', '')
24
- end
25
-
26
- def spree_calculators
27
- Spree::Config.environment.calculators
28
- end
29
- end
30
-
31
13
  def calculator_type
32
14
  calculator.class.to_s if calculator
33
15
  end
@@ -7,12 +7,10 @@ module Spree
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
- acts_as_paranoid
11
- include Spree::ParanoiaDeprecations::InstanceMethods
12
- extend Spree::ParanoiaDeprecations::ClassMethods
13
-
14
10
  include Discard::Model
15
11
  self.discard_column = :deleted_at
12
+
13
+ default_scope { kept }
16
14
  end
17
15
  end
18
16
  end
@@ -39,34 +39,6 @@ module Spree
39
39
  has_one :ship_address, through: :default_user_ship_address, source: :address
40
40
  end
41
41
 
42
- def default_address
43
- Spree::Deprecation.warn "#default_address is deprecated. Please start using #ship_address."
44
- ship_address
45
- end
46
-
47
- def default_user_address
48
- Spree::Deprecation.warn "#default_user_address is deprecated. Please start using #default_user_ship_address."
49
- default_user_ship_address
50
- end
51
-
52
- def default_address=(address)
53
- Spree::Deprecation.warn(
54
- "#default_address= does not take Spree::Config.automatic_default_address into account and is deprecated. " \
55
- "Please use #ship_address=."
56
- )
57
-
58
- self.ship_address = address if address
59
- end
60
-
61
- def default_address_attributes=(attributes)
62
- # see "Nested Attributes Examples" section of http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for
63
- # this #{fieldname}_attributes= method works with fields_for in the views
64
- # even without declaring accepts_nested_attributes_for
65
- Spree::Deprecation.warn "#default_address_attributes= is deprecated. Please use #ship_address_attributes=."
66
-
67
- self.default_address = Spree::Address.immutable_merge(ship_address, attributes)
68
- end
69
-
70
42
  # saves address in address book
71
43
  # sets address to the default if automatic_default_address is set to true
72
44
  # if address is nil, does nothing and returns nil
@@ -157,15 +129,6 @@ module Spree
157
129
  user_address.address
158
130
  end
159
131
 
160
- def mark_default_address(address)
161
- Spree::Deprecation.warn(
162
- "#mark_default_address is deprecated and it sets the ship_address only. " \
163
- "Please use #mark_default_ship_address."
164
- )
165
-
166
- mark_default_ship_address(address)
167
- end
168
-
169
132
  def mark_default_ship_address(address)
170
133
  user_addresses.mark_default(user_addresses.find_by(address: address))
171
134
  end
@@ -7,7 +7,6 @@ module Spree
7
7
  include Spree::UserApiAuthentication
8
8
  include Spree::UserReporting
9
9
  include Spree::UserAddressBook
10
- include Spree::UserPaymentSource
11
10
 
12
11
  included do
13
12
  extend Spree::DisplayMoney
@@ -24,9 +23,6 @@ module Spree
24
23
  has_many :store_credits, -> { includes(:credit_type) }, foreign_key: "user_id", class_name: "Spree::StoreCredit"
25
24
  has_many :store_credit_events, through: :store_credits
26
25
 
27
- money_methods :total_available_store_credit
28
- deprecate display_total_available_store_credit: :display_available_store_credit_total, deprecator: Spree::Deprecation
29
-
30
26
  has_many :credit_cards, class_name: "Spree::CreditCard", foreign_key: :user_id
31
27
  has_many :wallet_payment_sources, foreign_key: 'user_id', class_name: 'Spree::WalletPaymentSource', inverse_of: :user
32
28
 
@@ -34,9 +30,9 @@ module Spree
34
30
 
35
31
  include Spree::RansackableAttributes unless included_modules.include?(Spree::RansackableAttributes)
36
32
 
37
- ransack_alias :firstname_or_lastname, :addresses_firstname_or_addresses_lastname
33
+ ransack_alias :name, :addresses_name
38
34
  self.whitelisted_ransackable_associations = %w[addresses spree_roles]
39
- self.whitelisted_ransackable_attributes = %w[firstname_or_lastname id email created_at]
35
+ self.whitelisted_ransackable_attributes = %w[name id email created_at]
40
36
  end
41
37
 
42
38
  def wallet
@@ -68,11 +64,6 @@ module Spree
68
64
  last_order unless last_order.try!(:completed?)
69
65
  end
70
66
 
71
- def total_available_store_credit
72
- store_credits.reload.to_a.sum(&:amount_remaining)
73
- end
74
- deprecate total_available_store_credit: :available_store_credit_total, deprecator: Spree::Deprecation
75
-
76
67
  def available_store_credit_total(currency:)
77
68
  store_credits.to_a.
78
69
  select { |credit| credit.currency == currency }.
@@ -14,13 +14,6 @@ module Spree
14
14
 
15
15
  attr_reader :user
16
16
 
17
- CUSTOM_ALIASES_MAP = {
18
- delete: :destroy,
19
- display: :read,
20
- new_action: :create,
21
- read: :show
22
- }.freeze
23
-
24
17
  # Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to
25
18
  # modify the default +Ability+ of an application. The +ability+ argument must be a class that includes
26
19
  # the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class
@@ -40,38 +33,8 @@ module Spree
40
33
  register_extension_abilities
41
34
  end
42
35
 
43
- def can?(action, *args)
44
- super(normalize_action(action), *args)
45
- end
46
-
47
- def model_adapter(model_class, action)
48
- super(model_class, normalize_action(action))
49
- end
50
-
51
36
  private
52
37
 
53
- def normalize_action(action)
54
- return action unless Spree::Config.use_custom_cancancan_actions
55
-
56
- normalized_action = CUSTOM_ALIASES_MAP.fetch(action, action)
57
-
58
- if action == :read
59
- Spree::Deprecation.warn <<~WARN, caller(3)
60
- The behavior of CanCanCan `:read` action alias will be changing in Solidus 3.0.
61
- The current alias is: `:show, :to => :read`,
62
- the new alias will be compliant with CanCanCan's default: `index, :show, :to => :read`
63
- WARN
64
- elsif CUSTOM_ALIASES_MAP.key? action
65
- Spree::Deprecation.warn <<~WARN, caller(3)
66
- Calling CanCanCan alias action #{action.inspect} is deprecated.
67
- In Solidus 3.0 non-standard CanCanCan action aliases will be replaced with default ones,
68
- please replace with #{normalized_action.inspect}.
69
- WARN
70
- end
71
-
72
- normalized_action
73
- end
74
-
75
38
  # Before, this was the only way to extend this ability. Permission sets have been added since.
76
39
  # It is recommended to use them instead for extension purposes if possible.
77
40
  def register_extension_abilities
@@ -2,29 +2,11 @@
2
2
 
3
3
  module Spree
4
4
  class Address
5
- # Provides a value object to help transitioning from legacy
6
- # firstname and lastname fields to a unified name field.
5
+ # Provides a value object to help splitting and joining
6
+ # name fields
7
7
  class Name
8
8
  attr_reader :first_name, :last_name, :value
9
9
 
10
- # Creates an instance of Spree::Address::Name parsing input attributes.
11
- # @param attributes [Hash] an hash possibly containing name-related
12
- # attributes (name, firstname, lastname, first_name, last_name)
13
- # @return [Spree::Address::Name] the object created
14
- def self.from_attributes(attributes)
15
- params = attributes.with_indifferent_access
16
-
17
- if params[:name].present?
18
- Spree::Address::Name.new(params[:name])
19
- elsif params[:firstname].present?
20
- Spree::Address::Name.new(params[:firstname], params[:lastname])
21
- elsif params[:first_name].present?
22
- Spree::Address::Name.new(params[:first_name], params[:last_name])
23
- else
24
- Spree::Address::Name.new
25
- end
26
- end
27
-
28
10
  def initialize(*components)
29
11
  @value = components.join(' ').strip
30
12
  initialize_name_components(components)
@@ -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
- if Spree::Config.use_legacy_address_state_validator
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
- alias_attribute :first_name, :firstname
38
- alias_attribute :last_name, :lastname
39
- alias_attribute :full_name, :name
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.whitelisted_ransackable_attributes = %w[firstname lastname]
29
+ self.whitelisted_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
- if Spree::Config.use_combined_first_and_last_name_in_address
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