solidus_core 3.4.2 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/spree/base_controller.rb +0 -2
  4. data/app/helpers/spree/products_helper.rb +1 -1
  5. data/app/models/concerns/spree/active_storage_adapter.rb +0 -17
  6. data/app/models/concerns/spree/default_price.rb +0 -15
  7. data/app/models/concerns/spree/ransackable_attributes.rb +0 -21
  8. data/app/models/spree/adjustment.rb +0 -13
  9. data/app/models/spree/carton.rb +1 -1
  10. data/app/models/spree/fulfilment_changer.rb +2 -14
  11. data/app/models/spree/option_value.rb +2 -11
  12. data/app/models/spree/order.rb +23 -39
  13. data/app/models/spree/order_contents.rb +2 -2
  14. data/app/models/spree/order_merger.rb +2 -4
  15. data/app/models/spree/order_updater.rb +3 -30
  16. data/app/models/spree/payment.rb +5 -37
  17. data/app/models/spree/product/scopes.rb +0 -5
  18. data/app/models/spree/product.rb +3 -10
  19. data/app/models/spree/promotion/rules/item_total.rb +0 -11
  20. data/app/models/spree/promotion.rb +7 -30
  21. data/app/models/spree/promotion_rule.rb +0 -5
  22. data/app/models/spree/refund.rb +1 -1
  23. data/app/models/spree/taxon/paperclip_attachment.rb +1 -1
  24. data/app/models/spree/taxon.rb +2 -2
  25. data/app/models/spree/taxonomy.rb +1 -1
  26. data/app/models/spree/variant/price_selector.rb +1 -14
  27. data/app/models/spree/variant.rb +1 -17
  28. data/bin/rails +13 -0
  29. data/config/locales/en.yml +0 -1
  30. data/db/migrate/20210815004823_add_unique_index_to_option_values_variants.rb +16 -0
  31. data/db/migrate/20230321161854_change_column_null_option_values_option_type_id.rb +5 -0
  32. data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +5 -0
  33. data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +6 -0
  34. data/db/migrate/20230325161633_drop_unused_promo_action_line_items.rb +13 -0
  35. data/db/migrate/20230425103509_remove_taxon_position.rb +5 -0
  36. data/db/migrate/20230427095534_drop_deprecated_address_id_from_shipments.rb +11 -0
  37. data/lib/generators/solidus/install/app_templates/frontend/none.rb +1 -2
  38. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -3
  39. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +2 -14
  40. data/lib/generators/solidus/install/app_templates/payment_method/stripe.rb +5 -0
  41. data/lib/generators/solidus/install/install_generator.rb +59 -153
  42. data/lib/spree/app_configuration.rb +10 -82
  43. data/lib/spree/bus.rb +2 -11
  44. data/lib/spree/core/controller_helpers/auth.rb +0 -16
  45. data/lib/spree/core/engine.rb +11 -31
  46. data/lib/spree/core/importer/order.rb +1 -1
  47. data/lib/spree/core/validators/email.rb +0 -4
  48. data/lib/spree/core/version.rb +2 -2
  49. data/lib/spree/core.rb +0 -2
  50. data/lib/spree/migration_helpers.rb +3 -3
  51. data/lib/spree/permission_sets/configuration_display.rb +19 -1
  52. data/lib/spree/permission_sets/configuration_management.rb +18 -1
  53. data/lib/spree/permission_sets/dashboard_display.rb +5 -0
  54. data/lib/spree/permission_sets/default_customer.rb +29 -0
  55. data/lib/spree/permission_sets/order_display.rb +19 -0
  56. data/lib/spree/permission_sets/order_management.rb +18 -0
  57. data/lib/spree/permission_sets/product_display.rb +14 -0
  58. data/lib/spree/permission_sets/product_management.rb +16 -0
  59. data/lib/spree/permission_sets/promotion_display.rb +10 -0
  60. data/lib/spree/permission_sets/promotion_management.rb +10 -0
  61. data/lib/spree/permission_sets/restricted_stock_display.rb +5 -0
  62. data/lib/spree/permission_sets/restricted_stock_management.rb +5 -0
  63. data/lib/spree/permission_sets/stock_display.rb +4 -0
  64. data/lib/spree/permission_sets/stock_management.rb +4 -0
  65. data/lib/spree/permission_sets/super_user.rb +5 -0
  66. data/lib/spree/permission_sets/user_display.rb +4 -0
  67. data/lib/spree/permission_sets/user_management.rb +9 -0
  68. data/lib/spree/preferences/preferable_class_methods.rb +1 -25
  69. data/lib/spree/testing_support/common_rake.rb +5 -1
  70. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +4 -8
  71. data/lib/spree/testing_support/dummy_app.rb +1 -7
  72. data/lib/spree/testing_support/factories/address_factory.rb +0 -7
  73. data/lib/spree/testing_support/factories/adjustment_factory.rb +0 -11
  74. data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +0 -5
  75. data/lib/spree/testing_support/factories/calculator_factory.rb +0 -5
  76. data/lib/spree/testing_support/factories/carton_factory.rb +0 -8
  77. data/lib/spree/testing_support/factories/country_factory.rb +0 -5
  78. data/lib/spree/testing_support/factories/credit_card_factory.rb +0 -5
  79. data/lib/spree/testing_support/factories/customer_return_factory.rb +0 -9
  80. data/lib/spree/testing_support/factories/image_factory.rb +0 -5
  81. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +0 -10
  82. data/lib/spree/testing_support/factories/line_item_factory.rb +0 -8
  83. data/lib/spree/testing_support/factories/option_type_factory.rb +0 -8
  84. data/lib/spree/testing_support/factories/option_value_factory.rb +0 -5
  85. data/lib/spree/testing_support/factories/order_factory.rb +0 -12
  86. data/lib/spree/testing_support/factories/order_promotion_factory.rb +0 -8
  87. data/lib/spree/testing_support/factories/payment_factory.rb +0 -10
  88. data/lib/spree/testing_support/factories/payment_method_factory.rb +0 -5
  89. data/lib/spree/testing_support/factories/price_factory.rb +0 -7
  90. data/lib/spree/testing_support/factories/product_factory.rb +0 -11
  91. data/lib/spree/testing_support/factories/product_option_type_factory.rb +0 -8
  92. data/lib/spree/testing_support/factories/product_property_factory.rb +0 -8
  93. data/lib/spree/testing_support/factories/promotion_category_factory.rb +0 -5
  94. data/lib/spree/testing_support/factories/promotion_code_factory.rb +0 -8
  95. data/lib/spree/testing_support/factories/promotion_factory.rb +0 -8
  96. data/lib/spree/testing_support/factories/property_factory.rb +0 -5
  97. data/lib/spree/testing_support/factories/refund_factory.rb +0 -8
  98. data/lib/spree/testing_support/factories/refund_reason_factory.rb +0 -5
  99. data/lib/spree/testing_support/factories/reimbursement_factory.rb +0 -7
  100. data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +0 -5
  101. data/lib/spree/testing_support/factories/return_authorization_factory.rb +0 -9
  102. data/lib/spree/testing_support/factories/return_item_factory.rb +0 -9
  103. data/lib/spree/testing_support/factories/return_reason_factory.rb +0 -5
  104. data/lib/spree/testing_support/factories/role_factory.rb +0 -5
  105. data/lib/spree/testing_support/factories/shipment_factory.rb +0 -10
  106. data/lib/spree/testing_support/factories/shipping_category_factory.rb +0 -5
  107. data/lib/spree/testing_support/factories/shipping_method_factory.rb +0 -9
  108. data/lib/spree/testing_support/factories/shipping_rate_factory.rb +0 -8
  109. data/lib/spree/testing_support/factories/state_factory.rb +0 -8
  110. data/lib/spree/testing_support/factories/stock_item_factory.rb +0 -8
  111. data/lib/spree/testing_support/factories/stock_location_factory.rb +0 -9
  112. data/lib/spree/testing_support/factories/stock_movement_factory.rb +0 -7
  113. data/lib/spree/testing_support/factories/stock_package_factory.rb +0 -8
  114. data/lib/spree/testing_support/factories/store_credit_category_factory.rb +0 -5
  115. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +0 -8
  116. data/lib/spree/testing_support/factories/store_credit_factory.rb +0 -9
  117. data/lib/spree/testing_support/factories/store_credit_reason_factory.rb +0 -5
  118. data/lib/spree/testing_support/factories/store_credit_type_factory.rb +0 -5
  119. data/lib/spree/testing_support/factories/store_factory.rb +0 -5
  120. data/lib/spree/testing_support/factories/tax_category_factory.rb +0 -8
  121. data/lib/spree/testing_support/factories/tax_rate_factory.rb +0 -9
  122. data/lib/spree/testing_support/factories/taxon_factory.rb +0 -7
  123. data/lib/spree/testing_support/factories/taxonomy_factory.rb +0 -5
  124. data/lib/spree/testing_support/factories/user_factory.rb +0 -9
  125. data/lib/spree/testing_support/factories/variant_factory.rb +0 -10
  126. data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +0 -8
  127. data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +0 -9
  128. data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +0 -8
  129. data/lib/spree/testing_support/factories/zone_factory.rb +0 -8
  130. data/lib/spree/testing_support/factory_bot.rb +4 -28
  131. data/lib/spree/testing_support/sequences.rb +0 -5
  132. data/solidus_core.gemspec +3 -3
  133. metadata +48 -58
  134. data/app/subscribers/spree/mailer_subscriber.rb +0 -29
  135. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +0 -54
  136. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +0 -16
  137. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +0 -13
  138. data/lib/spree/core/controller_helpers/current_host.rb +0 -19
  139. data/lib/spree/event/adapters/active_support_notifications.rb +0 -67
  140. data/lib/spree/event/configuration.rb +0 -25
  141. data/lib/spree/event/subscriber.rb +0 -86
  142. data/lib/spree/event/subscriber_registry.rb +0 -92
  143. data/lib/spree/event.rb +0 -119
  144. data/lib/spree/promotion/match_policies.rb +0 -2
  145. data/lib/spree/rails_compatibility.rb +0 -106
  146. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +0 -10
  147. data/lib/spree/testing_support/dummy_app/assets/stylesheets/spree/frontend/all.css +0 -9
  148. data/lib/spree/testing_support/dummy_app/views/layouts/application.html.erb +0 -1
  149. data/lib/spree/testing_support/factories.rb +0 -11
  150. data/lib/spree/testing_support.rb +0 -36
  151. data/lib/tasks/solidus/check_orders_with_invalid_email.rake +0 -18
  152. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +0 -33
@@ -2,9 +2,6 @@
2
2
 
3
3
  module Spree
4
4
  class Promotion < Spree::Base
5
-
6
- autoload(:MATCH_POLICIES, "spree/promotion/match_policies")
7
-
8
5
  UNACTIVATABLE_ORDER_STATES = ["complete", "awaiting_return", "returned"]
9
6
 
10
7
  attr_reader :eligibility_errors
@@ -167,27 +164,13 @@ module Spree
167
164
  specific_rules = rules.select { |rule| rule.applicable?(promotable) }
168
165
  return [] if specific_rules.none?
169
166
 
170
- if match_all?
171
- # If there are rules for this promotion, but no rules for this
172
- # particular promotable, then the promotion is ineligible by default.
173
- unless specific_rules.all?(&eligible)
174
- @eligibility_errors = specific_rules.map(&:eligibility_errors).detect(&:present?)
175
- return nil
176
- end
177
- specific_rules
178
- else
179
- Spree::Deprecation.warn(
180
- <<~WARN
181
- Your promotion "#{name}" with ID #{id} has a match_policy of 'any'.
182
- This is deprecated, please split the promotion into separate promotions for each rule.
183
- WARN
184
- )
185
- unless specific_rules.any?(&eligible)
186
- @eligibility_errors = specific_rules.map(&:eligibility_errors).detect(&:present?)
187
- return nil
188
- end
189
- specific_rules.select(&eligible)
167
+ # If there are rules for this promotion, but no rules for this
168
+ # particular promotable, then the promotion is ineligible by default.
169
+ unless specific_rules.all?(&eligible)
170
+ @eligibility_errors = specific_rules.map(&:eligibility_errors).detect(&:present?)
171
+ return nil
190
172
  end
173
+ specific_rules
191
174
  end
192
175
 
193
176
  def products
@@ -224,9 +207,7 @@ module Spree
224
207
  if rules.blank?
225
208
  true
226
209
  else
227
- rules.send(match_all? ? :all? : :any?) do |rule|
228
- rule.actionable? line_item
229
- end
210
+ rules.all? { |rule| rule.actionable? line_item }
230
211
  end
231
212
  else
232
213
  false
@@ -271,10 +252,6 @@ module Spree
271
252
  self[:path] = nil if self[:path].blank?
272
253
  end
273
254
 
274
- def match_all?
275
- match_policy == "all"
276
- end
277
-
278
255
  def apply_automatically_disallowed_with_paths
279
256
  return unless apply_automatically
280
257
 
@@ -18,11 +18,6 @@ module Spree
18
18
  []
19
19
  end
20
20
 
21
- def self.for(promotable)
22
- all.select { |rule| rule.applicable?(promotable) }
23
- end
24
- deprecate :for, "Please select promotion rules by their applicable status on the promotable instead."
25
-
26
21
  def applicable?(_promotable)
27
22
  raise NotImplementedError, "applicable? should be implemented in a sub-class of Spree::PromotionRule"
28
23
  end
@@ -90,7 +90,7 @@ module Spree
90
90
  end
91
91
 
92
92
  def update_order
93
- payment.order.updater.update
93
+ payment.order.recalculate
94
94
  end
95
95
  end
96
96
  end
@@ -25,6 +25,6 @@ module Spree::Taxon::PaperclipAttachment
25
25
  attached_file = send(definition)
26
26
  return false unless attached_file.exists?
27
27
 
28
- attached_file.destroy
28
+ attached_file.destroy && save
29
29
  end
30
30
  end
@@ -18,11 +18,11 @@ module Spree
18
18
  after_update :update_child_permalinks, if: :saved_change_to_permalink?
19
19
 
20
20
  validates :name, presence: true
21
- validates :name, uniqueness: { scope: :parent_id, message: :must_be_unique_under_same_parent }, if: -> { Spree::Config.extra_taxon_validations}
21
+ validates :name, uniqueness: { scope: :parent_id, message: :must_be_unique_under_same_parent }
22
22
  validates :meta_keywords, length: { maximum: 255 }
23
23
  validates :meta_description, length: { maximum: 255 }
24
24
  validates :meta_title, length: { maximum: 255 }
25
- validates :taxonomy_id, uniqueness: { message: :can_have_only_one_root }, if: -> { Spree::Config.extra_taxon_validations && root? }
25
+ validates :taxonomy_id, uniqueness: { scope: :parent_id, message: :can_have_only_one_root }, if: -> { root? }
26
26
 
27
27
  after_save :touch_ancestors_and_taxonomy
28
28
  after_touch :touch_ancestors_and_taxonomy
@@ -5,7 +5,7 @@ module Spree
5
5
  acts_as_list
6
6
 
7
7
  validates :name, presence: true
8
- validates :name, uniqueness: true, if: -> { Spree::Config.extra_taxonomy_validations }
8
+ validates :name, uniqueness: true
9
9
 
10
10
  has_many :taxons, inverse_of: :taxonomy
11
11
  has_one :root, -> { where parent_id: nil }, class_name: "Spree::Taxon", dependent: :destroy
@@ -3,7 +3,7 @@
3
3
  module Spree
4
4
  class Variant < Spree::Base
5
5
  # This class is responsible for selecting a price for a variant given certain pricing options.
6
- # A variant can have multiple or even dynamic prices. The `price_for`
6
+ # A variant can have multiple or even dynamic prices. The `price_for_options`
7
7
  # method determines which price applies under the given circumstances.
8
8
  #
9
9
  class PriceSelector
@@ -22,19 +22,6 @@ module Spree
22
22
  @variant = variant
23
23
  end
24
24
 
25
- # The variant's price, given a set of pricing options
26
- # @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
27
- # @return [Spree::Money, nil] The most specific price for this set of pricing options.
28
- def price_for(price_options)
29
- Spree::Deprecation.warn(
30
- "price_for is deprecated and will be removed. The price_for method
31
- should return a Spree::Price as described. Please use
32
- #price_for_options and adjust your frontend code to explicitly call
33
- &.money where required"
34
- )
35
- price_for_options(price_options)&.money
36
- end
37
-
38
25
  # The variant's Spree::Price record, given a set of pricing options
39
26
  # @param [Spree::Variant::PricingOptions] price_options Pricing Options to abide by
40
27
  # @return [Spree::Price, nil] The most specific price for this set of pricing options.
@@ -39,6 +39,7 @@ module Spree
39
39
  delegate :shipping_category, :shipping_category_id,
40
40
  to: :product, prefix: true
41
41
  delegate :tax_rates, to: :tax_category
42
+ delegate :price_for_options, to: :price_selector
42
43
 
43
44
  has_many :inventory_units, inverse_of: :variant
44
45
  has_many :line_items, inverse_of: :variant
@@ -287,12 +288,6 @@ module Spree
287
288
  @price_selector ||= Spree::Config.variant_price_selector_class.new(self)
288
289
  end
289
290
 
290
- # Chooses an appropriate price for the given pricing options
291
- # This has been deprecated in favor of #price_for_options.
292
- #
293
- # @see Spree::Variant::PriceSelector#price_for_options
294
- delegate :price_for, to: :price_selector
295
-
296
291
  # Returns the difference in price from the master variant
297
292
  def price_difference_from_master(pricing_options = Spree::Config.default_pricing_options)
298
293
  master_price = product.master.price_for_options(pricing_options)
@@ -306,17 +301,6 @@ module Spree
306
301
  diff && diff.zero?
307
302
  end
308
303
 
309
- def price_for_options(price_options)
310
- if price_selector.respond_to?(:price_for_options)
311
- price_selector.price_for_options(price_options)
312
- else
313
- money = price_for(price_options)
314
- return if money.nil?
315
-
316
- Spree::Price.new(amount: money.to_d, variant: self, currency: price_options.currency)
317
- end
318
- end
319
-
320
304
  # Generates a friendly name and sku string.
321
305
  #
322
306
  # @return [String]
data/bin/rails ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/spree/core/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__)
10
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
11
+
12
+ require "rails/all"
13
+ require "rails/engine/commands"
@@ -1598,7 +1598,6 @@ en:
1598
1598
  gateway_config_unavailable: Gateway unavailable for environment
1599
1599
  gateway_error: Gateway Error
1600
1600
  general: General
1601
- general_settings: Store
1602
1601
  google_analytics: Google Analytics
1603
1602
  google_analytics_id: Analytics ID
1604
1603
  group_size: Group size
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddUniqueIndexToOptionValuesVariants < ActiveRecord::Migration[5.2]
4
+ def up
5
+ remove_index :spree_option_values_variants, [:variant_id, :option_value_id]
6
+ add_index :spree_option_values_variants, [:variant_id, :option_value_id],
7
+ name: "index_option_values_variants_on_variant_id_and_option_value_id",
8
+ unique: true
9
+ end
10
+
11
+ def down
12
+ remove_index :spree_option_values_variants, [:variant_id, :option_value_id]
13
+ add_index :spree_option_values_variants, [:variant_id, :option_value_id],
14
+ name: "index_option_values_variants_on_variant_id_and_option_value_id"
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ class ChangeColumnNullOptionValuesOptionTypeId < ActiveRecord::Migration[5.2]
2
+ def change
3
+ change_column_null(:spree_option_values, :option_type_id, false)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveMatchPolicyFromSpreePromotion < ActiveRecord::Migration[5.2]
2
+ def change
3
+ remove_column :spree_promotions, :match_policy, :string, default: "all"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class RemoveUnusedColumnsFromPromotionRules < ActiveRecord::Migration[5.2]
2
+ def change
3
+ remove_column :spree_promotion_rules, :code, :string
4
+ remove_column :spree_promotion_rules, :product_group_id, :integer
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ class DropUnusedPromoActionLineItems < ActiveRecord::Migration[5.2]
2
+ def change
3
+ drop_table :spree_promotion_action_line_items, force: :cascade do |t|
4
+ t.integer "promotion_action_id"
5
+ t.integer "variant_id"
6
+ t.integer "quantity", default: 1
7
+ t.datetime "created_at", precision: 6
8
+ t.datetime "updated_at", precision: 6
9
+ t.index ["promotion_action_id"], name: "index_spree_promotion_action_line_items_on_promotion_action_id"
10
+ t.index ["variant_id"], name: "index_spree_promotion_action_line_items_on_variant_id"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveTaxonPosition < ActiveRecord::Migration[5.2]
2
+ def change
3
+ remove_column :spree_taxons, :position, :integer, default: 0
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class DropDeprecatedAddressIdFromShipments < ActiveRecord::Migration[5.2]
2
+ def up
3
+ remove_index :spree_shipments, column: [:deprecated_address_id], name: :index_spree_shipments_on_deprecated_address_id
4
+ remove_column :spree_shipments, :deprecated_address_id
5
+ end
6
+
7
+ def down
8
+ add_column :spree_shipments, :deprecated_address_id
9
+ add_index :spree_shipments, :deprecated_address_id, name: :index_spree_shipments_on_deprecated_address_id
10
+ end
11
+ end
@@ -1,2 +1 @@
1
- apply "#{__dir__}/break_down_solidus_gem.rb"
2
- run_bundle
1
+ # noop
@@ -1,3 +1 @@
1
- apply "#{__dir__}/break_down_solidus_gem.rb"
2
- run_bundle
3
- apply 'https://github.com/solidusio/solidus_starter_frontend/raw/v3.4/template.rb'
1
+ apply 'https://github.com/solidusio/solidus_starter_frontend/raw/v4.1/template.rb'
@@ -1,17 +1,5 @@
1
- unless Bundler.locked_gems.dependencies['solidus_frontend']
2
- say_status :warning, "Support for frontends other than `solidus_frontend` by `solidus_paypal_commerce_platform` is still in progress.", :yellow
3
- end
4
-
5
- if @selected_frontend == 'classic'
6
- version = '< 1'
7
- migrations_flag = options[:migrate] ? '--auto-run-migrations' : '--skip-migrations'
8
- else
9
- version = '~> 1.0'
10
- migrations_flag = "--migrate=#{options[:migrate]}"
11
- end
12
-
13
1
  unless Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform']
14
- bundle_command "add solidus_paypal_commerce_platform --version='#{version}'"
2
+ bundle_command "add solidus_paypal_commerce_platform --version='~> 1.0'"
15
3
  end
16
4
 
17
- generate "solidus_paypal_commerce_platform:install #{migrations_flag}"
5
+ generate "solidus_paypal_commerce_platform:install --migrate=#{options[:migrate]}"
@@ -0,0 +1,5 @@
1
+ unless Bundler.locked_gems.dependencies['solidus_stripe']
2
+ bundle_command "add solidus_stripe --version '~> 5.a'"
3
+ end
4
+
5
+ generate 'solidus_stripe:install'
@@ -11,70 +11,37 @@ module Solidus
11
11
 
12
12
  CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"
13
13
 
14
- FRONTENDS = %w[
15
- none
16
- classic
17
- starter
14
+ FRONTENDS = [
15
+ { name: 'starter', description: 'Generate all necessary controllers and views directly in your Rails app', default: true },
16
+ { name: 'none', description: 'Skip installing a frontend' }
18
17
  ]
19
18
 
20
- LEGACY_FRONTENDS = %w[
21
- solidus_starter_frontend
22
- solidus_frontend
23
- ]
24
-
25
- AUTHENTICATIONS = %w[
26
- devise
27
- existing
28
- custom
29
- none
19
+ AUTHENTICATIONS = [
20
+ { name: 'devise', description: 'Install and configure the standard `devise` integration', default: true },
21
+ { name: 'existing', description: 'Integrate and configure an existing `devise` setup' },
22
+ { name: 'custom', description: 'A starter configuration for rolling your own authentication system' },
23
+ { name: 'none', description: 'Don\'t add any configuration for authentication' }
30
24
  ]
31
25
 
32
26
  PAYMENT_METHODS = [
33
- {
34
- name: 'paypal',
35
- frontends: %w[none classic starter],
36
- description: 'Install `solidus_paypal_commerce_platform`',
37
- default: true,
38
- },
39
- {
40
- name: 'bolt',
41
- frontends: %w[classic],
42
- description: 'Install `solidus_bolt`',
43
- default: false,
44
- },
45
- {
46
- name: 'braintree',
47
- frontends: %w[none starter],
48
- description: 'Install `solidus_braintree`',
49
- default: false,
50
- },
51
- {
52
- name: 'none',
53
- frontends: %w[none classic starter],
54
- description: 'Skip installing a payment method',
55
- default: false,
56
- },
27
+ { name: 'paypal', description: 'Install `solidus_paypal_commerce_platform`', default: true },
28
+ { name: 'stripe', description: 'Install `solidus_stripe`', default: false },
29
+ { name: 'braintree', description: 'Install `solidus_braintree`', default: false },
30
+ { name: 'none', description: 'Skip installing a payment method', default: false }
57
31
  ]
58
32
 
59
33
  class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
60
34
  class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)'
61
35
  class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations and seeds must be run)'
62
- class_option :active_storage, type: :boolean, default: (
63
- Rails.gem_version >= Gem::Version.new("6.1.0")
64
- ), banner: 'Install ActiveStorage as image attachments handler for products and taxons'
36
+ class_option :active_storage, type: :boolean, default: true, banner: 'Install ActiveStorage as image attachments handler for products and taxons'
65
37
  class_option :auto_accept, type: :boolean
66
38
  class_option :user_class, type: :string
67
39
  class_option :admin_email, type: :string
68
40
  class_option :admin_password, type: :string
69
41
 
70
- class_option :frontend, type: :string, enum: FRONTENDS + LEGACY_FRONTENDS, default: nil, desc: "Indicates which frontend to install."
71
- class_option :authentication, type: :string, enum: AUTHENTICATIONS, default: nil, desc: "Indicates which authentication system to install."
72
- class_option :payment_method, type: :string, enum: PAYMENT_METHODS.map { |payment_method| payment_method[:name] }, default: nil, desc: "Indicates which payment method to install."
73
-
74
- # DEPRECATED
75
- class_option :with_authentication, type: :boolean, hide: true, default: nil
76
- class_option :enforce_available_locales, type: :boolean, hide: true, default: nil
77
- class_option :lib_name, type: :string, hide: true, default: nil
42
+ class_option :frontend, type: :string, enum: FRONTENDS.map { _1[:name] }, default: nil, desc: "Indicates which frontend to install."
43
+ class_option :authentication, type: :string, enum: AUTHENTICATIONS.map { _1[:name] }, default: nil, desc: "Indicates which authentication system to install."
44
+ class_option :payment_method, type: :string, enum: PAYMENT_METHODS.map { _1[:name] }, default: nil, desc: "Indicates which payment method to install."
78
45
 
79
46
  source_root "#{__dir__}/templates"
80
47
 
@@ -86,27 +53,37 @@ module Solidus
86
53
  @run_migrations = options[:migrate]
87
54
  @load_seed_data = options[:seed] && @run_migrations
88
55
  @load_sample_data = options[:sample] && @run_migrations && @load_seed_data
89
- @selected_frontend = detect_frontend_to_install
90
- @selected_authentication = detect_authentication_to_install
91
- @selected_payment_method = detect_payment_method_to_install
56
+
57
+ @selected_frontend = selected_option_for(
58
+ 'frontend',
59
+ selected: ENV['FRONTEND'] || options[:frontend],
60
+ available_options: FRONTENDS,
61
+ )
62
+
63
+ @selected_authentication = selected_option_for(
64
+ 'authentication',
65
+ selected:
66
+ ('devise' if @selected_frontend == 'starter') ||
67
+ ('devise' if has_gem?('solidus_auth_devise')) ||
68
+ ENV['AUTHENTICATION'] || options[:authentication],
69
+ available_options: AUTHENTICATIONS,
70
+ )
71
+
72
+ @selected_payment_method = selected_option_for(
73
+ 'payment method',
74
+ selected:
75
+ ('paypal' if has_gem?('solidus_paypal_commerce_platform')) ||
76
+ ('stripe' if has_gem?('solidus_stripe')) ||
77
+ ('bolt' if has_gem?('solidus_bolt')) ||
78
+ ENV['PAYMENT_METHOD'] || options[:payment_method],
79
+ available_options: PAYMENT_METHODS,
80
+ )
92
81
 
93
82
  # Silence verbose output (e.g. Rails migrations will rely on this environment variable)
94
83
  ENV['VERBOSE'] = 'false'
95
84
 
96
85
  # No reason to check for their presence if we're about to install them
97
86
  ENV['SOLIDUS_SKIP_MIGRATIONS_CHECK'] = 'true'
98
-
99
- if options[:enforce_available_locales] != nil
100
- warn \
101
- "DEPRECATION WARNING: using `solidus:install --enforce-available-locales` is now deprecated and has no effect. " \
102
- "Since Rails 4.1 the default is `true` so we no longer need to explicitly set a value."
103
- end
104
-
105
- if options[:lib_name] != nil
106
- warn \
107
- "DEPRECATION WARNING: using `solidus:install --lib-name` is now deprecated and has no effect. " \
108
- "The option is legacy and should be removed from scripts still using it."
109
- end
110
87
  end
111
88
 
112
89
  def add_files
@@ -119,7 +96,7 @@ module Solidus
119
96
  rake 'active_storage:install'
120
97
  else
121
98
  say_status :assets, "Paperclip", :green
122
- gsub_file 'config/initializers/spree.rb', "ActiveStorageAttachment", "PaperclipAttachment"
99
+ gsub_file 'config/initializers/spree.rb', "::ActiveStorageAttachment", "::PaperclipAttachment"
123
100
  end
124
101
  end
125
102
 
@@ -181,15 +158,9 @@ module Solidus
181
158
  end
182
159
  end
183
160
 
184
- def install_authentication
161
+ def install_subcomponents
185
162
  apply_template_for :authentication, @selected_authentication
186
- end
187
-
188
- def install_frontend
189
163
  apply_template_for :frontend, @selected_frontend
190
- end
191
-
192
- def install_payment_method
193
164
  apply_template_for :payment_method, @selected_payment_method
194
165
  end
195
166
 
@@ -271,93 +242,28 @@ module Solidus
271
242
  end
272
243
  end
273
244
 
274
- def detect_frontend_to_install
275
- # We need to support names that were available in v3.2
276
- selected_frontend = 'starter' if options[:frontend] == 'solidus_starter_frontend'
277
- selected_frontend = 'classic' if options[:frontend] == 'solidus_frontend'
278
- selected_frontend ||= options[:frontend]
279
-
280
- ENV['FRONTEND'] ||
281
- selected_frontend ||
282
- (Bundler.locked_gems.dependencies['solidus_frontend'] && 'classic') ||
283
- (options[:auto_accept] && 'starter') ||
284
- ask_with_description(
285
- default: 'starter',
286
- limited_to: FRONTENDS,
287
- desc: <<~TEXT
288
- Which frontend would you like to use?
289
-
290
- - [#{set_color 'starter', :bold}] Generate all necessary controllers and views directly in your Rails app (#{set_color :default, :bold}).
291
- - [#{set_color 'classic', :bold}] Install `solidus_frontend`, was the default in previous solidus versions (#{set_color :deprecated, :bold}).
292
- - [#{set_color 'none', :bold}] Skip installing a frontend.
293
-
294
- Selecting `starter` is recommended, however, some extensions are still only compatible with `classic`.
295
- TEXT
296
- )
245
+ def has_gem?(name)
246
+ Bundler.locked_gems.dependencies[name]
297
247
  end
298
248
 
299
- def detect_authentication_to_install
300
- return 'devise' if @selected_frontend == 'starter'
301
-
302
- if options[:with_authentication] != nil
303
- say_status :warning, \
304
- "Using `solidus:install --with-authentication` is now deprecated. " \
305
- "Please use `--authentication` instead (see --help for the full list of options).",
306
- :red
307
-
308
- if options[:with_authentication] == 'false'
309
- # Don't use the default authentication if the user explicitly
310
- # requested no authentication system.
311
- return 'none'
312
- else
313
- return 'devise'
314
- end
315
- end
316
-
317
- ENV['AUTHENTICATION'] ||
318
- options[:authentication] ||
319
- (Bundler.locked_gems.dependencies['solidus_auth_devise'] && 'devise') ||
320
- (options[:auto_accept] && 'devise') ||
321
- ask_with_description(
322
- default: 'devise',
323
- limited_to: AUTHENTICATIONS,
324
- desc: <<~TEXT
325
- Which authentication would you like to use?
326
-
327
- - [#{set_color 'devise', :bold}] Install and configure the standard `devise` integration. (#{set_color :default, :bold}).
328
- - [#{set_color 'existing', :bold}] Integrate and configure an existing `devise` setup.
329
- - [#{set_color 'custom', :bold}] A starter configuration for rolling your own authentication system.
330
- - [#{set_color 'none', :bold}] Don't add any configuration for authentication.
331
-
332
- Selecting `devise` is recommended.
333
- TEXT
334
- )
335
- end
249
+ def selected_option_for(name, selected:, available_options:)
250
+ return selected if selected
336
251
 
337
- def detect_payment_method_to_install
338
- return 'paypal' if Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform']
339
- return 'bolt' if Bundler.locked_gems.dependencies['solidus_bolt']
252
+ option_description = ->(name:, description:, default: false, **) do
253
+ default_label = " (#{set_color :default, :bold})" if default
340
254
 
341
- selected_frontend_payment_methods = PAYMENT_METHODS.select do |payment_method|
342
- payment_method[:frontends].include?(@selected_frontend)
255
+ "- [#{set_color name, :bold}] #{description}#{default_label}."
343
256
  end
344
257
 
345
- selected = options[:payment_method] || (options[:auto_accept] && 'paypal') ||
346
- ask_with_description(
347
- default: 'paypal',
348
- limited_to: selected_frontend_payment_methods.map { |payment_method| payment_method[:name] },
349
- desc: <<~TEXT
350
- Which payment method would you like to use?
351
-
352
- #{selected_frontend_payment_methods.map { |payment_method| formatted_payment_method_description(payment_method) }.join("\n")}
353
- TEXT
354
- )
355
- end
356
-
357
- def formatted_payment_method_description(payment_method)
358
- default_label = " (#{set_color :default, :bold})" if payment_method[:default]
359
-
360
- "- [#{set_color payment_method[:name], :bold}] #{payment_method[:description]}#{default_label}."
258
+ default = available_options.find { _1[:default] }
259
+ (options[:auto_accept] && default[:name]) || ask_with_description(
260
+ default: default[:name],
261
+ limited_to: available_options.map { _1[:name] },
262
+ desc: <<~TEXT
263
+ Which #{name} would you like to use?
264
+ #{available_options.map { option_description[**_1] }.join("\n")}
265
+ TEXT
266
+ )
361
267
  end
362
268
  end
363
269
  end