solidus_core 3.1.8 → 3.1.9
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.
- checksums.yaml +4 -4
- data/app/models/concerns/spree/default_price.rb +4 -28
- data/app/models/spree/variant/price_selector.rb +18 -1
- data/app/models/spree/variant.rb +1 -1
- data/config/locales/en.yml +4 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/preferences/preferable.rb +5 -0
- data/lib/spree/preferences/preferable_class_methods.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd88c98f5da37d9a89e981aad39979998349f0e2405a4a7095a8f75f4d3839f8
|
4
|
+
data.tar.gz: 656beea8141300d09b62b4970dccd7691556112597a891a4f0d1821a67914ea3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44d04ac1151fd4f7f2ac20b7f117e500b76be1d39fd2ad5ef72654dca8749bd9dd42eb9acd402adf519d2769d7099b8d44977ccf0a906089c10315675b22cad1
|
7
|
+
data.tar.gz: 93ff18fdf9856b60aec7f484bd468db70c67bd9e446e7fbedf383ff88f21f59fb261d0c53b7db1f46c0a8848f133fb032258ae7d57c968d485503abc248fb606
|
@@ -16,10 +16,12 @@ module Spree
|
|
16
16
|
|
17
17
|
# Returns `#prices` prioritized for being considered as default price
|
18
18
|
#
|
19
|
+
# @deprecated
|
19
20
|
# @return [ActiveRecord::Relation<Spree::Price>]
|
20
21
|
def currently_valid_prices
|
21
22
|
prices.currently_valid
|
22
23
|
end
|
24
|
+
deprecate :currently_valid_prices, deprecator: Spree::Deprecation
|
23
25
|
|
24
26
|
# Returns {#default_price} or builds it from {Spree::Variant.default_price_attributes}
|
25
27
|
#
|
@@ -33,7 +35,7 @@ module Spree
|
|
33
35
|
# Select from {#prices} the one to be considered as the default
|
34
36
|
#
|
35
37
|
# This method works with the in-memory association, so non-persisted prices
|
36
|
-
# are taken into account.
|
38
|
+
# are taken into account.
|
37
39
|
#
|
38
40
|
# A price is a candidate to be considered as the default when it meets
|
39
41
|
# {Spree::Variant.default_price_attributes} criteria. When more than one candidate is
|
@@ -44,37 +46,11 @@ module Spree
|
|
44
46
|
# @return [Spree::Price, nil]
|
45
47
|
# @see Spree::Variant.default_price_attributes
|
46
48
|
def default_price
|
47
|
-
|
48
|
-
prices_meeting_criteria_to_be_default(
|
49
|
-
(prices + prices.with_discarded).uniq
|
50
|
-
)
|
51
|
-
)
|
49
|
+
price_selector.price_for_options(Spree::Config.default_pricing_options)
|
52
50
|
end
|
53
51
|
|
54
52
|
def has_default_price?
|
55
53
|
default_price.present? && !default_price.discarded?
|
56
54
|
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def prices_meeting_criteria_to_be_default(prices)
|
61
|
-
criteria = self.class.default_price_attributes.transform_keys(&:to_s)
|
62
|
-
prices.select do |price|
|
63
|
-
contender = price.attributes.slice(*criteria.keys)
|
64
|
-
criteria == contender
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def prioritized_default(prices)
|
69
|
-
prices.min do |prev, succ|
|
70
|
-
contender_one, contender_two = [succ, prev].map do |item|
|
71
|
-
[
|
72
|
-
item.updated_at || Time.zone.now,
|
73
|
-
item.id || Float::INFINITY
|
74
|
-
]
|
75
|
-
end
|
76
|
-
contender_one <=> contender_two
|
77
|
-
end
|
78
|
-
end
|
79
55
|
end
|
80
56
|
end
|
@@ -39,12 +39,29 @@ module Spree
|
|
39
39
|
# @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
|
40
40
|
# @return [Spree::Price, nil] The most specific price for this set of pricing options.
|
41
41
|
def price_for_options(price_options)
|
42
|
-
variant.
|
42
|
+
sorted_prices_for(variant).detect do |price|
|
43
43
|
(price.country_iso == price_options.desired_attributes[:country_iso] ||
|
44
44
|
price.country_iso.nil?
|
45
45
|
) && price.currency == price_options.desired_attributes[:currency]
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Returns `#prices` prioritized for being considered as default price
|
52
|
+
#
|
53
|
+
# @return [Array<Spree::Price>]
|
54
|
+
def sorted_prices_for(variant)
|
55
|
+
variant.prices.select do |price|
|
56
|
+
variant.discarded? || price.kept?
|
57
|
+
end.sort_by do |price|
|
58
|
+
[
|
59
|
+
price.country_iso.nil? ? 0 : 1,
|
60
|
+
price.updated_at || Time.zone.now,
|
61
|
+
price.id || Float::INFINITY,
|
62
|
+
]
|
63
|
+
end.reverse
|
64
|
+
end
|
48
65
|
end
|
49
66
|
end
|
50
67
|
end
|
data/app/models/spree/variant.rb
CHANGED
@@ -23,7 +23,6 @@ module Spree
|
|
23
23
|
after_discard do
|
24
24
|
stock_items.discard_all
|
25
25
|
images.destroy_all
|
26
|
-
prices.discard_all
|
27
26
|
end
|
28
27
|
|
29
28
|
attr_writer :rebuild_vat_prices
|
@@ -52,6 +51,7 @@ module Spree
|
|
52
51
|
has_many :images, -> { order(:position) }, as: :viewable, dependent: :destroy, class_name: "Spree::Image"
|
53
52
|
|
54
53
|
has_many :prices,
|
54
|
+
-> { with_discarded },
|
55
55
|
class_name: 'Spree::Price',
|
56
56
|
dependent: :destroy,
|
57
57
|
inverse_of: :variant,
|
data/config/locales/en.yml
CHANGED
@@ -762,6 +762,10 @@ en:
|
|
762
762
|
not_saved:
|
763
763
|
one: '1 error prohibited this %{resource} from being saved:'
|
764
764
|
other: "%{count} errors prohibited this %{resource} from being saved:"
|
765
|
+
number:
|
766
|
+
percentage:
|
767
|
+
format:
|
768
|
+
precision: 1
|
765
769
|
spree:
|
766
770
|
abbreviation: Abbreviation
|
767
771
|
accept: Accept
|
data/lib/spree/core/version.rb
CHANGED
@@ -10,6 +10,9 @@ module Spree
|
|
10
10
|
#
|
11
11
|
# A class including Preferable must implement #preferences which should return
|
12
12
|
# an object responding to .fetch(key), []=(key, val), and .delete(key).
|
13
|
+
# If #preferences is initialized with `default_preferences` and one of the
|
14
|
+
# preferences is another preference, it will cause a stack level too deep error.
|
15
|
+
# To avoid it do not memoize #preferences.
|
13
16
|
#
|
14
17
|
# It may also define a `#context_for_default` method. It should return an
|
15
18
|
# array with the arguments to be provided to a proc used as the `default:`
|
@@ -111,6 +114,8 @@ module Spree
|
|
111
114
|
end
|
112
115
|
|
113
116
|
# @return [Hash{Symbol => Object}] Default for all preferences defined on this class
|
117
|
+
# This may raise an infinite loop error if any of the defaults are
|
118
|
+
# dependent on other preferences defaults.
|
114
119
|
def default_preferences
|
115
120
|
Hash[
|
116
121
|
defined_preferences.map do |preference|
|
@@ -75,7 +75,7 @@ module Spree::Preferences
|
|
75
75
|
# is a pending preference before going to default
|
76
76
|
define_method preference_getter_method(name) do
|
77
77
|
value = preferences.fetch(name) do
|
78
|
-
|
78
|
+
instance_exec(*context_for_default, &default)
|
79
79
|
end
|
80
80
|
value = preference_encryptor.decrypt(value) if preference_encryptor.present?
|
81
81
|
value
|
@@ -92,7 +92,7 @@ module Spree::Preferences
|
|
92
92
|
end
|
93
93
|
|
94
94
|
define_method preference_default_getter_method(name) do
|
95
|
-
|
95
|
+
instance_exec(*context_for_default, &default)
|
96
96
|
end
|
97
97
|
|
98
98
|
define_method preference_type_getter_method(name) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|