spree_core 4.0.2 → 4.0.7

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: e79320700b634228f0412b07daf6a3bd7b8af06ec5cc1bfc4ffa13928ea041a5
4
- data.tar.gz: aa559a7fd3888ba8be2b02e6d0210430a0535424fb9346133a561f0750b52076
3
+ metadata.gz: 24d8697b01ebe0da73f0747dc3ddc9a45522db809a92ebc93a97dc9e8c4fccef
4
+ data.tar.gz: 691bcf5bba6d78868abb9b39893b63737398dae79d5e939381cc9c02ef6a6286
5
5
  SHA512:
6
- metadata.gz: 24c0e981d5a9b8e54868224300755b3247a0ac647feb2916f052f1171ac50235fa8bf478200fc6e5c8af226bbc4773f849c09c0402ab6757ebd9ce4c61e0e5ef
7
- data.tar.gz: b634ef167616757b41b6e2197c18e6b142b24db859ccd62d01c7b578743cfd235b2d733fe8a95f678669eb8f9f774549fc4ce4abece81353f6f7801790659e2a
6
+ metadata.gz: 79a9d22bd03b122d64e7bf5a2505df120e4671442945eb2c2c0d8a63be3a592f344252730add4fde3bbf757282d9016fb8e2f6cf21b405415b6094d45d0407cf
7
+ data.tar.gz: c12bb814fa2b091c153e5ebdc18c33c645ae6e5c40e4d0bf78e2fd36bc712f3017ee7b0149904402bca5376193e496df652a56cfed8486a908ee59b35e4d83ab
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ module Addresses
3
+ class Find
4
+ def initialize(scope:, params:)
5
+ @scope = scope
6
+ end
7
+
8
+ def execute
9
+ scope
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :scope
15
+ end
16
+ end
17
+ end
@@ -112,9 +112,11 @@ module Spree
112
112
  def by_options(products)
113
113
  return products unless options?
114
114
 
115
- options.map do |key, value|
116
- products.with_option_value(key, value)
117
- end.inject(:&)
115
+ products.where(
116
+ id: options.map do |key, value|
117
+ products.with_option_value(key, value).ids
118
+ end.flatten.compact.uniq
119
+ )
118
120
  end
119
121
 
120
122
  def by_option_value_ids(products)
@@ -11,7 +11,8 @@ module Spree
11
11
  :checkout_remove_store_credit_service, :checkout_get_shipping_rates_service,
12
12
  :coupon_handler, :country_finder, :current_order_finder, :credit_card_finder,
13
13
  :completed_order_finder, :order_sorter, :cart_compare_line_items_service, :collection_paginator, :products_sorter,
14
- :products_finder, :taxon_finder, :line_item_by_variant_finder, :cart_estimate_shipping_rates_service
14
+ :products_finder, :taxon_finder, :line_item_by_variant_finder, :cart_estimate_shipping_rates_service,
15
+ :account_create_address_service, :account_update_address_service, :address_finder
15
16
  ].freeze
16
17
 
17
18
  attr_accessor *INJECTION_POINTS
@@ -59,9 +60,14 @@ module Spree
59
60
  # coupons
60
61
  # TODO: we should split this service into 2 seperate - Add and Remove
61
62
  @coupon_handler = 'Spree::PromotionHandler::Coupon'
63
+
64
+ # account
65
+ @account_create_address_service = 'Spree::Account::Addresses::Create'
66
+ @account_update_address_service = 'Spree::Account::Addresses::Update'
62
67
  end
63
68
 
64
69
  def set_default_finders
70
+ @address_finder = 'Spree::Addresses::Find'
65
71
  @country_finder = 'Spree::Countries::Find'
66
72
  @current_order_finder = 'Spree::Orders::FindCurrent'
67
73
  @completed_order_finder = 'Spree::Orders::FindComplete'
@@ -24,10 +24,9 @@ module Spree
24
24
  attribute :month, ActiveRecord::Type::Integer.new
25
25
  attribute :year, ActiveRecord::Type::Integer.new
26
26
 
27
- attr_reader :number
27
+ attr_reader :number, :verification_value
28
28
  attr_accessor :encrypted_data,
29
29
  :imported,
30
- :verification_value,
31
30
  :manual_entry
32
31
 
33
32
  with_options if: :require_card_numbers?, on: :create do
@@ -101,9 +100,11 @@ module Spree
101
100
  end
102
101
  end
103
102
 
103
+ def verification_value=(value)
104
+ @verification_value = value.to_s.gsub(/\s/, '')
105
+ end
106
+
104
107
  def set_last_digits
105
- number.to_s.gsub!(/\s/, '')
106
- verification_value.to_s.gsub!(/\s/, '')
107
108
  self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..-1)
108
109
  end
109
110
 
@@ -59,7 +59,8 @@ module Spree
59
59
 
60
60
  extend DisplayMoney
61
61
  money_methods :amount, :subtotal, :discounted_amount, :final_amount, :total, :price,
62
- :adjustment_total, :additional_tax_total, :promo_total, :included_tax_total
62
+ :adjustment_total, :additional_tax_total, :promo_total, :included_tax_total,
63
+ :pre_tax_amount
63
64
 
64
65
  alias single_money display_price
65
66
  alias single_display_amount display_price
@@ -21,7 +21,8 @@ module Spree
21
21
  extend Spree::DisplayMoney
22
22
  money_methods :outstanding_balance, :item_total, :adjustment_total,
23
23
  :included_tax_total, :additional_tax_total, :tax_total,
24
- :shipment_total, :promo_total, :total
24
+ :shipment_total, :promo_total, :total,
25
+ :cart_promo_total, :pre_tax_item_amount, :pre_tax_total
25
26
 
26
27
  alias display_ship_total display_shipment_total
27
28
  alias_attribute :ship_total, :shipment_total
@@ -173,7 +174,12 @@ module Spree
173
174
 
174
175
  # Sum of all line item amounts pre-tax
175
176
  def pre_tax_item_amount
176
- line_items.to_a.sum(&:pre_tax_amount)
177
+ line_items.sum(:pre_tax_amount)
178
+ end
179
+
180
+ # Sum of all line item and shipment pre-tax
181
+ def pre_tax_total
182
+ pre_tax_item_amount + shipments.sum(:pre_tax_amount)
177
183
  end
178
184
 
179
185
  def shipping_discount
@@ -55,31 +55,18 @@ module Spree
55
55
  def update_or_create_address(attributes = {})
56
56
  return if attributes.blank?
57
57
 
58
- attributes = attributes.select { |_k, v| v.present? }
58
+ attributes.transform_values! { |v| v == '' ? nil : v }
59
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)
60
+ default_address_scope = user ? user.addresses : ::Spree::Address
61
+ default_address = default_address_scope.find_by(id: attributes[:id])
68
62
 
69
- if address&.editable?
70
- address.update(attributes)
71
- return address
72
- else
73
- attributes.delete(:id)
74
- end
75
- end
63
+ if default_address&.editable?
64
+ default_address.update(attributes)
76
65
 
77
- unless attributes[:id]
78
- address = Spree::Address.new(attributes)
79
- address.save
66
+ return default_address
80
67
  end
81
68
 
82
- address
69
+ ::Spree::Address.find_or_create_by(attributes.except(:id, :updated_at, :created_at))
83
70
  end
84
71
  end
85
72
  end
@@ -100,7 +100,7 @@ module Spree::Preferences::Preferable
100
100
  if value.is_a?(FalseClass) ||
101
101
  value.nil? ||
102
102
  value == 0 ||
103
- value =~ /^(f|false|0)$/i ||
103
+ value&.to_s =~ /^(f|false|0)$/i ||
104
104
  (value.respond_to?(:empty?) && value.empty?)
105
105
  false
106
106
  else
@@ -110,7 +110,7 @@ module Spree
110
110
 
111
111
  alias options product_option_types
112
112
 
113
- self.whitelisted_ransackable_associations = %w[stores variants_including_master master variants]
113
+ self.whitelisted_ransackable_associations = %w[taxons stores variants_including_master master variants]
114
114
  self.whitelisted_ransackable_attributes = %w[description name slug discontinue_on]
115
115
  self.whitelisted_ransackable_scopes = %w[not_discontinued]
116
116
 
@@ -321,7 +321,7 @@ module Spree
321
321
  price: master.price
322
322
  )
323
323
  end
324
- throw(:abort) unless save
324
+ save
325
325
  end
326
326
 
327
327
  def ensure_master
@@ -23,7 +23,7 @@ module Spree
23
23
  order = line_item.order
24
24
 
25
25
  # Prevent negative order totals
26
- amounts << order.amount - order.adjustments.sum(:amount).abs if order.adjustments.any?
26
+ amounts << order.amount - order.adjustments.eligible.sum(:amount).abs if order.adjustments.eligible.any?
27
27
 
28
28
  amounts.min * -1
29
29
  end
@@ -25,7 +25,6 @@ module Spree
25
25
 
26
26
  def remove(coupon_code)
27
27
  promotion = order.promotions.with_coupon_code(coupon_code)
28
-
29
28
  if promotion.present?
30
29
  # Order promotion has to be destroyed before line item removing
31
30
  order.order_promotions.find_by!(promotion_id: promotion.id).destroy
@@ -76,7 +75,7 @@ module Spree
76
75
  line_item = order.find_line_item_by_variant(item.variant)
77
76
  next if line_item.blank?
78
77
 
79
- Spree::Dependencies.cart_remove_item_service(order: order, item: item.variant, quantity: item.quantity)
78
+ Spree::Dependencies.cart_remove_item_service.constantize.call(order: order, item: item.variant, quantity: item.quantity)
80
79
  end
81
80
  end
82
81
 
@@ -234,7 +234,11 @@ module Spree
234
234
  end
235
235
 
236
236
  def in_stock?
237
- Rails.cache.fetch(in_stock_cache_key) do
237
+ # Issue 10280
238
+ # Check if model responds to cache version and fall back to updated_at for older rails versions
239
+ # This makes sure a version is supplied when recyclable cache keys are disabled.
240
+ version = respond_to?(:cache_version) ? cache_version : updated_at.to_i
241
+ Rails.cache.fetch(in_stock_cache_key, version: version) do
238
242
  total_on_hand > 0
239
243
  end
240
244
  end
@@ -69,8 +69,8 @@ module Spree
69
69
  end
70
70
 
71
71
  def kind
72
- if kind?
73
- super
72
+ if self[:kind].present?
73
+ self[:kind]
74
74
  else
75
75
  not_nil_scope = members.where.not(zoneable_type: nil)
76
76
  zone_type = not_nil_scope.order('created_at ASC').pluck(:zoneable_type).last
@@ -0,0 +1,39 @@
1
+ module Spree
2
+ module Account
3
+ module Addresses
4
+ class Base
5
+ prepend Spree::ServiceModule::Base
6
+
7
+ private
8
+
9
+ attr_accessor :country
10
+
11
+ def fill_country_and_state_ids(params)
12
+ replace_country_iso_with_id(params)
13
+ fill_state_id(params)
14
+ end
15
+
16
+ def replace_country_iso_with_id(params)
17
+ iso = params[:country_iso]
18
+ return params unless iso.present?
19
+
20
+ country = Spree::Country.by_iso(iso)
21
+ params[:country_id] = country&.id
22
+ params.delete(:country_iso)
23
+ params
24
+ end
25
+
26
+ def fill_state_id(params)
27
+ state_name = params[:state_name]
28
+ return params unless state_name.present?
29
+
30
+ country ||= Spree::Country.find(params[:country_id]) if params[:country_id].present?
31
+ return params unless country
32
+
33
+ params[:state_id] = country.states.find_by(name: state_name)&.id
34
+ params
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ module Spree
2
+ module Account
3
+ module Addresses
4
+ class Create < ::Spree::Account::Addresses::Base
5
+ def call(user:, address_params:)
6
+ fill_country_and_state_ids(address_params)
7
+
8
+ address = user.addresses.new(address_params)
9
+ if address.save
10
+ success(address)
11
+ else
12
+ failure(address)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Spree
2
+ module Account
3
+ module Addresses
4
+ class Update < ::Spree::Account::Addresses::Base
5
+ def call(address:, address_params:)
6
+ address_params[:country_id] ||= address.country_id
7
+ fill_country_and_state_ids(address_params)
8
+
9
+ if address.update(address_params)
10
+ success(address)
11
+ else
12
+ failure(address)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -7,9 +7,7 @@ module Spree
7
7
  run :reload_order
8
8
  run :ensure_shipping_address
9
9
  run :ensure_line_items_present
10
- run :move_order_to_delivery_state
11
- run :generate_shipping_rates
12
- run :return_shipments
10
+ run :generate_or_return_shipping_rates
13
11
  end
14
12
 
15
13
  private
@@ -31,6 +29,11 @@ module Spree
31
29
  success(order: order)
32
30
  end
33
31
 
32
+ def generate_or_return_shipping_rates(order:)
33
+ generate_shipping_rates(order: order) if order.shipments.empty?
34
+ return_shipments(order: order)
35
+ end
36
+
34
37
  def generate_shipping_rates(order:)
35
38
  ApplicationRecord.transaction do
36
39
  order.create_proposed_shipments
@@ -42,13 +45,7 @@ module Spree
42
45
  end
43
46
 
44
47
  def return_shipments(order:)
45
- success(order.shipments.includes([shipping_rates: :shipping_method]))
46
- end
47
-
48
- def move_order_to_delivery_state(order:)
49
- Spree::Dependencies.checkout_next_service.constantize.call(order: order) until order.state == 'delivery'
50
-
51
- success(order: order)
48
+ success(order.reload.shipments.includes([shipping_rates: :shipping_method]))
52
49
  end
53
50
  end
54
51
  end
@@ -4,8 +4,12 @@ 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
+ ship_changed = address_with_country_iso_present?(params, 'ship')
8
+ bill_changed = address_with_country_iso_present?(params, 'bill')
9
+ params = replace_country_iso_with_id(params, 'ship') if ship_changed
10
+ params = replace_country_iso_with_id(params, 'bill') if bill_changed
11
+ order.state = 'address' if (ship_changed || bill_changed) && order.has_checkout_step?('address')
12
+ order.state = 'delivery' if selected_shipping_rate_present?(params) && order.has_checkout_step?('delivery')
9
13
  return success(order) if order.update_from_params(params, permitted_attributes, request_env)
10
14
 
11
15
  failure(order)
@@ -20,6 +24,13 @@ module Spree
20
24
  true
21
25
  end
22
26
 
27
+ def selected_shipping_rate_present?(params)
28
+ shipments_attributes = params.dig(:order, :shipments_attributes)
29
+ return false unless shipments_attributes
30
+
31
+ shipments_attributes.any? { |s| s.dig(:selected_shipping_rate_id) }
32
+ end
33
+
23
34
  def replace_country_iso_with_id(params, address_kind = 'ship')
24
35
  country_id = Spree::Country.by_iso(params[:order]["#{address_kind}_address_attributes"].fetch(:country_iso))&.id
25
36
 
@@ -137,7 +137,7 @@ end
137
137
  end
138
138
 
139
139
  def gemfile_path
140
- core_gems = ['spree/core', 'spree/api', 'spree/backend', 'spree/frontend']
140
+ core_gems = ['spree/core', 'spree/api', 'spree/backend', 'spree/frontend', 'spree/sample']
141
141
 
142
142
  if core_gems.include?(lib_name)
143
143
  '../../../../../Gemfile'
@@ -26,5 +26,6 @@ Spree.dependencies do |dependencies|
26
26
  # dependencies.cart_add_item_service = 'MyNewAwesomeService'
27
27
  end
28
28
 
29
+ # Spree::Api::Dependencies.storefront_cart_serializer = 'MyRailsApp::CartSerializer'
29
30
 
30
31
  Spree.user_class = <%= (options[:user_class].blank? ? 'Spree::LegacyUser' : options[:user_class]).inspect %>
data/lib/spree/core.rb CHANGED
@@ -93,6 +93,7 @@ require 'spree/money'
93
93
  require 'spree/permitted_attributes'
94
94
  require 'spree/service_module'
95
95
  require 'spree/dependencies_helper'
96
+ require 'spree/database_type_utilities'
96
97
 
97
98
  require 'spree/core/importer'
98
99
  require 'spree/core/query_filters'
@@ -1,5 +1,7 @@
1
1
  module Spree
2
+ VERSION = '4.0.7'.freeze
3
+
2
4
  def self.version
3
- '4.0.2'
5
+ VERSION
4
6
  end
5
7
  end
@@ -0,0 +1,12 @@
1
+ module Spree
2
+ module DatabaseTypeUtilities
3
+ def self.maximum_value_for(data_type)
4
+ case data_type
5
+ when :integer
6
+ ActiveModel::Type::Integer.new.instance_eval { range.max }
7
+ else
8
+ raise ArgumentError.new('Currently only :integer argument is acceptable')
9
+ end
10
+ end
11
+ end
12
+ end
data/spree_core.gemspec CHANGED
@@ -6,17 +6,23 @@ Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.name = 'spree_core'
8
8
  s.version = Spree.version
9
+ s.author = 'Sean Schofield'
10
+ s.email = 'sean@spreecommerce.com'
9
11
  s.summary = 'The bare bones necessary for Spree.'
10
12
  s.description = 'The bare bones necessary for Spree.'
13
+ s.homepage = 'http://spreecommerce.org'
14
+ s.license = 'BSD-3-Clause'
15
+
16
+ s.metadata = {
17
+ "bug_tracker_uri" => "https://github.com/spree/spree/issues",
18
+ "changelog_uri" => "https://github.com/spree/spree/releases/tag/v#{s.version}",
19
+ "documentation_uri" => "https://guides.spreecommerce.org/",
20
+ "source_code_uri" => "https://github.com/spree/spree/tree/v#{s.version}",
21
+ }
11
22
 
12
23
  s.required_ruby_version = '>= 2.5.0'
13
24
  s.required_rubygems_version = '>= 1.8.23'
14
25
 
15
- s.author = 'Sean Schofield'
16
- s.email = 'sean@spreecommerce.com'
17
- s.homepage = 'http://spreecommerce.org'
18
- s.license = 'BSD-3-Clause'
19
-
20
26
  s.files = `git ls-files`.split("\n").reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
21
27
  s.require_path = 'lib'
22
28
 
@@ -28,7 +34,7 @@ Gem::Specification.new do |s|
28
34
  s.add_dependency 'ffaker', '~> 2.9'
29
35
  s.add_dependency 'friendly_id', '>= 5.2.1', '< 5.4.0'
30
36
  s.add_dependency 'highline', '~> 2.0.0' # Necessary for the install generator
31
- s.add_dependency 'kaminari', '>= 1.0.1', '< 1.2.0'
37
+ s.add_dependency 'kaminari', '~> 1.2.1'
32
38
  s.add_dependency 'money', '~> 6.13'
33
39
  s.add_dependency 'monetize', '~> 1.9'
34
40
  s.add_dependency 'paranoia', '~> 2.4.2'
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: 4.0.2
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -144,22 +144,16 @@ dependencies:
144
144
  name: kaminari
145
145
  requirement: !ruby/object:Gem::Requirement
146
146
  requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- version: 1.0.1
150
- - - "<"
147
+ - - "~>"
151
148
  - !ruby/object:Gem::Version
152
- version: 1.2.0
149
+ version: 1.2.1
153
150
  type: :runtime
154
151
  prerelease: false
155
152
  version_requirements: !ruby/object:Gem::Requirement
156
153
  requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: 1.0.1
160
- - - "<"
154
+ - - "~>"
161
155
  - !ruby/object:Gem::Version
162
- version: 1.2.0
156
+ version: 1.2.1
163
157
  - !ruby/object:Gem::Dependency
164
158
  name: money
165
159
  requirement: !ruby/object:Gem::Requirement
@@ -400,6 +394,7 @@ files:
400
394
  - app/assets/images/noimage/small.png
401
395
  - app/assets/javascripts/spree.js
402
396
  - app/controllers/spree/base_controller.rb
397
+ - app/finders/spree/addresses/find.rb
403
398
  - app/finders/spree/countries/find.rb
404
399
  - app/finders/spree/credit_cards/find.rb
405
400
  - app/finders/spree/line_items/find_by_variant.rb
@@ -606,6 +601,9 @@ files:
606
601
  - app/models/spree/zone.rb
607
602
  - app/models/spree/zone_member.rb
608
603
  - app/paginators/spree/shared/paginate.rb
604
+ - app/services/spree/account/addresses/base.rb
605
+ - app/services/spree/account/addresses/create.rb
606
+ - app/services/spree/account/addresses/update.rb
609
607
  - app/services/spree/cart/add_item.rb
610
608
  - app/services/spree/cart/create.rb
611
609
  - app/services/spree/cart/estimate_shipping_rates.rb
@@ -971,6 +969,7 @@ files:
971
969
  - lib/spree/core/search/base.rb
972
970
  - lib/spree/core/token_generator.rb
973
971
  - lib/spree/core/version.rb
972
+ - lib/spree/database_type_utilities.rb
974
973
  - lib/spree/dependencies_helper.rb
975
974
  - lib/spree/i18n.rb
976
975
  - lib/spree/i18n/base.rb
@@ -1062,8 +1061,12 @@ files:
1062
1061
  homepage: http://spreecommerce.org
1063
1062
  licenses:
1064
1063
  - BSD-3-Clause
1065
- metadata: {}
1066
- post_install_message:
1064
+ metadata:
1065
+ bug_tracker_uri: https://github.com/spree/spree/issues
1066
+ changelog_uri: https://github.com/spree/spree/releases/tag/v4.0.7
1067
+ documentation_uri: https://guides.spreecommerce.org/
1068
+ source_code_uri: https://github.com/spree/spree/tree/v4.0.7
1069
+ post_install_message:
1067
1070
  rdoc_options: []
1068
1071
  require_paths:
1069
1072
  - lib
@@ -1078,8 +1081,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1078
1081
  - !ruby/object:Gem::Version
1079
1082
  version: 1.8.23
1080
1083
  requirements: []
1081
- rubygems_version: 3.0.2
1082
- signing_key:
1084
+ rubygems_version: 3.2.3
1085
+ signing_key:
1083
1086
  specification_version: 4
1084
1087
  summary: The bare bones necessary for Spree.
1085
1088
  test_files: []