spree_core 3.7.14.1 → 4.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/app/controllers/spree/base_controller.rb +0 -1
  4. data/app/finders/spree/taxons/find.rb +6 -5
  5. data/app/helpers/spree/base_helper.rb +0 -9
  6. data/app/helpers/spree/products_helper.rb +1 -1
  7. data/app/models/concerns/spree/product_scopes.rb +254 -0
  8. data/app/models/concerns/spree/user_address.rb +5 -2
  9. data/app/models/friendly_id/slug_decorator.rb +8 -2
  10. data/app/models/spree/ability.rb +21 -22
  11. data/app/models/spree/address.rb +37 -24
  12. data/app/models/spree/adjustment.rb +0 -10
  13. data/app/models/spree/app_dependencies.rb +2 -2
  14. data/app/models/spree/asset.rb +1 -12
  15. data/app/models/spree/country.rb +2 -2
  16. data/app/models/spree/credit_card.rb +4 -5
  17. data/app/models/spree/gateway/bogus.rb +1 -1
  18. data/app/models/spree/image.rb +8 -1
  19. data/app/models/spree/image/configuration/active_storage.rb +0 -2
  20. data/app/models/spree/order.rb +13 -78
  21. data/app/models/spree/order/address_book.rb +86 -0
  22. data/app/models/spree/order/checkout.rb +4 -22
  23. data/app/models/spree/order/currency_updater.rb +1 -1
  24. data/app/models/spree/order/store_credit.rb +0 -18
  25. data/app/models/spree/order_merger.rb +1 -0
  26. data/app/models/spree/payment.rb +4 -2
  27. data/app/models/spree/payment/gateway_options.rb +1 -1
  28. data/app/models/spree/payment/processing.rb +2 -0
  29. data/app/models/spree/preferences/configuration.rb +1 -1
  30. data/app/models/spree/preferences/preferable.rb +1 -1
  31. data/app/models/spree/product.rb +2 -3
  32. data/app/models/spree/promotion_handler/coupon.rb +2 -1
  33. data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
  34. data/app/models/spree/return_item.rb +1 -1
  35. data/app/models/spree/return_item/eligibility_validator/default.rb +2 -0
  36. data/app/models/spree/return_item/eligibility_validator/{rma_required.rb → r_m_a_required.rb} +0 -0
  37. data/app/models/spree/shipment.rb +1 -1
  38. data/app/models/spree/store_credit.rb +4 -5
  39. data/app/models/spree/taxon_image.rb +1 -1
  40. data/app/models/spree/taxonomy.rb +1 -1
  41. data/app/services/spree/cart/add_item.rb +3 -1
  42. data/app/services/spree/cart/update.rb +1 -1
  43. data/config/locales/en.yml +15 -0
  44. data/db/default/spree/stores.rb +1 -0
  45. data/db/default/spree/zones.rb +16 -0
  46. data/db/migrate/20140806144901_add_type_to_reimbursement_type.rb +1 -1
  47. data/db/migrate/20141101231208_fix_adjustment_order_presence.rb +2 -2
  48. data/db/migrate/20170323151450_add_missing_unique_indexes_for_unique_attributes.rb +1 -1
  49. data/db/migrate/20190305121659_add_iso_and_iso3_validation_on_presence_and_uniqueness.rb +18 -0
  50. data/db/migrate/20190523092729_add_user_id_and_deleted_at_to_spree_addresses.rb +12 -0
  51. data/lib/generators/spree/dummy/dummy_generator.rb +3 -1
  52. data/lib/spree/core.rb +0 -2
  53. data/lib/spree/core/importer/order.rb +64 -103
  54. data/lib/spree/core/importer/product.rb +2 -2
  55. data/lib/spree/core/product_duplicator.rb +1 -5
  56. data/lib/spree/core/version.rb +1 -3
  57. data/lib/spree/permitted_attributes.rb +3 -1
  58. data/lib/spree/testing_support/ability_helpers.rb +3 -11
  59. data/lib/spree/testing_support/capybara_config.rb +4 -1
  60. data/lib/spree/testing_support/capybara_ext.rb +22 -98
  61. data/lib/spree/testing_support/controller_requests.rb +36 -26
  62. data/lib/spree/testing_support/factories/image_factory.rb +2 -6
  63. data/lib/spree/testing_support/factories/return_item_factory.rb +2 -2
  64. data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
  65. data/lib/spree/testing_support/i18n.rb +6 -8
  66. data/lib/spree/testing_support/image_helpers.rb +5 -11
  67. data/lib/tasks/exchanges.rake +35 -37
  68. data/spree_core.gemspec +11 -14
  69. metadata +63 -103
  70. data/app/models/concerns/spree/acts_as_taggable.rb +0 -11
  71. data/app/models/spree/image/configuration/paperclip.rb +0 -64
  72. data/app/models/spree/order_contents.rb +0 -54
  73. data/app/models/spree/product/scopes.rb +0 -250
  74. data/app/models/spree/tag.rb +0 -4
  75. data/app/models/spree/taxon_image/configuration/paperclip.rb +0 -27
  76. data/config/initializers/acts_as_taggable_on.rb +0 -9
  77. data/config/initializers/use_paperclip.rb +0 -3
  78. data/db/migrate/20160511071954_acts_as_taggable_on_spree_migration.rb +0 -40
  79. data/db/migrate/20160511072249_change_collation_for_spree_tag_names.rb +0 -9
  80. data/db/migrate/20160511072335_add_missing_indexes_to_spree_taggings.rb +0 -14
  81. data/lib/spree/core/controller_helpers/respond_with.rb +0 -67
  82. data/lib/spree/responder.rb +0 -44
  83. data/lib/spree/testing_support/factories/tag_factory.rb +0 -5
@@ -48,16 +48,6 @@ module Spree
48
48
 
49
49
  self.competing_promos_source_types = ['Spree::PromotionAction']
50
50
 
51
- scope :open, -> {
52
- ActiveSupport::Deprecation.warn 'Adjustment.open is deprecated. Please use Adjustment.not_finalized instead', caller
53
- not_finalized
54
- }
55
-
56
- scope :closed, -> {
57
- ActiveSupport::Deprecation.warn 'Adjustment.closed is deprecated. Please use Adjustment.finalized instead', caller
58
- finalized
59
- }
60
-
61
51
  scope :not_finalized, -> { where(state: 'open') }
62
52
  scope :finalized, -> { where(state: 'closed') }
63
53
  scope :tax, -> { where(source_type: 'Spree::TaxRate') }
@@ -17,14 +17,14 @@ module Spree
17
17
  attr_accessor *INJECTION_POINTS
18
18
 
19
19
  def initialize
20
- set_default_abitily
20
+ set_default_ability
21
21
  set_default_services
22
22
  set_default_finders
23
23
  end
24
24
 
25
25
  private
26
26
 
27
- def set_default_abitily
27
+ def set_default_ability
28
28
  @ability_class = 'Spree::Ability'
29
29
  end
30
30
 
@@ -1,17 +1,6 @@
1
1
  module Spree
2
- if Rails.application.config.use_paperclip
3
- ActiveSupport::Deprecation.warn(<<-EOS, caller)
4
- Paperclip support is deprecated, and will be removed in Spree 4.0.
5
- Please migrate to ActiveStorage, to avoid problems after update
6
- https://github.com/thoughtbot/paperclip/blob/master/MIGRATING.md
7
- EOS
8
- Paperclip.interpolates :viewable_id do |attachment, _style|
9
- attachment.instance.viewable_id
10
- end
11
- end
12
-
13
2
  class Asset < Spree::Base
14
- include Support::ActiveStorage unless Rails.application.config.use_paperclip
3
+ include Support::ActiveStorage
15
4
 
16
5
  belongs_to :viewable, polymorphic: true, touch: true
17
6
  acts_as_list scope: [:viewable_id, :viewable_type]
@@ -4,8 +4,8 @@ module Spree
4
4
  # https://github.com/rails/rails/issues/3458
5
5
  before_destroy :ensure_not_default
6
6
 
7
- has_many :states, dependent: :destroy
8
7
  has_many :addresses, dependent: :restrict_with_error
8
+ has_many :states, dependent: :destroy
9
9
  has_many :zone_members,
10
10
  -> { where(zoneable_type: 'Spree::Country') },
11
11
  class_name: 'Spree::ZoneMember',
@@ -14,7 +14,7 @@ module Spree
14
14
 
15
15
  has_many :zones, through: :zone_members, class_name: 'Spree::Zone'
16
16
 
17
- validates :name, :iso_name, presence: true, uniqueness: { case_sensitive: false }
17
+ validates :name, :iso_name, :iso, :iso3, presence: true, uniqueness: { case_sensitive: false }
18
18
 
19
19
  def self.default
20
20
  country_id = Spree::Config[:default_country_id]
@@ -24,9 +24,10 @@ module Spree
24
24
  attribute :month, ActiveRecord::Type::Integer.new
25
25
  attribute :year, ActiveRecord::Type::Integer.new
26
26
 
27
- attr_reader :number, :verification_value
27
+ attr_reader :number
28
28
  attr_accessor :encrypted_data,
29
29
  :imported,
30
+ :verification_value,
30
31
  :manual_entry
31
32
 
32
33
  with_options if: :require_card_numbers?, on: :create do
@@ -100,11 +101,9 @@ module Spree
100
101
  end
101
102
  end
102
103
 
103
- def verification_value=(value)
104
- @verification_value = value.to_s.gsub(/\s/, '')
105
- end
106
-
107
104
  def set_last_digits
105
+ number.to_s.gsub!(/\s/, '')
106
+ verification_value.to_s.gsub!(/\s/, '')
108
107
  self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1)
109
108
  end
110
109
 
@@ -22,7 +22,7 @@ module Spree
22
22
 
23
23
  # simulate the storage of credit card profile using remote service
24
24
  if success = VALID_CCS.include?(payment.source.number)
25
- payment.source.update_attributes(gateway_customer_profile_id: generate_profile_id(success))
25
+ payment.source.update(gateway_customer_profile_id: generate_profile_id(success))
26
26
  end
27
27
  end
28
28
 
@@ -1,7 +1,14 @@
1
1
  module Spree
2
2
  class Image < Asset
3
- include Rails.application.config.use_paperclip ? Configuration::Paperclip : Configuration::ActiveStorage
3
+ include Configuration::ActiveStorage
4
4
  include Rails.application.routes.url_helpers
5
+
6
+ # In Rails 5.x class constants are being undefined/redefined during the code reloading process
7
+ # in a rails development environment, after which the actual ruby objects stored in those class constants
8
+ # are no longer equal (subclass == self) what causes error ActiveRecord::SubclassNotFound
9
+ # Invalid single-table inheritance type: Spree::Image is not a subclass of Spree::Image.
10
+ # The line below prevents the error.
11
+ self.inheritance_column = nil
5
12
 
6
13
  def styles
7
14
  self.class.styles.map do |_, size|
@@ -29,14 +29,12 @@ module Spree
29
29
 
30
30
  def check_attachment_presence
31
31
  unless attachment.attached?
32
- attachment.purge
33
32
  errors.add(:attachment, :attachment_must_be_present)
34
33
  end
35
34
  end
36
35
 
37
36
  def check_attachment_content_type
38
37
  if attachment.attached? && !attachment.content_type.in?(accepted_image_types)
39
- attachment.purge
40
38
  errors.add(:attachment, :not_allowed_content_type)
41
39
  end
42
40
  end
@@ -1,4 +1,7 @@
1
1
  require_dependency 'spree/order/checkout'
2
+ require_dependency 'spree/order/currency_updater'
3
+ require_dependency 'spree/order/payments'
4
+ require_dependency 'spree/order/store_credit'
2
5
 
3
6
  module Spree
4
7
  class Order < Spree::Base
@@ -9,6 +12,7 @@ module Spree
9
12
  include Spree::Order::CurrencyUpdater
10
13
  include Spree::Order::Payments
11
14
  include Spree::Order::StoreCredit
15
+ include Spree::Order::AddressBook
12
16
  include Spree::Core::NumberGenerator.new(prefix: 'R')
13
17
  include Spree::Core::TokenGenerator
14
18
 
@@ -22,30 +26,6 @@ module Spree
22
26
  alias display_ship_total display_shipment_total
23
27
  alias_attribute :ship_total, :shipment_total
24
28
 
25
- def guest_token
26
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
27
- Order#guest_token is deprecated and will be removed in Spree 4.0. Please use Order#token instead
28
- DEPRECATION
29
-
30
- token
31
- end
32
-
33
- def guest_token?
34
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
35
- Order#guest_token? is deprecated and will be removed in Spree 4.0. Please use Order#token? instead
36
- DEPRECATION
37
-
38
- token?
39
- end
40
-
41
- def guest_token=(value)
42
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
43
- Order#guest_token= is deprecated and will be removed in Spree 4.0. Please use Order#token= instead
44
- DEPRECATION
45
-
46
- self.token = value
47
- end
48
-
49
29
  MONEY_THRESHOLD = 100_000_000
50
30
  MONEY_VALIDATION = {
51
31
  presence: true,
@@ -93,11 +73,11 @@ module Spree
93
73
  end
94
74
 
95
75
  belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address',
96
- optional: true
76
+ optional: true, dependent: :destroy
97
77
  alias_attribute :billing_address, :bill_address
98
78
 
99
79
  belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address',
100
- optional: true
80
+ optional: true, dependent: :destroy
101
81
  alias_attribute :shipping_address, :ship_address
102
82
 
103
83
  belongs_to :store, class_name: 'Spree::Store'
@@ -186,17 +166,6 @@ module Spree
186
166
  update_hooks.add(hook)
187
167
  end
188
168
 
189
- # Use this method in other gems that wish to register their own custom logic
190
- # that should be called when determining if two line items are equal.
191
- def self.register_line_item_comparison_hook(hook)
192
- ActiveSupport::Deprecation.warn(<<-EOS, caller)
193
- Order.register_line_item_comparison_hook is deprecated and will be removed in Spree 4.0. Please use
194
- `Rails.application.config.spree.line_item_comparison_hooks << hook` instead.
195
- EOS
196
-
197
- Rails.application.config.spree.line_item_comparison_hooks << hook
198
- end
199
-
200
169
  # For compatiblity with Calculator::PriceSack
201
170
  def amount
202
171
  line_items.inject(0.0) { |sum, li| sum + li.amount }
@@ -265,15 +234,6 @@ module Spree
265
234
  @merger ||= Spree::OrderMerger.new(self)
266
235
  end
267
236
 
268
- def clone_billing_address
269
- if bill_address && ship_address.nil?
270
- self.ship_address = bill_address.clone
271
- else
272
- ship_address.attributes = bill_address.attributes.except('id', 'updated_at', 'created_at')
273
- end
274
- true
275
- end
276
-
277
237
  def ensure_store_presence
278
238
  self.store ||= Spree::Store.default
279
239
  end
@@ -288,10 +248,6 @@ module Spree
288
248
  inventory_units.all?(&:returned?)
289
249
  end
290
250
 
291
- def contents
292
- @contents ||= Spree::OrderContents.new(self)
293
- end
294
-
295
251
  # Associates the specified user with the order.
296
252
  def associate_user!(user, override_email = true)
297
253
  self.user = user
@@ -315,29 +271,10 @@ module Spree
315
271
  def find_line_item_by_variant(variant, options = {})
316
272
  line_items.detect do |line_item|
317
273
  line_item.variant_id == variant.id &&
318
- line_item_options_match(line_item, options)
274
+ Spree::Dependencies.cart_compare_line_items_service.constantize.new.call(order: self, line_item: line_item, options: options).value
319
275
  end
320
276
  end
321
277
 
322
- # This method enables extensions to participate in the
323
- # "Are these line items equal" decision.
324
- #
325
- # When adding to cart, an extension would send something like:
326
- # params[:product_customizations]={...}
327
- #
328
- # and would provide:
329
- #
330
- # def product_customizations_match
331
- def line_item_options_match(line_item, options)
332
- ActiveSupport::Deprecation.warn(<<-EOS, caller)
333
- Order#add is deprecated and will be removed in Spree 4.0. Please use
334
- Spree::CompareLineItems service instead.
335
- EOS
336
- return true unless options
337
-
338
- Spree::Dependencies.cart_compare_line_items_service.constantize.new.call(order: self, line_item: line_item, options: options).value
339
- end
340
-
341
278
  # Creates new tax charges if there are any applicable rates. If prices already
342
279
  # include taxes then price adjustments are created instead.
343
280
  def create_tax_charge!
@@ -540,9 +477,15 @@ module Spree
540
477
  def apply_free_shipping_promotions
541
478
  Spree::PromotionHandler::FreeShipping.new(self).activate
542
479
  shipments.each { |shipment| Spree::Adjustable::AdjustmentsUpdater.update(shipment) }
480
+ create_shipment_tax_charge!
543
481
  update_with_updater!
544
482
  end
545
483
 
484
+ # Applies user promotions when login after filling the cart
485
+ def apply_unassigned_promotions
486
+ ::Spree::PromotionHandler::Cart.new(self).activate
487
+ end
488
+
546
489
  # Clean shipments and make order back to address state
547
490
  #
548
491
  # At some point the might need to force the order to transition from address
@@ -728,14 +671,6 @@ module Spree
728
671
  self.currency ||= store.default_currency || Spree::Config[:currency]
729
672
  end
730
673
 
731
- def set_currency
732
- ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
733
- Spree::Order#set_currency was renamed to Spree::Order#ensure_currency_presence
734
- and will be removed in Spree 4.0. Please update your code to avoid problems after update
735
- DEPRECATION
736
- ensure_currency_presence
737
- end
738
-
739
674
  def create_token
740
675
  self.token ||= generate_token
741
676
  end
@@ -0,0 +1,86 @@
1
+ # https://github.com/spree-contrib/spree_address_book/blob/master/app/models/spree/order_decorator.rb
2
+ module Spree
3
+ class Order < Spree::Base
4
+ module AddressBook
5
+ extend ActiveSupport::Concern
6
+
7
+ def clone_shipping_address
8
+ if ship_address
9
+ self.bill_address = ship_address
10
+ end
11
+ true
12
+ end
13
+
14
+ def clone_billing_address
15
+ if bill_address
16
+ self.ship_address = bill_address
17
+ end
18
+ true
19
+ end
20
+
21
+ def bill_address_id=(id)
22
+ address = Spree::Address.find_by(id: id)
23
+ if address && address.user_id == user_id
24
+ self['bill_address_id'] = address.id
25
+ user.update_attribute(:bill_address_id, address.id)
26
+ bill_address.reload
27
+ else
28
+ self['bill_address_id'] = nil
29
+ end
30
+ end
31
+
32
+ def bill_address_attributes=(attributes)
33
+ self.bill_address = update_or_create_address(attributes)
34
+ user.bill_address = bill_address if user
35
+ end
36
+
37
+ def ship_address_id=(id)
38
+ address = Spree::Address.find_by(id: id)
39
+ if address && address.user_id == user_id
40
+ self['ship_address_id'] = address.id
41
+ user.update_attribute(:ship_address_id, address.id)
42
+ ship_address.reload
43
+ else
44
+ self['ship_address_id'] = nil
45
+ end
46
+ end
47
+
48
+ def ship_address_attributes=(attributes)
49
+ self.ship_address = update_or_create_address(attributes)
50
+ user.ship_address = ship_address if user
51
+ end
52
+
53
+ private
54
+
55
+ def update_or_create_address(attributes = {})
56
+ return if attributes.blank?
57
+
58
+ attributes = attributes.select { |_k, v| v.present? }
59
+
60
+ if user
61
+ address = user.addresses.build(attributes.except(:id)).check
62
+ return address if address.id
63
+ end
64
+
65
+ if attributes[:id]
66
+ address = Spree::Address.find(attributes[:id])
67
+ attributes.delete(:id)
68
+
69
+ if address&.editable?
70
+ address.update_attributes(attributes)
71
+ return address
72
+ else
73
+ attributes.delete(:id)
74
+ end
75
+ end
76
+
77
+ unless attributes[:id]
78
+ address = Spree::Address.new(attributes)
79
+ address.save
80
+ end
81
+
82
+ address
83
+ end
84
+ end
85
+ end
86
+ end
@@ -94,7 +94,6 @@ module Spree
94
94
  before_transition from: :address, do: :update_line_item_prices!
95
95
  before_transition from: :address, do: :create_tax_charge!
96
96
  before_transition to: :address, do: :assign_default_addresses!
97
- before_transition from: :address, do: :persist_user_address!
98
97
  end
99
98
 
100
99
  if states[:delivery]
@@ -103,6 +102,7 @@ module Spree
103
102
  before_transition to: :delivery, do: :set_shipments_cost
104
103
  before_transition to: :delivery, do: :create_shipment_tax_charge!
105
104
  before_transition from: :delivery, do: :apply_free_shipping_promotions
105
+ before_transition to: :delivery, do: :apply_unassigned_promotions
106
106
  end
107
107
 
108
108
  before_transition to: :resumed, do: :ensure_line_item_variants_are_not_discontinued
@@ -246,7 +246,7 @@ module Spree
246
246
  attributes[:payments_attributes].first[:request_env] = request_env
247
247
  end
248
248
 
249
- success = update_attributes(attributes)
249
+ success = update(attributes)
250
250
  set_shipments_cost if shipments.any?
251
251
  end
252
252
 
@@ -256,31 +256,13 @@ module Spree
256
256
 
257
257
  def assign_default_addresses!
258
258
  if user
259
- clone_billing
259
+ self.bill_address = user.bill_address if !bill_address_id && user.bill_address&.valid?
260
260
  # Skip setting ship address if order doesn't have a delivery checkout step
261
261
  # to avoid triggering validations on shipping address
262
- clone_shipping if checkout_steps.include?('delivery')
262
+ self.ship_address = user.ship_address if !ship_address_id && user.ship_address&.valid? && checkout_steps.include?('delivery')
263
263
  end
264
264
  end
265
265
 
266
- def clone_billing
267
- return unless !bill_address_id && user.bill_address.try(:valid?)
268
-
269
- self.bill_address = user.bill_address.try(:clone)
270
- end
271
-
272
- def clone_shipping
273
- return unless !ship_address_id && user.ship_address.try(:valid?)
274
-
275
- self.ship_address = user.ship_address.try(:clone)
276
- end
277
-
278
- def persist_user_address!
279
- return unless !temporary_address && user && user.respond_to?(:persist_order_address) && bill_address_id
280
-
281
- user.persist_order_address(self)
282
- end
283
-
284
266
  def persist_user_credit_card
285
267
  return unless !temporary_credit_card && user_id && valid_credit_cards.present?
286
268