solidus_core 2.11.17 → 3.0.0.rc2

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.
Files changed (146) 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/attachment.rb +11 -13
  6. data/app/models/concerns/spree/active_storage_adapter.rb +0 -2
  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/name.rb +2 -20
  14. data/app/models/spree/address.rb +8 -187
  15. data/app/models/spree/adjustment.rb +0 -28
  16. data/app/models/spree/base.rb +12 -48
  17. data/app/models/spree/calculator/flexi_rate.rb +0 -5
  18. data/app/models/spree/calculator.rb +0 -11
  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/active_storage_attachment.rb +2 -10
  23. data/app/models/spree/image/paperclip_attachment.rb +1 -1
  24. data/app/models/spree/image.rb +0 -7
  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/log_entry.rb +1 -74
  28. data/app/models/spree/order.rb +4 -137
  29. data/app/models/spree/order_cancellations.rb +4 -24
  30. data/app/models/spree/order_shipping.rb +9 -6
  31. data/app/models/spree/order_updater.rb +2 -11
  32. data/app/models/spree/payment/cancellation.rb +3 -22
  33. data/app/models/spree/payment.rb +0 -3
  34. data/app/models/spree/payment_create.rb +1 -13
  35. data/app/models/spree/payment_method/bogus_credit_card.rb +9 -13
  36. data/app/models/spree/payment_method/credit_card.rb +1 -3
  37. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +4 -4
  38. data/app/models/spree/payment_method.rb +2 -106
  39. data/app/models/spree/product/scopes.rb +0 -27
  40. data/app/models/spree/product.rb +0 -39
  41. data/app/models/spree/promotion/actions/create_adjustment.rb +0 -3
  42. data/app/models/spree/promotion/actions/create_item_adjustments.rb +0 -3
  43. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
  44. data/app/models/spree/promotion/rules/taxon.rb +2 -15
  45. data/app/models/spree/promotion.rb +2 -6
  46. data/app/models/spree/promotion_action.rb +2 -12
  47. data/app/models/spree/promotion_code/batch_builder.rb +0 -14
  48. data/app/models/spree/promotion_code.rb +2 -2
  49. data/app/models/spree/promotion_rule.rb +0 -4
  50. data/app/models/spree/refund.rb +0 -60
  51. data/app/models/spree/reimbursement.rb +3 -41
  52. data/app/models/spree/reimbursement_performer.rb +2 -8
  53. data/app/models/spree/reimbursement_type/credit.rb +1 -4
  54. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
  55. data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
  56. data/app/models/spree/return_authorization.rb +1 -4
  57. data/app/models/spree/return_item.rb +1 -19
  58. data/app/models/spree/shipment.rb +1 -54
  59. data/app/models/spree/shipping_method.rb +0 -25
  60. data/app/models/spree/shipping_rate.rb +0 -2
  61. data/app/models/spree/state.rb +0 -4
  62. data/app/models/spree/stock/simple_coordinator.rb +1 -20
  63. data/app/models/spree/stock/splitter/base.rb +2 -7
  64. data/app/models/spree/stock_item.rb +1 -7
  65. data/app/models/spree/store.rb +0 -12
  66. data/app/models/spree/store_credit.rb +0 -8
  67. data/app/models/spree/store_credit_category.rb +0 -32
  68. data/app/models/spree/tax_calculator/shipping_rate.rb +1 -12
  69. data/app/models/spree/tax_rate.rb +0 -27
  70. data/app/models/spree/taxon/active_storage_attachment.rb +0 -5
  71. data/app/models/spree/taxon/paperclip_attachment.rb +0 -5
  72. data/app/models/spree/taxon.rb +0 -11
  73. data/app/models/spree/user_address.rb +0 -5
  74. data/app/models/spree/variant.rb +2 -46
  75. data/config/locales/en.yml +0 -8
  76. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
  77. data/lib/generators/solidus/install/install_generator.rb +13 -2
  78. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +3 -39
  79. data/lib/generators/spree/dummy/dummy_generator.rb +2 -1
  80. data/lib/generators/spree/dummy/templates/rails/database.yml +6 -1
  81. data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
  82. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  83. data/lib/spree/app_configuration.rb +6 -89
  84. data/lib/spree/core/class_constantizer.rb +2 -0
  85. data/lib/spree/core/controller_helpers/auth.rb +1 -14
  86. data/lib/spree/core/controller_helpers/order.rb +2 -22
  87. data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
  88. data/lib/spree/core/controller_helpers/pricing.rb +0 -8
  89. data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
  90. data/lib/spree/core/engine.rb +0 -49
  91. data/lib/spree/core/environment_extension.rb +0 -9
  92. data/lib/spree/core/product_filters.rb +0 -40
  93. data/lib/spree/core/role_configuration.rb +0 -14
  94. data/lib/spree/core/search/base.rb +0 -26
  95. data/lib/spree/core/state_machines.rb +2 -11
  96. data/lib/spree/core/validators/email.rb +1 -1
  97. data/lib/spree/core/version.rb +1 -1
  98. data/lib/spree/core.rb +9 -8
  99. data/lib/spree/event/configuration.rb +0 -5
  100. data/lib/spree/event/subscriber.rb +0 -18
  101. data/lib/spree/event/subscriber_registry.rb +3 -1
  102. data/lib/spree/event.rb +0 -31
  103. data/lib/spree/i18n.rb +0 -22
  104. data/lib/spree/money.rb +3 -18
  105. data/lib/spree/permitted_attributes.rb +3 -60
  106. data/lib/spree/testing_support/blacklist_urls.rb +1 -1
  107. data/lib/spree/testing_support/capybara_ext.rb +0 -30
  108. data/lib/spree/testing_support/controller_requests.rb +0 -82
  109. data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
  110. data/lib/spree/testing_support/dummy_app.rb +6 -16
  111. data/lib/spree/testing_support/factories/order_factory.rb +0 -1
  112. data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
  113. data/lib/spree/testing_support/factories/user_factory.rb +0 -6
  114. data/lib/spree/testing_support/order_walkthrough.rb +0 -3
  115. data/lib/spree/testing_support/preferences.rb +0 -25
  116. data/lib/spree/testing_support.rb +1 -1
  117. data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +20 -15
  118. data/solidus_core.gemspec +1 -25
  119. metadata +9 -94
  120. data/app/mailers/spree/test_mailer.rb +0 -13
  121. data/app/models/concerns/spree/user_payment_source.rb +0 -26
  122. data/app/models/spree/calculator/free_shipping.rb +0 -22
  123. data/app/models/spree/calculator/percent_per_item.rb +0 -51
  124. data/app/models/spree/calculator/price_sack.rb +0 -28
  125. data/app/models/spree/gateway/bogus.rb +0 -13
  126. data/app/models/spree/gateway/bogus_simple.rb +0 -13
  127. data/app/models/spree/gateway.rb +0 -14
  128. data/app/models/spree/order/checkout.rb +0 -244
  129. data/app/models/spree/order_capturing.rb +0 -50
  130. data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
  131. data/lib/generators/spree/install/install_generator.rb +0 -15
  132. data/lib/solidus/migrations/rename_gateways.rb +0 -41
  133. data/lib/spree/core/current_store.rb +0 -24
  134. data/lib/spree/paranoia_deprecations.rb +0 -41
  135. data/lib/spree/preferences/persistable.rb +0 -23
  136. data/lib/spree/promo/environment.rb +0 -12
  137. data/lib/spree/testing_support/bar_ability.rb +0 -19
  138. data/lib/spree/testing_support/fixtures/file.txt +0 -1
  139. data/lib/tasks/core.rake +0 -104
  140. data/lib/tasks/email.rake +0 -12
  141. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
  142. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
  143. data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
  144. data/lib/tasks/migrations/rename_gateways.rake +0 -23
  145. data/lib/tasks/order_capturing.rake +0 -27
  146. data/lib/tasks/solidus/check_orders_with_invalid_email.rake +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78b3a6c05e492d60c9690e028991c934d4a2aa33788de045110a62b28924bbcb
4
- data.tar.gz: 79213862902521b83cfa4dc56c9f6c59bc79cd6c73920145a53b1a67d3cb1eb2
3
+ metadata.gz: 35ced6fd29e1822a14a86b637243c871d373b2ead2d575e7737d0fa35907a48d
4
+ data.tar.gz: ab72677886bf4ce7c2ba48dbe711fe73aa5e1193d990fb4d7cd872035e247f33
5
5
  SHA512:
6
- metadata.gz: 18eac571ddd52378a9b186a8f18f8eccb7c0825e9d966926106ccfc07e25792ce0d4081b22175e671638bd1ccf98fd5292328887fa5872075690ddd3c1488fba
7
- data.tar.gz: b2c25455b49e633a5b9388d92d2dd6d4bbc22a394f8c8d2eb81deb3e0c04e5fdc8e9a7916f9b4dfe97df2724f0607eb8b3fcaf9542e54e441752efdcf74d91a0
6
+ metadata.gz: 1b18d6067bfbe97ce226fd82fb9a48da5e16eadeef3ac3b758c7d159dc079aef8880396a2acb9c0e23f98953d331f8161ba3271f780c21de04c1f9e501b1136b
7
+ data.tar.gz: 5cc4ad46294a842daa2850e785d08dbfa4f01b28f5806449457fb498898c557866590ed7d332888d6c5fae72ae1ee81fbf3d4fa1ead5aa682af226debce6a890
@@ -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)
@@ -9,9 +9,11 @@ module Spree
9
9
  class Attachment
10
10
  delegate_missing_to :@attachment
11
11
 
12
+ DEFAULT_SIZE = '100%'
13
+
12
14
  def initialize(attachment, styles: {})
13
15
  @attachment = attachment
14
- @styles = normalize_styles(styles)
16
+ @styles = styles
15
17
  end
16
18
 
17
19
  def exists?
@@ -19,20 +21,20 @@ module Spree
19
21
  end
20
22
 
21
23
  def filename
22
- blob&.filename.to_s
24
+ blob.filename.to_s
23
25
  end
24
26
 
25
27
  def url(style = nil)
26
- variant(style)&.url
28
+ variant(style).url
27
29
  end
28
30
 
29
31
  def variant(style = nil)
30
- size = style_to_size(style)
32
+ size = style_to_size(style&.to_sym)
31
33
  @attachment.variant(
32
- resize_to_limit: size,
33
- saver: {
34
- strip: true
35
- }
34
+ resize: size,
35
+ strip: true,
36
+ 'auto-orient': true,
37
+ colorspace: 'sRGB',
36
38
  ).processed
37
39
  end
38
40
 
@@ -59,12 +61,8 @@ module Spree
59
61
  @attachment.metadata
60
62
  end
61
63
 
62
- def normalize_styles(styles)
63
- styles.transform_values { |v| v.split('x').map(&:to_i) }
64
- end
65
-
66
64
  def style_to_size(style)
67
- @styles.fetch(style&.to_sym) { [width, height] }
65
+ @styles.fetch(style) { DEFAULT_SIZE }
68
66
  end
69
67
  end
70
68
  end
@@ -107,8 +107,6 @@ module Spree
107
107
 
108
108
  def url(style = default_style)
109
109
  attachment.url(style)
110
- rescue ActiveStorage::FileNotFoundError
111
- "noimage/#{style}.png"
112
110
  end
113
111
 
114
112
  def destroy_attachment(_name)
@@ -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,24 +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
- base.delete("name") unless Spree::Config.use_combined_first_and_last_name_in_address
88
-
89
- name_from_attributes = Spree::Address::Name.from_attributes(base)
90
- if base['firstname'].presence || base['first_name'].presence
91
- base['firstname'] = name_from_attributes.first_name
92
- end
93
- if base['lastname'].presence || base['last_name'].presence
94
- base['lastname'] = name_from_attributes.last_name
95
- end
96
-
97
- virtual_name = name_from_attributes.value
98
- if base['name'].blank? && virtual_name.present?
99
- base['name'] = virtual_name
100
- end
101
-
102
- excluded_attributes = DB_ONLY_ATTRS + %w(first_name last_name)
103
-
104
- base.except(*excluded_attributes)
66
+ base.except(*DB_ONLY_ATTRS)
105
67
  end
106
68
 
107
69
  # @return [Hash] hash of attributes contributing to value equality
@@ -127,36 +89,7 @@ module Spree
127
89
  # @return [Boolean] true if the two addresses have the same address fields
128
90
  def ==(other_address)
129
91
  return false unless other_address && other_address.respond_to?(:value_attributes)
130
- if Spree::Config.use_combined_first_and_last_name_in_address
131
- value_attributes.except(*LEGACY_NAME_ATTRS) == other_address.value_attributes.except(*LEGACY_NAME_ATTRS)
132
- else
133
- value_attributes == other_address.value_attributes
134
- end
135
- end
136
-
137
- # @deprecated Do not use this. Use Address.== instead.
138
- def same_as?(other_address)
139
- Spree::Deprecation.warn("Address#same_as? is deprecated. It's equivalent to Address.==", caller)
140
- self == other_address
141
- end
142
-
143
- # @deprecated Do not use this. Use Address.== instead.
144
- def same_as(other_address)
145
- Spree::Deprecation.warn("Address#same_as is deprecated. It's equivalent to Address.==", caller)
146
- self == other_address
147
- end
148
-
149
- # @deprecated Do not use this
150
- def empty?
151
- Spree::Deprecation.warn("Address#empty? is deprecated.", caller)
152
- attributes.except('id', 'created_at', 'updated_at', 'country_id').all? { |_, value| value.nil? }
153
- end
154
-
155
- # This exists because the default Object#blank?, checks empty? if it is
156
- # defined, and we have defined empty.
157
- # This should be removed once empty? is removed
158
- def blank?
159
- false
92
+ value_attributes == other_address.value_attributes
160
93
  end
161
94
 
162
95
  # @return [Hash] an ActiveMerchant compatible address hash
@@ -203,117 +136,5 @@ module Spree
203
136
  def country_iso
204
137
  country && country.iso
205
138
  end
206
-
207
- before_save :set_name_from_firstname_and_lastname
208
-
209
- def set_name_from_firstname_and_lastname
210
- name_from_firstname_and_lastname = Spree::Address::Name.from_attributes(attributes.except(:name, 'name'))
211
-
212
- if read_attribute(:name).blank? && name_from_firstname_and_lastname.present?
213
- write_attribute(:name, name_from_firstname_and_lastname)
214
- end
215
- end
216
-
217
- # @return [String] the full name on this address
218
- def name
219
- self[:name] || begin
220
- Spree::Address::Name.new(
221
- read_attribute(:firstname),
222
- read_attribute(:lastname)
223
- ).value
224
- end
225
- end
226
-
227
- def name=(value)
228
- return if value.nil?
229
-
230
- write_attribute(:name, value)
231
- name_from_value = Spree::Address::Name.new(value)
232
- write_attribute(:firstname, name_from_value.first_name)
233
- write_attribute(:lastname, name_from_value.last_name)
234
- end
235
-
236
- def as_json(options = {})
237
- if Spree::Config.use_combined_first_and_last_name_in_address
238
- super(options.merge(except: LEGACY_NAME_ATTRS)).tap do |hash|
239
- hash['name'] = name
240
- end
241
- else
242
- super
243
- end
244
- end
245
-
246
- private
247
-
248
- def validate_name
249
- return if name.present?
250
-
251
- name_attribute = if Spree::Config.use_combined_first_and_last_name_in_address
252
- :name
253
- else
254
- :firstname
255
- end
256
- errors.add(name_attribute, :blank)
257
- end
258
-
259
- def state_validate
260
- unless @silence_state_deprecations
261
- Spree::Deprecation.warn \
262
- "#{self.class}#state_validate private method has been deprecated" \
263
- " and will be removed in Solidus v3." \
264
- " Check https://github.com/solidusio/solidus/pull/3129 for more details.",
265
- caller
266
- end
267
-
268
- # Skip state validation without country (also required)
269
- # or when disabled by preference
270
- return if country.blank? || !Spree::Config[:address_requires_state]
271
- return unless country.states_required
272
-
273
- # ensure associated state belongs to country
274
- if state.present?
275
- if state.country == country
276
- self.state_name = nil # not required as we have a valid state and country combo
277
- elsif state_name.present?
278
- self.state = nil
279
- else
280
- errors.add(:state, :invalid)
281
- end
282
- end
283
-
284
- # ensure state_name belongs to country without states, or that it matches a predefined state name/abbr
285
- if state_name.present?
286
- if country.states.present?
287
- states = country.states.with_name_or_abbr(state_name)
288
-
289
- if states.size == 1
290
- self.state = states.first
291
- self.state_name = nil
292
- else
293
- errors.add(:state, :invalid)
294
- end
295
- end
296
- end
297
-
298
- # ensure at least one state field is populated
299
- errors.add :state, :blank if state.blank? && state_name.blank?
300
- end
301
-
302
- def validate_state_matches_country
303
- unless @silence_state_deprecations
304
- Spree::Deprecation.warn \
305
- "#{self.class}#validate_state_matches_country private method has been deprecated" \
306
- " and will be removed in Solidus v3." \
307
- " Check https://github.com/solidusio/solidus/pull/3129 for more details.",
308
- caller
309
- end
310
-
311
- return unless country
312
-
313
- self.state = nil if country.states.empty?
314
- if state && state.country != country
315
- errors.add(:state, :does_not_match_country)
316
- end
317
- end
318
139
  end
319
140
  end