solidus_core 2.11.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (140) 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/active_storage_adapter.rb +2 -0
  6. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +11 -11
  7. data/app/models/concerns/spree/adjustment_source.rb +0 -15
  8. data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
  9. data/app/models/concerns/spree/soft_deletable.rb +2 -4
  10. data/app/models/concerns/spree/user_address_book.rb +0 -37
  11. data/app/models/concerns/spree/user_methods.rb +2 -11
  12. data/app/models/spree/ability.rb +0 -37
  13. data/app/models/spree/address.rb +8 -186
  14. data/app/models/spree/address/name.rb +2 -20
  15. data/app/models/spree/adjustment.rb +0 -28
  16. data/app/models/spree/base.rb +0 -35
  17. data/app/models/spree/calculator.rb +4 -7
  18. data/app/models/spree/calculator/flexi_rate.rb +0 -5
  19. data/app/models/spree/country.rb +1 -6
  20. data/app/models/spree/credit_card.rb +0 -27
  21. data/app/models/spree/customer_return.rb +1 -4
  22. data/app/models/spree/image.rb +0 -7
  23. data/app/models/spree/image/active_storage_attachment.rb +10 -2
  24. data/app/models/spree/image/paperclip_attachment.rb +1 -1
  25. data/app/models/spree/inventory_unit.rb +0 -21
  26. data/app/models/spree/line_item.rb +2 -45
  27. data/app/models/spree/order.rb +3 -136
  28. data/app/models/spree/order_cancellations.rb +4 -24
  29. data/app/models/spree/order_updater.rb +2 -11
  30. data/app/models/spree/payment.rb +0 -3
  31. data/app/models/spree/payment/cancellation.rb +1 -1
  32. data/app/models/spree/payment_create.rb +1 -13
  33. data/app/models/spree/payment_method.rb +5 -103
  34. data/app/models/spree/payment_method/bogus_credit_card.rb +13 -9
  35. data/app/models/spree/payment_method/credit_card.rb +1 -3
  36. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +4 -4
  37. data/app/models/spree/product.rb +0 -39
  38. data/app/models/spree/product/scopes.rb +0 -27
  39. data/app/models/spree/promotion.rb +2 -6
  40. data/app/models/spree/promotion/actions/create_adjustment.rb +0 -3
  41. data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -3
  42. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
  43. data/app/models/spree/promotion/rules/taxon.rb +2 -15
  44. data/app/models/spree/promotion_action.rb +5 -9
  45. data/app/models/spree/promotion_code/batch_builder.rb +0 -14
  46. data/app/models/spree/promotion_rule.rb +4 -0
  47. data/app/models/spree/refund.rb +0 -50
  48. data/app/models/spree/reimbursement.rb +3 -41
  49. data/app/models/spree/reimbursement_performer.rb +2 -8
  50. data/app/models/spree/reimbursement_type/credit.rb +1 -4
  51. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
  52. data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
  53. data/app/models/spree/return_authorization.rb +1 -4
  54. data/app/models/spree/return_item.rb +1 -19
  55. data/app/models/spree/shipment.rb +1 -54
  56. data/app/models/spree/shipping_method.rb +0 -25
  57. data/app/models/spree/shipping_rate.rb +0 -2
  58. data/app/models/spree/state.rb +0 -4
  59. data/app/models/spree/stock/simple_coordinator.rb +0 -14
  60. data/app/models/spree/stock/splitter/base.rb +2 -7
  61. data/app/models/spree/stock_item.rb +1 -7
  62. data/app/models/spree/store.rb +0 -12
  63. data/app/models/spree/store_credit_category.rb +0 -32
  64. data/app/models/spree/tax_calculator/shipping_rate.rb +1 -12
  65. data/app/models/spree/tax_rate.rb +0 -27
  66. data/app/models/spree/taxon.rb +0 -11
  67. data/app/models/spree/taxon/active_storage_attachment.rb +0 -5
  68. data/app/models/spree/taxon/paperclip_attachment.rb +0 -5
  69. data/app/models/spree/user_address.rb +0 -5
  70. data/app/models/spree/variant.rb +1 -45
  71. data/config/locales/en.yml +0 -8
  72. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
  73. data/lib/generators/solidus/install/install_generator.rb +13 -2
  74. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -39
  75. data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
  76. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
  77. data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
  78. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  79. data/lib/spree/app_configuration.rb +14 -65
  80. data/lib/spree/core.rb +9 -8
  81. data/lib/spree/core/class_constantizer.rb +2 -0
  82. data/lib/spree/core/controller_helpers/auth.rb +1 -14
  83. data/lib/spree/core/controller_helpers/order.rb +2 -22
  84. data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
  85. data/lib/spree/core/controller_helpers/pricing.rb +0 -8
  86. data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
  87. data/lib/spree/core/engine.rb +0 -35
  88. data/lib/spree/core/environment_extension.rb +0 -9
  89. data/lib/spree/core/product_filters.rb +0 -40
  90. data/lib/spree/core/role_configuration.rb +0 -14
  91. data/lib/spree/core/search/base.rb +0 -26
  92. data/lib/spree/core/state_machines.rb +2 -11
  93. data/lib/spree/core/version.rb +1 -1
  94. data/lib/spree/deprecation.rb +1 -1
  95. data/lib/spree/event.rb +0 -31
  96. data/lib/spree/event/configuration.rb +0 -5
  97. data/lib/spree/event/subscriber.rb +0 -18
  98. data/lib/spree/event/subscriber_registry.rb +3 -1
  99. data/lib/spree/i18n.rb +0 -22
  100. data/lib/spree/money.rb +3 -18
  101. data/lib/spree/permitted_attributes.rb +2 -53
  102. data/lib/spree/preferences/persistable.rb +23 -0
  103. data/lib/spree/testing_support/capybara_ext.rb +0 -30
  104. data/lib/spree/testing_support/controller_requests.rb +0 -82
  105. data/lib/spree/testing_support/dummy_app.rb +6 -14
  106. data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
  107. data/lib/spree/testing_support/factories/order_factory.rb +0 -1
  108. data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
  109. data/lib/spree/testing_support/fixtures/file.txt +1 -0
  110. data/lib/spree/testing_support/order_walkthrough.rb +0 -3
  111. data/lib/spree/testing_support/preferences.rb +0 -25
  112. data/lib/tasks/upgrade.rake +7 -5
  113. data/solidus_core.gemspec +2 -5
  114. metadata +9 -48
  115. data/app/mailers/spree/test_mailer.rb +0 -13
  116. data/app/models/concerns/spree/user_payment_source.rb +0 -26
  117. data/app/models/spree/calculator/free_shipping.rb +0 -22
  118. data/app/models/spree/calculator/percent_per_item.rb +0 -51
  119. data/app/models/spree/calculator/price_sack.rb +0 -28
  120. data/app/models/spree/gateway.rb +0 -14
  121. data/app/models/spree/gateway/bogus.rb +0 -13
  122. data/app/models/spree/gateway/bogus_simple.rb +0 -13
  123. data/app/models/spree/order/checkout.rb +0 -244
  124. data/app/models/spree/order_capturing.rb +0 -50
  125. data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
  126. data/lib/generators/spree/install/install_generator.rb +0 -15
  127. data/lib/solidus/migrations/rename_gateways.rb +0 -41
  128. data/lib/spree/core/current_store.rb +0 -24
  129. data/lib/spree/paranoia_deprecations.rb +0 -41
  130. data/lib/spree/promo/environment.rb +0 -12
  131. data/lib/spree/testing_support/bar_ability.rb +0 -19
  132. data/lib/tasks/core.rake +0 -104
  133. data/lib/tasks/email.rake +0 -12
  134. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
  135. data/lib/tasks/migrations/migrate_address_names.rake +0 -158
  136. data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -38
  137. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
  138. data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
  139. data/lib/tasks/migrations/rename_gateways.rake +0 -23
  140. data/lib/tasks/order_capturing.rake +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d027dc2e99b1a25b1217cd8625f0e375a54fe6c63649080d2b3199360965886b
4
- data.tar.gz: 6c6dd38a8b9a117ca95b9608c6b5a1b367fe263b8cd0d152f84dda94c337ac55
3
+ metadata.gz: 81eb655ea1d37e3bcff2919b25a0eeb4bfe3ab9e1a63bde79634d2dc4aabdbf6
4
+ data.tar.gz: 6da9f5ee0d1c4f6ac1207360a0b02aab57815979c9cfcc92fc0ac7d96045c4e8
5
5
  SHA512:
6
- metadata.gz: 6402bc69d1af4cb7fc0f7b41af1086238249a49a9ded3bc2f70471766820a8950c748f416bf795a7f43d5852727981d15d1bd6af9051226f4159f57f69946fc8
7
- data.tar.gz: a79e25b3f90d223545db55b96adefc1ac6474bfdce50d738e6d16a621deb69f5ed1f5a46b7f466b7f58d138a9930a9a466680eb181dedf84e8c6278ceaa532cf
6
+ metadata.gz: accdc98f491008a0541f3b03e4354724d772ea47546419871cb39a0b4431d9fba8db6757ae7b41dd0c0d3347948d31b13cb72ccac2fee9e8bf96a3de5d00a629
7
+ data.tar.gz: 7b4d5570a1e2b882d9d6186840e0f324fdf44af55347a14434c3ce58d8cabba0331daca21a65c34e49c70d26c631d24794610e45cde69565087ca7c40caf582f
@@ -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)
@@ -107,6 +107,8 @@ module Spree
107
107
 
108
108
  def url(style = default_style)
109
109
  attachment.url(style)
110
+ rescue ActiveStorage::FileNotFoundError
111
+ "noimage/#{style}.png"
110
112
  end
111
113
 
112
114
  def destroy_attachment(_name)
@@ -9,11 +9,9 @@ module Spree
9
9
  class Attachment
10
10
  delegate_missing_to :@attachment
11
11
 
12
- DEFAULT_SIZE = '100%'
13
-
14
12
  def initialize(attachment, styles: {})
15
13
  @attachment = attachment
16
- @styles = styles
14
+ @styles = normalize_styles(styles)
17
15
  end
18
16
 
19
17
  def exists?
@@ -21,20 +19,18 @@ module Spree
21
19
  end
22
20
 
23
21
  def filename
24
- blob.filename.to_s
22
+ blob&.filename.to_s
25
23
  end
26
24
 
27
25
  def url(style = nil)
28
- variant(style).url
26
+ variant(style)&.url
29
27
  end
30
28
 
31
29
  def variant(style = nil)
32
- size = style_to_size(style&.to_sym)
30
+ size = style_to_size(style)
33
31
  @attachment.variant(
34
- resize: size,
35
- strip: true,
36
- 'auto-orient': true,
37
- colorspace: 'sRGB',
32
+ resize_to_limit: size,
33
+ strip: true
38
34
  ).processed
39
35
  end
40
36
 
@@ -61,8 +57,12 @@ module Spree
61
57
  @attachment.metadata
62
58
  end
63
59
 
60
+ def normalize_styles(styles)
61
+ styles.transform_values { |v| v.split('x') }
62
+ end
63
+
64
64
  def style_to_size(style)
65
- @styles.fetch(style) { DEFAULT_SIZE }
65
+ @styles.fetch(style&.to_sym) { [width, height] }
66
66
  end
67
67
  end
68
68
  end
@@ -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
@@ -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