solidus_core 3.2.3 → 3.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc968f634c0e31f7ad3d1928133d5d682df2669617eaca7abdc87379228d7e30
4
- data.tar.gz: a2e38014e3d24fe363651e7e27f5b8fa21b93105f1269e67adee3e20ec1665fa
3
+ metadata.gz: b7a2c88277ebda2afcdfced8c30f64602d6cc9bbb1839f47eab674e1e58ebd7f
4
+ data.tar.gz: 76b1cea1f67d9eff240ab277ceb2df51085e111224ead5c3343596e2dca0c15e
5
5
  SHA512:
6
- metadata.gz: 8fbc377c572b99bb42d055b1479f2be9c5bca450019f70bef38adf76a3bfd69057c90824150036c7ed1330d9052f3916f09a48a252b85f31c0719f33f5d52c43
7
- data.tar.gz: c57b6889ddf53bcf23fc1ed0012a9759ef72a031a72e1c8a8a838abfb8594b8f401bb17a973d17c37347aae44f37411181ab9a663e884659ebeb6122c06481c4
6
+ metadata.gz: fa93973896e2ad61b824e82f12a263594936a986db1c0bd4eb6689813e19d8cb1009d31d33201ca00ab6e524ad7cb31fc93f469932da842abc442470a8577c2e
7
+ data.tar.gz: 4d74fa5a9f2bbe435d22c247581762a97856c982e999f22d0886afb22bd624299a3ae77ed171b5ed42e9fafe1fab98e695d46c706e92d97763b803f0ec232a36
@@ -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. Discarded prices are also considered.
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
- prioritized_default(
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.currently_valid_prices.detect do |price|
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
@@ -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,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "3.2.3"
4
+ VERSION = "3.2.4"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
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.2.3
4
+ version: 3.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2022-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -1020,7 +1020,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1020
1020
  - !ruby/object:Gem::Version
1021
1021
  version: 1.8.23
1022
1022
  requirements: []
1023
- rubygems_version: 3.3.19
1023
+ rubygems_version: 3.3.21
1024
1024
  signing_key:
1025
1025
  specification_version: 4
1026
1026
  summary: Essential models, mailers, and classes for the Solidus e-commerce project.