solidus_core 3.2.2 → 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: 544b2bfea9af16a2ae309c6eb5b4d2038b60cf592b461b9019d66933324cbab8
4
- data.tar.gz: 36312a6f1b0b979c06e68125199834650b0f5fea1ee65af092136527b4121978
3
+ metadata.gz: b7a2c88277ebda2afcdfced8c30f64602d6cc9bbb1839f47eab674e1e58ebd7f
4
+ data.tar.gz: 76b1cea1f67d9eff240ab277ceb2df51085e111224ead5c3343596e2dca0c15e
5
5
  SHA512:
6
- metadata.gz: 4c5bbfc5dacae815c6ce863d2c807d2a4e49c448912f3c8e9f5e8901b5aa1b1c2e8d3bdeeea3ea3e76d116b66e6aa6e9eba307471023f44ed61806eaa3b662c6
7
- data.tar.gz: 816d06788b22c4fe4b02780e0d640ba8f56a0186371ddbcf2e40cac9695a4f697e3a131cbc6d893321e42c741f27d63c48e7ce604958da5ed37957db451a5bfc
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,
@@ -11,42 +11,48 @@ module Solidus
11
11
  @generator_context = generator_context
12
12
  end
13
13
 
14
- def call(frontend, installer_adds_auth:)
14
+ def call(frontend)
15
15
  case frontend
16
16
  when 'solidus_frontend'
17
17
  install_solidus_frontend
18
18
  when 'solidus_starter_frontend'
19
- install_solidus_starter_frontend(installer_adds_auth)
19
+ install_solidus_starter_frontend
20
20
  end
21
21
  end
22
22
 
23
23
  private
24
24
 
25
- def install_solidus_frontend
26
- unless @bundler_context.component_in_gemfile?(:frontend)
27
- BundlerContext.bundle_cleanly do
28
- `bundle add solidus_frontend`
29
- `bundle install`
30
- end
31
- end
25
+ def bundle_command(command)
26
+ @generator_context.say_status :run, "bundle #{command}"
27
+ bundle_path = Gem.bin_path("bundler", "bundle")
32
28
 
33
- @generator_context.generate("solidus_frontend:install #{@generator_context.options[:auto_accept] ? '--auto-accept' : ''}")
29
+ BundlerContext.bundle_cleanly do
30
+ system(
31
+ Gem.ruby,
32
+ bundle_path,
33
+ *command.shellsplit,
34
+ )
35
+ end
34
36
  end
35
37
 
36
- def install_solidus_starter_frontend(installer_adds_auth)
37
- @bundler_context.remove(['solidus_frontend']) if @bundler_context.component_in_gemfile?(:frontend)
38
+ def install_solidus_frontend
39
+ unless @bundler_context.component_in_gemfile?(:frontend)
40
+ bundle_command 'add solidus_frontend'
41
+ end
38
42
 
39
- # TODO: Move installation of solidus_auth_devise to the
40
- # solidus_starter_frontend template
41
- unless auth_present?(installer_adds_auth)
42
- BundlerContext.bundle_cleanly { `bundle add solidus_auth_devise` }
43
- @generator_context.generate('solidus:auth:install --auto-run-migrations')
43
+ # Solidus bolt will be handled in the installer as a payment method.
44
+ begin
45
+ skip_solidus_bolt = ENV['SKIP_SOLIDUS_BOLT']
46
+ ENV['SKIP_SOLIDUS_BOLT'] = 'true'
47
+ @generator_context.generate("solidus_frontend:install #{@generator_context.options[:auto_accept] ? '--auto-accept' : ''}")
48
+ ensure
49
+ ENV['SKIP_SOLIDUS_BOLT'] = skip_solidus_bolt
44
50
  end
45
- `LOCATION="https://raw.githubusercontent.com/solidusio/solidus_starter_frontend/main/template.rb" bin/rails app:template`
46
51
  end
47
52
 
48
- def auth_present?(installer_adds_auth)
49
- installer_adds_auth || @bundler_context.component_in_gemfile?(:auth_devise)
53
+ def install_solidus_starter_frontend
54
+ @bundler_context.remove(['solidus_frontend']) if @bundler_context.component_in_gemfile?(:frontend)
55
+ @generator_context.apply "https://raw.githubusercontent.com/solidusio/solidus_starter_frontend/v3.2/template.rb"
50
56
  end
51
57
  end
52
58
  end
@@ -19,6 +19,12 @@ module Solidus
19
19
  'none'
20
20
  ].freeze
21
21
 
22
+ PAYMENT_METHODS = {
23
+ 'paypal' => 'solidus_paypal_commerce_platform',
24
+ 'bolt' => 'solidus_bolt',
25
+ 'none' => nil,
26
+ }
27
+
22
28
  class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
23
29
  class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)'
24
30
  class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations must be run)'
@@ -28,13 +34,18 @@ module Solidus
28
34
  class_option :admin_email, type: :string
29
35
  class_option :admin_password, type: :string
30
36
  class_option :lib_name, type: :string, default: 'spree'
31
- class_option :with_authentication, type: :boolean, default: true
37
+ class_option :with_authentication, type: :boolean, default: nil
32
38
  class_option :enforce_available_locales, type: :boolean, default: nil
33
39
  class_option :frontend,
34
40
  type: :string,
35
41
  enum: FRONTENDS,
36
42
  default: nil,
37
43
  desc: "Indicates which frontend to install."
44
+ class_option :payment_method,
45
+ type: :string,
46
+ enum: PAYMENT_METHODS.keys,
47
+ default: nil,
48
+ desc: "Indicates which payment method to install."
38
49
 
39
50
  def self.source_paths
40
51
  paths = superclass.source_paths
@@ -118,7 +129,8 @@ module Solidus
118
129
  end
119
130
 
120
131
  def install_auth_plugin
121
- if options[:with_authentication] && (options[:auto_accept] || !no?("
132
+ with_authentication = options[:with_authentication]
133
+ with_authentication.nil? and with_authentication = (options[:auto_accept] || !no?("
122
134
  Solidus has a default authentication extension that uses Devise.
123
135
  You can find more info at https://github.com/solidusio/solidus_auth_devise.
124
136
 
@@ -127,11 +139,32 @@ module Solidus
127
139
 
128
140
  Would you like to install it? (Y/n)"))
129
141
 
142
+ if with_authentication
130
143
  @plugins_to_be_installed << 'solidus_auth_devise'
131
144
  @plugin_generators_to_run << 'solidus:auth:install'
132
145
  end
133
146
  end
134
147
 
148
+ def install_payment_method
149
+ say_status :warning, set_color(
150
+ "Selecting a payment along with `solidus_starter_frontend` might require manual integration.",
151
+ :yellow
152
+ ), :yellow
153
+
154
+ name = options[:payment_method]
155
+ name ||= PAYMENT_METHODS.keys.first if options[:auto_accept]
156
+ name ||= ask("
157
+ You can select a payment method to be included in the installation process.
158
+ Please select a payment method name:", limited_to: PAYMENT_METHODS.keys, default: PAYMENT_METHODS.keys.first)
159
+
160
+ gem_name = PAYMENT_METHODS.fetch(name)
161
+
162
+ if gem_name
163
+ @plugins_to_be_installed << gem_name
164
+ @plugin_generators_to_run << "#{gem_name}:install"
165
+ end
166
+ end
167
+
135
168
  def include_seed_data
136
169
  append_file "db/seeds.rb", <<-RUBY.strip_heredoc
137
170
 
@@ -150,19 +183,6 @@ module Solidus
150
183
  rake 'db:create'
151
184
  end
152
185
 
153
- def run_bundle_install_if_needed_by_plugins
154
- @plugins_to_be_installed.each do |plugin_name|
155
- gem plugin_name
156
- end
157
-
158
- BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
159
- run "spring stop" if defined?(Spring)
160
-
161
- @plugin_generators_to_run.each do |plugin_generator_name|
162
- generate "#{plugin_generator_name} --skip_migrations=true"
163
- end
164
- end
165
-
166
186
  def install_frontend
167
187
  return if options[:frontend] == 'none'
168
188
 
@@ -174,9 +194,22 @@ module Solidus
174
194
 
175
195
  say_status :installing, frontend
176
196
 
177
- InstallFrontend.
178
- new(bundler_context: bundler_context, generator_context: self).
179
- call(frontend, installer_adds_auth: @plugins_to_be_installed.include?('solidus_auth_devise'))
197
+ InstallFrontend
198
+ .new(bundler_context: bundler_context, generator_context: self)
199
+ .call(frontend)
200
+ end
201
+
202
+ def run_bundle_install_if_needed_by_plugins
203
+ @plugins_to_be_installed.each do |plugin_name|
204
+ gem plugin_name
205
+ end
206
+
207
+ BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
208
+ run "spring stop" if defined?(Spring)
209
+
210
+ @plugin_generators_to_run.each do |plugin_generator_name|
211
+ generate "#{plugin_generator_name} --skip_migrations=true"
212
+ end
180
213
  end
181
214
 
182
215
  def run_migrations
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "3.2.2"
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.2
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-09-09 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.