spree_core 3.7.0.rc1 → 3.7.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49eb4666a35ce5b88c3ce5bc92b0cf34503851edee70623f215bc674ea3d322f
4
- data.tar.gz: cefaa50b133701b0572392a03c11bdf4544e9ca97aa0eaa34e5293cd2892336f
3
+ metadata.gz: b7124c86a59c0fdd43a117c2765d9d7253de04054cef1c787934ce48abf06c9c
4
+ data.tar.gz: 3c00c9709cd38461a3aeeff347a2377482766c54501d3a91bf8cc429d043a52c
5
5
  SHA512:
6
- metadata.gz: 1d422e99c814605fe9cbb9ce7eaf3bedd80e93f6298446bd6a9b30cc8d1d3d8e8d870926222aa437bb6d58a0ec725bfb1192a0d28c48c1cadc9a97e0dd3d504d
7
- data.tar.gz: caf99f8ededb70977b1e1eba5adcaff62a60108d62b469b82d885921539f8acc1f84528a9161d28f48f7f6ab7755e866eb34392df936904dc1aaaa29a59becf6
6
+ metadata.gz: 33c2354b25887911fef568f618c9d0316cfbda57bb0839ab2b3172e7a8f72ba798b8fce7bc7e2354ca2c913444647b2b44c885cd60a605196279ada234fd3242
7
+ data.tar.gz: d62478a37f518d87cf21a7caec39d9a12314c1532bfa7cba161a5c1945077588ddec70ff741ba77445bd9c7290021853809accc423abf0f4c606ce9b1904607c
@@ -0,0 +1,69 @@
1
+ module Spree
2
+ module Orders
3
+ class FindComplete
4
+ attr_reader :user, :number, :token
5
+
6
+ def initialize(user: nil, number: nil, token: nil)
7
+ @user = user
8
+ @number = number
9
+ @token = token
10
+ end
11
+
12
+ def execute
13
+ orders = by_user(scope)
14
+ orders = by_number(orders)
15
+ orders = by_token(orders)
16
+
17
+ orders
18
+ end
19
+
20
+ private
21
+
22
+ def scope
23
+ user? ? user.orders.complete.includes(scope_includes) : Spree::Order.complete.includes(scope_includes)
24
+ end
25
+
26
+ def user?
27
+ user.present?
28
+ end
29
+
30
+ def number?
31
+ number.present?
32
+ end
33
+
34
+ def token?
35
+ token.present?
36
+ end
37
+
38
+ def by_user(orders)
39
+ return orders unless user?
40
+
41
+ orders
42
+ end
43
+
44
+ def by_number(orders)
45
+ return orders unless number?
46
+
47
+ orders.where(number: number)
48
+ end
49
+
50
+ def by_token(orders)
51
+ return orders unless token?
52
+
53
+ orders.where(token: token)
54
+ end
55
+
56
+ def scope_includes
57
+ {
58
+ line_items: [
59
+ variant: [
60
+ :images,
61
+ option_values: :option_type,
62
+ product: :product_properties,
63
+ ]
64
+ ]
65
+ }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -29,8 +29,8 @@ module Spree
29
29
 
30
30
  validate :state_validate, :postal_code_validate
31
31
 
32
- delegate :name, :iso3, to: :country, prefix: true
33
- delegate :abbr, to: :state, prefix: true, allow_nil: true
32
+ delegate :name, :iso3, :iso, :iso_name, to: :country, prefix: true
33
+ delegate :abbr, to: :state, prefix: true, allow_nil: true
34
34
 
35
35
  alias_attribute :first_name, :firstname
36
36
  alias_attribute :last_name, :lastname
@@ -49,6 +49,14 @@ module Spree
49
49
  end
50
50
  end
51
51
 
52
+ def iso_name
53
+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
54
+ Address#iso_name is deprecated and will be removed in Spree 4.0.
55
+ Please use Address#country_iso_name instead
56
+ DEPRECATION
57
+ country_iso_name
58
+ end
59
+
52
60
  def full_name
53
61
  "#{firstname} #{lastname}".strip
54
62
  end
@@ -57,6 +65,10 @@ module Spree
57
65
  state.try(:abbr) || state.try(:name) || state_name
58
66
  end
59
67
 
68
+ def state_name_text
69
+ state_name.present? ? state_name : state&.name
70
+ end
71
+
60
72
  def same_as?(other)
61
73
  ActiveSupport::Deprecation.warn(<<-EOS, caller)
62
74
  Address#same_as? is deprecated and will be removed in Spree 4.0. Please use Address#== instead"
@@ -22,6 +22,10 @@ module Spree
22
22
  default || find_by(iso: 'US') || first
23
23
  end
24
24
 
25
+ def self.by_iso(iso)
26
+ where(['LOWER(iso) = ?', iso.downcase]).or(where(['LOWER(iso3) = ?', iso.downcase])).take
27
+ end
28
+
25
29
  def default?
26
30
  id == Spree::Config[:default_country_id]
27
31
  end
@@ -2,8 +2,11 @@ module Spree
2
2
  class CreditCard < Spree::Base
3
3
  include ActiveMerchant::Billing::CreditCardMethods
4
4
 
5
+ # to migrate safely from older Spree versions that din't provide safe deletion for CCs
6
+ # we need to ensure that we have a connection to the DB and that the `deleted_at` column exists
5
7
  if !ENV['SPREE_DISABLE_DB_CONNECTION'] &&
6
- connection.data_source_exists?(:spree_credit_cards) &&
8
+ connected? &&
9
+ table_exists? &&
7
10
  connection.column_exists?(:spree_credit_cards, :deleted_at)
8
11
  acts_as_paranoid
9
12
  end
@@ -20,7 +20,7 @@ module Spree
20
20
  validates :quantity, numericality: { only_integer: true, message: Spree.t('validation.must_be_int') }
21
21
  validates :price, numericality: true
22
22
 
23
- validates_with Stock::AvailabilityValidator
23
+ validates_with Spree::Stock::AvailabilityValidator
24
24
  validate :ensure_proper_currency, if: -> { order.present? }
25
25
 
26
26
  before_destroy :verify_order_inventory_before_destroy, if: -> { order.has_checkout_step?('delivery') }
@@ -85,7 +85,7 @@ module Spree
85
85
  alias money display_total
86
86
 
87
87
  def sufficient_stock?
88
- Stock::Quantifier.new(variant).can_supply? quantity
88
+ Spree::Stock::Quantifier.new(variant).can_supply? quantity
89
89
  end
90
90
 
91
91
  def insufficient_stock?
@@ -153,7 +153,7 @@ module Spree
153
153
  end
154
154
 
155
155
  def recalculate_adjustments
156
- Adjustable::AdjustmentsUpdater.update(self)
156
+ Spree::Adjustable::AdjustmentsUpdater.update(self)
157
157
  end
158
158
 
159
159
  def update_tax_charge
@@ -269,7 +269,7 @@ module Spree
269
269
  end
270
270
 
271
271
  def shipping_method
272
- selected_shipping_rate.try(:shipping_method) || shipping_rates.first.try(:shipping_method)
272
+ selected_shipping_rate&.shipping_method || shipping_rates.first&.shipping_method
273
273
  end
274
274
 
275
275
  def tax_category
@@ -292,7 +292,7 @@ module Spree
292
292
  end
293
293
 
294
294
  def tracking_url
295
- @tracking_url ||= shipping_method.build_tracking_url(tracking)
295
+ @tracking_url ||= shipping_method&.build_tracking_url(tracking)
296
296
  end
297
297
 
298
298
  def update_amounts
@@ -81,7 +81,7 @@ module Spree
81
81
  )
82
82
  end
83
83
 
84
- scope :not_deleted, -> { where("#{Variant.quoted_table_name}.deleted_at IS NULL") }
84
+ scope :not_deleted, -> { where("#{Spree::Variant.quoted_table_name}.deleted_at IS NULL") }
85
85
 
86
86
  scope :for_currency_and_available_price_amount, ->(currency = nil) do
87
87
  currency ||= Spree::Config[:currency]
@@ -112,7 +112,7 @@ module Spree
112
112
  if self[:tax_category_id].nil?
113
113
  product.tax_category
114
114
  else
115
- TaxCategory.find(self[:tax_category_id])
115
+ Spree::TaxCategory.find(self[:tax_category_id])
116
116
  end
117
117
  end
118
118
 
@@ -4,10 +4,29 @@ module Spree
4
4
  prepend Spree::ServiceModule::Base
5
5
 
6
6
  def call(order:, params:, permitted_attributes:, request_env:)
7
+ params = replace_country_iso_with_id(params, 'ship') if address_with_country_iso_present?(params, 'ship')
8
+ params = replace_country_iso_with_id(params, 'bill') if address_with_country_iso_present?(params, 'bill')
7
9
  return success(order) if order.update_from_params(params, permitted_attributes, request_env)
8
10
 
9
11
  failure(order)
10
12
  end
13
+
14
+ private
15
+
16
+ def address_with_country_iso_present?(params, address_kind = 'ship')
17
+ return false unless params.dig(:order, "#{address_kind}_address_attributes".to_sym, :country_iso)
18
+ return false if params.dig(:order, "#{address_kind}_address_attributes".to_sym, :country_id)
19
+
20
+ true
21
+ end
22
+
23
+ def replace_country_iso_with_id(params, address_kind = 'ship')
24
+ country_id = Spree::Country.by_iso(params[:order]["#{address_kind}_address_attributes"].fetch(:country_iso))&.id
25
+
26
+ params[:order]["#{address_kind}_address_attributes"]['country_id'] = country_id
27
+ params[:order]["#{address_kind}_address_attributes"].delete(:country_iso)
28
+ params
29
+ end
11
30
  end
12
31
  end
13
32
  end
@@ -0,0 +1,42 @@
1
+ module Spree
2
+ module Orders
3
+ class Sort
4
+ attr_reader :scope, :sort
5
+
6
+ def initialize(scope, params)
7
+ @scope = scope
8
+ @sort = params[:sort]
9
+ end
10
+
11
+ def call
12
+ orders = completed_at(scope)
13
+
14
+ orders
15
+ end
16
+
17
+ private
18
+
19
+ def desc_order
20
+ @desc_order ||= String(sort)[0] == '-'
21
+ end
22
+
23
+ def sort_field
24
+ @sort_field ||= desc_order ? sort[1..-1] : sort
25
+ end
26
+
27
+ def order_direction
28
+ desc_order ? :asc : :desc
29
+ end
30
+
31
+ def completed_at?
32
+ sort_field.eql?('completed_at')
33
+ end
34
+
35
+ def completed_at(orders)
36
+ return orders unless completed_at?
37
+
38
+ orders.order(completed_at: order_direction)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- '3.7.0.rc1'
3
+ '3.7.0.rc2'
4
4
  end
5
5
  end
@@ -31,7 +31,7 @@ module Spree
31
31
 
32
32
  @@address_attributes = [
33
33
  :id, :firstname, :lastname, :first_name, :last_name,
34
- :address1, :address2, :city, :country_id, :state_id,
34
+ :address1, :address2, :city, :country_iso, :country_id, :state_id,
35
35
  :zipcode, :phone, :state_name, :alternative_phone, :company,
36
36
  country: [:iso, :name, :iso3, :iso_name],
37
37
  state: [:name, :abbr]
@@ -106,7 +106,7 @@ module CapybaraExt
106
106
  def wait_for_ajax(delay = Capybara.default_max_wait_time)
107
107
  Timeout.timeout(delay) do
108
108
  active = page.evaluate_script('typeof jQuery !== "undefined" && jQuery.active')
109
- active = page.evaluate_script('typeof jQuery !== "undefined" && jQuery.active') until active.zero?
109
+ active = page.evaluate_script('typeof jQuery !== "undefined" && jQuery.active') until active.nil? || active.zero?
110
110
  end
111
111
  end
112
112
 
data/spree_core.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.summary = 'The bare bones necessary for Spree.'
10
10
  s.description = 'The bare bones necessary for Spree.'
11
11
 
12
- s.required_ruby_version = '>= 2.3.0'
12
+ s.required_ruby_version = '>= 2.3.3'
13
13
  s.required_rubygems_version = '>= 1.8.23'
14
14
 
15
15
  s.author = 'Sean Schofield'
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency 'activemerchant', '~> 1.67'
24
24
  s.add_dependency 'acts_as_list', '~> 0.8'
25
- s.add_dependency 'awesome_nested_set', '~> 3.1.3'
25
+ s.add_dependency 'awesome_nested_set', '~> 3.1.4'
26
26
  s.add_dependency 'carmen', '~> 1.0.0'
27
27
  s.add_dependency 'cancancan', '~> 2.0'
28
28
  s.add_dependency 'deface', '~> 1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0.rc1
4
+ version: 3.7.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.3
47
+ version: 3.1.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.3
54
+ version: 3.1.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: carmen
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -385,6 +385,7 @@ files:
385
385
  - app/finders/spree/countries/find.rb
386
386
  - app/finders/spree/credit_cards/find.rb
387
387
  - app/finders/spree/line_items/find_by_variant.rb
388
+ - app/finders/spree/orders/find_complete.rb
388
389
  - app/finders/spree/orders/find_current.rb
389
390
  - app/finders/spree/products/find.rb
390
391
  - app/finders/spree/taxons/find.rb
@@ -606,6 +607,7 @@ files:
606
607
  - app/services/spree/checkout/update.rb
607
608
  - app/services/spree/compare_line_items.rb
608
609
  - app/services/spree/generate_token.rb
610
+ - app/sorters/spree/orders/sort.rb
609
611
  - app/sorters/spree/products/sort.rb
610
612
  - app/validators/db_maximum_length_validator.rb
611
613
  - app/validators/email_validator.rb
@@ -1057,7 +1059,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1057
1059
  requirements:
1058
1060
  - - ">="
1059
1061
  - !ruby/object:Gem::Version
1060
- version: 2.3.0
1062
+ version: 2.3.3
1061
1063
  required_rubygems_version: !ruby/object:Gem::Requirement
1062
1064
  requirements:
1063
1065
  - - ">="
@@ -1065,7 +1067,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1065
1067
  version: 1.8.23
1066
1068
  requirements: []
1067
1069
  rubyforge_project:
1068
- rubygems_version: 2.7.6
1070
+ rubygems_version: 2.7.8
1069
1071
  signing_key:
1070
1072
  specification_version: 4
1071
1073
  summary: The bare bones necessary for Spree.