spree_core 4.0.5 → 4.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/finders/spree/addresses/find.rb +17 -0
- data/app/finders/spree/products/find.rb +5 -3
- data/app/models/spree/app_dependencies.rb +7 -1
- data/app/models/spree/line_item.rb +2 -1
- data/app/models/spree/order.rb +8 -2
- data/app/models/spree/order/address_book.rb +7 -20
- data/app/models/spree/product.rb +2 -2
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +1 -1
- data/app/models/spree/variant.rb +5 -1
- data/app/models/spree/zone.rb +2 -2
- data/app/services/spree/account/addresses/base.rb +39 -0
- data/app/services/spree/account/addresses/create.rb +18 -0
- data/app/services/spree/account/addresses/update.rb +18 -0
- data/app/services/spree/checkout/get_shipping_rates.rb +7 -10
- data/app/services/spree/checkout/update.rb +13 -2
- data/lib/generators/spree/install/templates/config/initializers/spree.rb +1 -0
- data/lib/spree/core.rb +1 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/database_type_utilities.rb +12 -0
- data/spree_core.gemspec +12 -6
- metadata +16 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9c76746a8aefcd58da169e77b4e30d436ce5c7b670dccbe5a949fa68f1bac08
|
4
|
+
data.tar.gz: f72936183c3f4c62db43b9b9fae337cd0ebf60c55f49fe7bdc051662d5490244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454bcf0cafdf6205eddc4360e49a54a9d1c8afa0e4f352311a34988312628c2d6c7cd50b07944c9be4dccd98dadd1232052b60d97ff80f03ad3ed91cd670471f
|
7
|
+
data.tar.gz: f20f81616c612d250ba5080ccc2696fd55a758ece0b35002edb19b3b7ed353de720a95ecb9b2aaf0dbbea37f3e5b904afdf37521ff7ad9cf4490767985f70a29
|
@@ -112,9 +112,11 @@ module Spree
|
|
112
112
|
def by_options(products)
|
113
113
|
return products unless options?
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
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'
|
@@ -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
|
data/app/models/spree/order.rb
CHANGED
@@ -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.
|
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
|
58
|
+
attributes.transform_values! { |v| v == '' ? nil : v }
|
59
59
|
|
60
|
-
|
61
|
-
|
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
|
-
|
70
|
-
|
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
|
-
|
78
|
-
address = Spree::Address.new(attributes)
|
79
|
-
address.save
|
66
|
+
return default_address
|
80
67
|
end
|
81
68
|
|
82
|
-
|
69
|
+
::Spree::Address.find_or_create_by(attributes.except(:id, :updated_at, :created_at))
|
83
70
|
end
|
84
71
|
end
|
85
72
|
end
|
data/app/models/spree/product.rb
CHANGED
@@ -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
|
-
|
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
|
data/app/models/spree/variant.rb
CHANGED
@@ -234,7 +234,11 @@ module Spree
|
|
234
234
|
end
|
235
235
|
|
236
236
|
def in_stock?
|
237
|
-
|
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
|
data/app/models/spree/zone.rb
CHANGED
@@ -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 :
|
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
|
-
|
8
|
-
|
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
|
|
@@ -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
data/lib/spree/core/version.rb
CHANGED
@@ -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', '
|
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.
|
4
|
+
version: 4.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Schofield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-30 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.
|
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.
|
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,7 +1061,11 @@ files:
|
|
1062
1061
|
homepage: http://spreecommerce.org
|
1063
1062
|
licenses:
|
1064
1063
|
- BSD-3-Clause
|
1065
|
-
metadata:
|
1064
|
+
metadata:
|
1065
|
+
bug_tracker_uri: https://github.com/spree/spree/issues
|
1066
|
+
changelog_uri: https://github.com/spree/spree/releases/tag/v4.0.6
|
1067
|
+
documentation_uri: https://guides.spreecommerce.org/
|
1068
|
+
source_code_uri: https://github.com/spree/spree/tree/v4.0.6
|
1066
1069
|
post_install_message:
|
1067
1070
|
rdoc_options: []
|
1068
1071
|
require_paths:
|