solidus_core 2.11.10 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -2
  3. data/app/assets/javascripts/spree.js.erb +0 -51
  4. data/app/controllers/spree/base_controller.rb +1 -1
  5. data/app/helpers/spree/base_helper.rb +1 -1
  6. data/app/helpers/spree/products_helper.rb +2 -2
  7. data/app/helpers/spree/store_helper.rb +0 -11
  8. data/app/mailers/spree/carton_mailer.rb +1 -5
  9. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +30 -11
  10. data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
  11. data/app/models/concerns/spree/adjustment_source.rb +0 -15
  12. data/app/models/concerns/spree/calculated_adjustments.rb +0 -18
  13. data/app/models/concerns/spree/default_price.rb +39 -10
  14. data/app/models/concerns/spree/ransackable_attributes.rb +24 -4
  15. data/app/models/concerns/spree/soft_deletable.rb +2 -4
  16. data/app/models/concerns/spree/user_address_book.rb +10 -37
  17. data/app/models/concerns/spree/user_methods.rb +38 -13
  18. data/app/models/spree/ability.rb +0 -37
  19. data/app/models/spree/address/name.rb +2 -20
  20. data/app/models/spree/address.rb +8 -186
  21. data/app/models/spree/adjustment.rb +7 -33
  22. data/app/models/spree/base.rb +0 -53
  23. data/app/models/spree/calculator/flat_fee.rb +21 -0
  24. data/app/models/spree/calculator/flexi_rate.rb +0 -5
  25. data/app/models/spree/calculator.rb +0 -7
  26. data/app/models/spree/carton.rb +1 -1
  27. data/app/models/spree/country.rb +2 -7
  28. data/app/models/spree/credit_card.rb +1 -28
  29. data/app/models/spree/customer_return.rb +5 -7
  30. data/app/models/spree/image/active_storage_attachment.rb +2 -7
  31. data/app/models/spree/image/paperclip_attachment.rb +2 -2
  32. data/app/models/spree/image.rb +0 -7
  33. data/app/models/spree/inventory_unit.rb +0 -21
  34. data/app/models/spree/line_item.rb +6 -49
  35. data/app/models/spree/log_entry.rb +74 -1
  36. data/app/models/spree/option_type.rb +1 -1
  37. data/app/models/spree/option_value.rb +10 -1
  38. data/app/models/spree/order/number_generator.rb +7 -1
  39. data/app/models/spree/order.rb +82 -170
  40. data/app/models/spree/order_cancellations.rb +4 -24
  41. data/app/models/spree/order_contents.rb +2 -1
  42. data/app/models/spree/order_inventory.rb +1 -1
  43. data/app/models/spree/order_merger.rb +2 -2
  44. data/app/models/spree/order_promotion.rb +1 -1
  45. data/app/models/spree/order_shipping.rb +6 -9
  46. data/app/models/spree/order_taxation.rb +6 -4
  47. data/app/models/spree/order_updater.rb +17 -16
  48. data/app/models/spree/payment/cancellation.rb +1 -1
  49. data/app/models/spree/payment/processing.rb +58 -55
  50. data/app/models/spree/payment.rb +0 -3
  51. data/app/models/spree/payment_create.rb +1 -13
  52. data/app/models/spree/payment_method/bogus_credit_card.rb +6 -7
  53. data/app/models/spree/payment_method/credit_card.rb +1 -3
  54. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +8 -0
  55. data/app/models/spree/payment_method.rb +26 -110
  56. data/app/models/spree/price.rb +3 -3
  57. data/app/models/spree/product/scopes.rb +24 -33
  58. data/app/models/spree/product.rb +15 -42
  59. data/app/models/spree/product_property.rb +1 -1
  60. data/app/models/spree/promotion/actions/create_adjustment.rb +4 -3
  61. data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -9
  62. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +0 -3
  63. data/app/models/spree/promotion/actions/free_shipping.rb +1 -0
  64. data/app/models/spree/promotion/order_adjustments_recalculator.rb +92 -0
  65. data/app/models/spree/promotion/rules/item_total.rb +50 -6
  66. data/app/models/spree/promotion/rules/product.rb +20 -8
  67. data/app/models/spree/promotion/rules/store.rb +4 -0
  68. data/app/models/spree/promotion/rules/taxon.rb +6 -15
  69. data/app/models/spree/promotion/rules/user.rb +4 -0
  70. data/app/models/spree/promotion.rb +39 -32
  71. data/app/models/spree/promotion_action.rb +6 -9
  72. data/app/models/spree/promotion_code/batch_builder.rb +0 -14
  73. data/app/models/spree/promotion_code.rb +11 -7
  74. data/app/models/spree/promotion_handler/cart.rb +26 -6
  75. data/app/models/spree/promotion_rule.rb +5 -0
  76. data/app/models/spree/property.rb +1 -1
  77. data/app/models/spree/refund.rb +8 -52
  78. data/app/models/spree/reimbursement.rb +5 -43
  79. data/app/models/spree/reimbursement_performer.rb +2 -8
  80. data/app/models/spree/reimbursement_type/credit.rb +1 -4
  81. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +1 -2
  82. data/app/models/spree/reimbursement_type/store_credit.rb +1 -4
  83. data/app/models/spree/return_authorization.rb +2 -5
  84. data/app/models/spree/return_item.rb +4 -24
  85. data/app/models/spree/shipment.rb +3 -56
  86. data/app/models/spree/shipping_method.rb +0 -25
  87. data/app/models/spree/shipping_rate.rb +0 -2
  88. data/app/models/spree/shipping_rate_tax.rb +1 -1
  89. data/app/models/spree/state.rb +1 -5
  90. data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
  91. data/app/models/spree/stock/availability.rb +11 -3
  92. data/app/models/spree/stock/quantifier.rb +12 -8
  93. data/app/models/spree/stock/simple_coordinator.rb +8 -26
  94. data/app/models/spree/stock/splitter/base.rb +2 -7
  95. data/app/models/spree/stock_item.rb +2 -8
  96. data/app/models/spree/stock_location.rb +2 -2
  97. data/app/models/spree/stock_movement.rb +2 -2
  98. data/app/models/spree/store.rb +0 -12
  99. data/app/models/spree/store_credit.rb +14 -1
  100. data/app/models/spree/store_credit_category.rb +0 -32
  101. data/app/models/spree/store_credit_prioritizer.rb +17 -0
  102. data/app/models/spree/tax/item_tax.rb +3 -2
  103. data/app/models/spree/tax/order_tax.rb +3 -1
  104. data/app/models/spree/tax/tax_helpers.rb +2 -2
  105. data/app/models/spree/tax/tax_location.rb +4 -7
  106. data/app/models/spree/tax_calculator/default.rb +31 -0
  107. data/app/models/spree/tax_calculator/shipping_rate.rb +2 -13
  108. data/app/models/spree/tax_rate.rb +9 -27
  109. data/app/models/spree/taxon/active_storage_attachment.rb +2 -7
  110. data/app/models/spree/taxon/paperclip_attachment.rb +3 -8
  111. data/app/models/spree/taxon.rb +1 -12
  112. data/app/models/spree/taxonomy.rb +1 -1
  113. data/app/models/spree/user_address.rb +0 -5
  114. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +1 -1
  115. data/app/models/spree/variant/price_selector.rb +34 -4
  116. data/app/models/spree/variant.rb +52 -66
  117. data/app/models/spree/zone.rb +1 -1
  118. data/app/subscribers/spree/mailer_subscriber.rb +4 -0
  119. data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
  120. data/config/i18n-tasks.yml +134 -0
  121. data/config/locales/en.yml +406 -263
  122. data/db/migrate/20180416083007_add_apply_to_all_to_variant_property_rule.rb +1 -1
  123. data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
  124. data/db/migrate/20210312061050_change_column_null_on_prices.rb +7 -0
  125. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
  126. data/db/migrate/20220805202442_add_level_to_spree_tax_rates.rb +5 -0
  127. data/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb +5 -0
  128. data/db/seeds.rb +4 -1
  129. data/lib/generators/solidus/install/app_templates/authentication/custom.rb +21 -0
  130. data/lib/generators/solidus/install/app_templates/authentication/devise.rb +16 -0
  131. data/lib/generators/solidus/install/app_templates/authentication/existing.rb +10 -0
  132. data/lib/generators/solidus/install/app_templates/authentication/none.rb +1 -0
  133. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +54 -0
  134. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +16 -0
  135. data/lib/generators/solidus/install/app_templates/frontend/none.rb +2 -0
  136. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +3 -0
  137. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +13 -0
  138. data/lib/generators/solidus/install/app_templates/payment_method/none.rb +1 -0
  139. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +10 -0
  140. data/lib/generators/solidus/install/install_generator.rb +247 -149
  141. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +15 -60
  142. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
  143. data/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt +30 -0
  144. data/lib/generators/solidus/update/update_generator.rb +112 -0
  145. data/lib/generators/spree/custom_user/custom_user_generator.rb +6 -4
  146. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +2 -6
  147. data/lib/generators/spree/custom_user/templates/migration.rb.tt +7 -3
  148. data/lib/generators/spree/dummy/dummy_generator.rb +12 -9
  149. data/lib/generators/spree/dummy/templates/rails/application.rb.tt +0 -1
  150. data/lib/generators/spree/dummy/templates/rails/database.yml +81 -39
  151. data/lib/generators/spree/dummy/templates/rails/storage.yml +3 -0
  152. data/lib/generators/spree/dummy/templates/rails/test.rb +2 -0
  153. data/lib/spree/app_configuration.rb +134 -64
  154. data/lib/spree/bus.rb +20 -0
  155. data/lib/spree/core/class_constantizer.rb +2 -0
  156. data/lib/spree/core/controller_helpers/auth.rb +10 -15
  157. data/lib/spree/core/controller_helpers/current_host.rb +5 -3
  158. data/lib/spree/core/controller_helpers/order.rb +12 -32
  159. data/lib/spree/core/controller_helpers/payment_parameters.rb +0 -54
  160. data/lib/spree/core/controller_helpers/pricing.rb +0 -8
  161. data/lib/spree/core/controller_helpers/search.rb +1 -1
  162. data/lib/spree/core/controller_helpers/strong_parameters.rb +0 -4
  163. data/lib/spree/core/engine.rb +54 -50
  164. data/lib/spree/core/environment_extension.rb +0 -9
  165. data/lib/spree/core/product_filters.rb +1 -41
  166. data/lib/spree/core/role_configuration.rb +0 -14
  167. data/lib/spree/core/search/base.rb +18 -35
  168. data/lib/spree/core/state_machines/order.rb +2 -2
  169. data/lib/spree/core/state_machines.rb +2 -11
  170. data/lib/spree/core/stock_configuration.rb +18 -0
  171. data/lib/spree/core/validators/email.rb +5 -3
  172. data/lib/spree/core/version.rb +5 -1
  173. data/lib/spree/core/versioned_value.rb +75 -0
  174. data/lib/spree/core.rb +40 -11
  175. data/lib/spree/deprecation.rb +1 -1
  176. data/lib/spree/event/configuration.rb +0 -5
  177. data/lib/spree/event/subscriber.rb +0 -18
  178. data/lib/spree/event/subscriber_registry.rb +7 -7
  179. data/lib/spree/event.rb +1 -32
  180. data/lib/spree/i18n.rb +0 -22
  181. data/lib/spree/migrations.rb +13 -11
  182. data/lib/spree/money.rb +3 -18
  183. data/lib/spree/permission_sets/default_customer.rb +8 -1
  184. data/lib/spree/permitted_attributes.rb +17 -59
  185. data/lib/spree/preferences/configuration.rb +84 -0
  186. data/lib/spree/preferences/preferable.rb +13 -0
  187. data/lib/spree/preferences/preferable_class_methods.rb +37 -4
  188. data/lib/spree/preferences/preference_differentiator.rb +29 -0
  189. data/lib/spree/preferences/static_model_preferences.rb +25 -10
  190. data/lib/spree/rails_compatibility.rb +106 -0
  191. data/lib/spree/testing_support/blacklist_urls.rb +1 -1
  192. data/lib/spree/testing_support/bus_helpers.rb +101 -0
  193. data/lib/spree/testing_support/capybara_ext.rb +0 -30
  194. data/lib/spree/testing_support/common_rake.rb +71 -23
  195. data/lib/spree/testing_support/controller_requests.rb +0 -82
  196. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
  197. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
  198. data/lib/spree/testing_support/dummy_app/database.yml +42 -22
  199. data/lib/spree/testing_support/dummy_app/migrations.rb +0 -3
  200. data/lib/spree/testing_support/dummy_app.rb +47 -34
  201. data/lib/spree/testing_support/factories/address_factory.rb +9 -6
  202. data/lib/spree/testing_support/factories/calculator_factory.rb +3 -0
  203. data/lib/spree/testing_support/factories/country_factory.rb +1 -2
  204. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
  205. data/lib/spree/testing_support/factories/order_factory.rb +8 -5
  206. data/lib/spree/testing_support/factories/product_factory.rb +4 -1
  207. data/lib/spree/testing_support/factories/promotion_factory.rb +28 -14
  208. data/lib/spree/testing_support/factories/refund_factory.rb +0 -1
  209. data/lib/spree/testing_support/factories/state_factory.rb +8 -2
  210. data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
  211. data/lib/spree/testing_support/factories/user_factory.rb +6 -0
  212. data/lib/spree/testing_support/factory_bot.rb +2 -2
  213. data/lib/spree/testing_support/order_walkthrough.rb +6 -8
  214. data/lib/spree/testing_support/preferences.rb +0 -25
  215. data/lib/spree/testing_support/silence_deprecations.rb +9 -0
  216. data/lib/tasks/colorado_delivery_fee.rake +28 -0
  217. data/lib/tasks/payment_method.rake +29 -0
  218. data/lib/tasks/solidus/check_orders_with_invalid_email.rake +18 -0
  219. data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +8 -0
  220. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
  221. data/solidus_core.gemspec +14 -7
  222. metadata +127 -78
  223. data/app/mailers/spree/test_mailer.rb +0 -13
  224. data/app/models/concerns/spree/user_payment_source.rb +0 -26
  225. data/app/models/spree/calculator/free_shipping.rb +0 -22
  226. data/app/models/spree/calculator/percent_per_item.rb +0 -51
  227. data/app/models/spree/calculator/price_sack.rb +0 -28
  228. data/app/models/spree/gateway/bogus.rb +0 -13
  229. data/app/models/spree/gateway/bogus_simple.rb +0 -13
  230. data/app/models/spree/gateway.rb +0 -14
  231. data/app/models/spree/order/checkout.rb +0 -244
  232. data/app/models/spree/order_capturing.rb +0 -50
  233. data/app/models/spree/promotion_handler/free_shipping.rb +0 -9
  234. data/app/models/spree/tax/shipping_rate_taxer.rb +0 -24
  235. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
  236. data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
  237. data/lib/generators/spree/install/install_generator.rb +0 -15
  238. data/lib/solidus/migrations/rename_gateways.rb +0 -41
  239. data/lib/spree/core/current_store.rb +0 -24
  240. data/lib/spree/paranoia_deprecations.rb +0 -41
  241. data/lib/spree/promo/environment.rb +0 -12
  242. data/lib/spree/testing_support/bar_ability.rb +0 -19
  243. data/lib/tasks/core.rake +0 -104
  244. data/lib/tasks/email.rake +0 -12
  245. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -119
  246. data/lib/tasks/migrations/migrate_address_names.rake +0 -158
  247. data/lib/tasks/migrations/migrate_default_billing_addresses_to_address_book.rake +0 -26
  248. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +0 -22
  249. data/lib/tasks/migrations/migrate_user_addresses.rake +0 -34
  250. data/lib/tasks/migrations/rename_gateways.rake +0 -23
  251. data/lib/tasks/order_capturing.rake +0 -27
  252. data/lib/tasks/upgrade.rake +0 -13
@@ -1,49 +1,90 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rails/version'
3
4
  require 'rails/generators'
5
+ require 'rails/generators/app_base'
4
6
 
5
7
  module Solidus
6
8
  # @private
7
- class InstallGenerator < Rails::Generators::Base
9
+ class InstallGenerator < Rails::Generators::AppBase
10
+ argument :app_path, type: :string, default: Rails.root
11
+
8
12
  CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"
9
13
 
10
- PAYMENT_METHODS = {
11
- 'paypal' => 'solidus_paypal_commerce_platform',
12
- 'none' => nil,
13
- }
14
+ FRONTENDS = %w[
15
+ none
16
+ classic
17
+ starter
18
+ ]
19
+
20
+ LEGACY_FRONTENDS = %w[
21
+ solidus_starter_frontend
22
+ solidus_frontend
23
+ ]
24
+
25
+ AUTHENTICATIONS = %w[
26
+ devise
27
+ existing
28
+ custom
29
+ none
30
+ ]
31
+
32
+ PAYMENT_METHODS = %w[
33
+ paypal
34
+ bolt
35
+ none
36
+ ]
14
37
 
15
38
  class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
16
39
  class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)'
17
- class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations must be run)'
40
+ class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations and seeds must be run)'
41
+ class_option :active_storage, type: :boolean, default: (
42
+ Rails.gem_version >= Gem::Version.new("6.1.0")
43
+ ), banner: 'Install ActiveStorage as image attachments handler for products and taxons'
18
44
  class_option :auto_accept, type: :boolean
19
45
  class_option :user_class, type: :string
20
46
  class_option :admin_email, type: :string
21
47
  class_option :admin_password, type: :string
22
- class_option :lib_name, type: :string, default: 'spree'
23
- class_option :with_authentication, type: :boolean, default: true
24
- class_option :enforce_available_locales, type: :boolean, default: nil
25
- class_option :payment_method,
26
- type: :string,
27
- enum: PAYMENT_METHODS.keys,
28
- default: PAYMENT_METHODS.keys.first,
29
- desc: "Indicates which payment method to install."
30
-
31
- def self.source_paths
32
- paths = superclass.source_paths
33
- paths << File.expand_path('../templates', "../../#{__FILE__}")
34
- paths << File.expand_path('../templates', "../#{__FILE__}")
35
- paths << File.expand_path('templates', __dir__)
36
- paths.flatten
48
+
49
+ class_option :frontend, type: :string, enum: FRONTENDS + LEGACY_FRONTENDS, default: nil, desc: "Indicates which frontend to install."
50
+ class_option :authentication, type: :string, enum: AUTHENTICATIONS, default: nil, desc: "Indicates which authentication system to install."
51
+ class_option :payment_method, type: :string, enum: PAYMENT_METHODS, default: nil, desc: "Indicates which payment method to install."
52
+
53
+ # DEPRECATED
54
+ class_option :with_authentication, type: :boolean, hide: true, default: nil
55
+ class_option :enforce_available_locales, type: :boolean, hide: true, default: nil
56
+ class_option :lib_name, type: :string, hide: true, default: nil
57
+
58
+ source_root "#{__dir__}/templates"
59
+
60
+ def self.exit_on_failure?
61
+ true
37
62
  end
38
63
 
39
64
  def prepare_options
40
65
  @run_migrations = options[:migrate]
41
- @load_seed_data = options[:seed]
42
- @load_sample_data = options[:sample]
66
+ @load_seed_data = options[:seed] && @run_migrations
67
+ @load_sample_data = options[:sample] && @run_migrations && @load_seed_data
68
+ @selected_frontend = detect_frontend_to_install
69
+ @selected_authentication = detect_authentication_to_install
70
+ @selected_payment_method = detect_payment_method_to_install
71
+
72
+ # Silence verbose output (e.g. Rails migrations will rely on this environment variable)
73
+ ENV['VERBOSE'] = 'false'
74
+
75
+ # No reason to check for their presence if we're about to install them
76
+ ENV['SOLIDUS_SKIP_MIGRATIONS_CHECK'] = 'true'
77
+
78
+ if options[:enforce_available_locales] != nil
79
+ warn \
80
+ "DEPRECATION WARNING: using `solidus:install --enforce-available-locales` is now deprecated and has no effect. " \
81
+ "Since Rails 4.1 the default is `true` so we no longer need to explicitly set a value."
82
+ end
43
83
 
44
- unless @run_migrations
45
- @load_seed_data = false
46
- @load_sample_data = false
84
+ if options[:lib_name] != nil
85
+ warn \
86
+ "DEPRECATION WARNING: using `solidus:install --lib-name` is now deprecated and has no effect. " \
87
+ "The option is legacy and should be removed from scripts still using it."
47
88
  end
48
89
  end
49
90
 
@@ -51,37 +92,24 @@ module Solidus
51
92
  template 'config/initializers/spree.rb.tt', 'config/initializers/spree.rb'
52
93
  end
53
94
 
54
- def additional_tweaks
55
- return unless File.exist? 'public/robots.txt'
56
-
57
- append_file "public/robots.txt", <<-ROBOTS.strip_heredoc
58
- User-agent: *
59
- Disallow: /checkout
60
- Disallow: /cart
61
- Disallow: /orders
62
- Disallow: /user
63
- Disallow: /account
64
- Disallow: /api
65
- Disallow: /password
66
- ROBOTS
95
+ def install_file_attachment
96
+ if options[:active_storage]
97
+ say_status :assets, "Active Storage", :green
98
+ rake 'active_storage:install'
99
+ else
100
+ say_status :assets, "Paperclip", :green
101
+ gsub_file 'config/initializers/spree.rb', "ActiveStorageAttachment", "PaperclipAttachment"
102
+ end
67
103
  end
68
104
 
69
105
  def setup_assets
70
- @lib_name = 'spree'
71
-
72
106
  empty_directory 'app/assets/images'
73
107
 
74
108
  %w{javascripts stylesheets images}.each do |path|
75
- empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test?
76
- empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test?
109
+ empty_directory "vendor/assets/#{path}/spree/backend" if defined?(Spree::Backend) || Rails.env.test?
77
110
  end
78
111
 
79
- if defined? Spree::Frontend || Rails.env.test?
80
- template "vendor/assets/javascripts/spree/frontend/all.js"
81
- template "vendor/assets/stylesheets/spree/frontend/all.css"
82
- end
83
-
84
- if defined? Spree::Backend || Rails.env.test?
112
+ if defined?(Spree::Backend) || Rails.env.test?
85
113
  template "vendor/assets/javascripts/spree/backend/all.js"
86
114
  template "vendor/assets/stylesheets/spree/backend/all.css"
87
115
  end
@@ -91,73 +119,15 @@ module Solidus
91
119
  empty_directory "app/overrides"
92
120
  end
93
121
 
94
- def configure_application
95
- application <<-RUBY
96
- # Load application's model / class decorators
97
- initializer 'spree.decorators' do |app|
98
- config.to_prepare do
99
- Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path|
100
- require_dependency(path)
101
- end
102
- end
103
- end
104
- RUBY
105
-
106
- if !options[:enforce_available_locales].nil?
107
- application <<-RUBY
108
- # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e
109
- I18n.enforce_available_locales = #{options[:enforce_available_locales]}
110
- RUBY
111
- end
112
- end
113
-
114
- def plugin_install_preparation
115
- @plugins_to_be_installed = []
116
- @plugin_generators_to_run = []
117
- end
118
-
119
- def install_auth_plugin
120
- if options[:with_authentication] && (options[:auto_accept] || !no?("
121
- Solidus has a default authentication extension that uses Devise.
122
- You can find more info at https://github.com/solidusio/solidus_auth_devise.
123
-
124
- Would you like to install it? (y/n)"))
125
-
126
- @plugins_to_be_installed << 'solidus_auth_devise'
127
- @plugin_generators_to_run << 'solidus:auth:install'
128
- end
129
- end
130
-
131
- def install_payment_method
132
- name = options[:payment_method]
133
-
134
- unless options[:auto_accept]
135
- available_names = PAYMENT_METHODS.keys
136
-
137
- name = ask("
138
- You can select a payment method to be included in the installation process.
139
- Please select a payment method name:", limited_to: available_names, default: available_names.first)
140
- end
141
-
142
- gem_name = PAYMENT_METHODS.fetch(name)
143
-
144
- if gem_name
145
- @plugins_to_be_installed << gem_name
146
- @plugin_generators_to_run << "#{gem_name}:install"
147
- end
148
- end
149
-
150
122
  def include_seed_data
151
- append_file "db/seeds.rb", <<-RUBY.strip_heredoc
152
-
153
- Spree::Core::Engine.load_seed if defined?(Spree::Core)
154
- Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
123
+ append_file "db/seeds.rb", <<~RUBY
124
+ Spree::Core::Engine.load_seed
155
125
  RUBY
156
126
  end
157
127
 
158
128
  def install_migrations
159
129
  say_status :copying, "migrations"
160
- `rake railties:install:migrations`
130
+ rake 'railties:install:migrations'
161
131
  end
162
132
 
163
133
  def create_database
@@ -165,16 +135,18 @@ module Solidus
165
135
  rake 'db:create'
166
136
  end
167
137
 
168
- def run_bundle_install_if_needed_by_plugins
169
- @plugins_to_be_installed.each do |plugin_name|
170
- gem plugin_name
171
- end
172
-
173
- bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
174
- run "spring stop" if defined?(Spring)
175
-
176
- @plugin_generators_to_run.each do |plugin_generator_name|
177
- generate "#{plugin_generator_name} --skip_migrations=false"
138
+ def install_routes
139
+ if Pathname(app_path).join('config', 'routes.rb').read.include? CORE_MOUNT_ROUTE
140
+ say_status :route_exist, CORE_MOUNT_ROUTE, :blue
141
+ else
142
+ route <<~RUBY
143
+ # This line mounts Solidus's routes at the root of your application.
144
+ # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
145
+ # If you would like to change where this engine is mounted, simply change the :at option to something different.
146
+ #
147
+ # We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
148
+ #{CORE_MOUNT_ROUTE}, at: '/'
149
+ RUBY
178
150
  end
179
151
  end
180
152
 
@@ -182,15 +154,27 @@ module Solidus
182
154
  if @run_migrations
183
155
  say_status :running, "migrations"
184
156
 
185
- rake 'db:migrate VERBOSE=false'
157
+ rake 'db:migrate'
186
158
  else
187
159
  say_status :skipping, "migrations (don't forget to run rake db:migrate)"
188
160
  end
189
161
  end
190
162
 
163
+ def install_authentication
164
+ apply_template_for :authentication, @selected_authentication
165
+ end
166
+
167
+ def install_frontend
168
+ apply_template_for :frontend, @selected_frontend
169
+ end
170
+
171
+ def install_payment_method
172
+ apply_template_for :payment_method, @selected_payment_method
173
+ end
174
+
191
175
  def populate_seed_data
192
176
  if @load_seed_data
193
- say_status :loading, "seed data"
177
+ say_status :loading, "seed data"
194
178
  rake_options = []
195
179
  rake_options << "AUTO_ACCEPT=1" if options[:auto_accept]
196
180
  rake_options << "ADMIN_EMAIL=#{options[:admin_email]}" if options[:admin_email]
@@ -211,43 +195,157 @@ module Solidus
211
195
  end
212
196
  end
213
197
 
214
- def install_routes
215
- routes_file_path = File.join('config', 'routes.rb')
216
- unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
217
- insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
218
- <<-RUBY
219
- # This line mounts Solidus's routes at the root of your application.
220
- # This means, any requests to URLs such as /products, will go to Spree::ProductsController.
221
- # If you would like to change where this engine is mounted, simply change the :at option to something different.
222
- #
223
- # We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
224
- #{CORE_MOUNT_ROUTE}, at: '/'
225
-
226
- RUBY
198
+ def complete
199
+ say_status :complete, "Solidus has been installed successfully. Enjoy!"
200
+ end
201
+
202
+ private
203
+
204
+ def generate(what, *args, abort_on_failure: true)
205
+ args << '--auto-accept' if options[:auto_accept]
206
+ args << '--auto-run-migrations' if options[:migrate]
207
+ super(what, *args, abort_on_failure: abort_on_failure)
208
+ end
209
+
210
+ def bundle_command(command, env = {})
211
+ # Make `bundle install` less verbose by skipping the "Using ..." messages
212
+ super(command, env.reverse_merge('BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES' => 'true'))
213
+ ensure
214
+ Bundler.reset_paths!
215
+ end
216
+
217
+ def ask_with_description(desc:, limited_to:, default:)
218
+ loop do
219
+ say_status :question, desc, :yellow
220
+ answer = ask(set_color("answer:".rjust(13), :blue, :bold)).to_s.downcase.presence
221
+
222
+ case answer
223
+ when nil
224
+ say_status :using, "#{default} (default)"
225
+ break default
226
+ when *limited_to.map(&:to_s)
227
+ say_status :using, answer
228
+ break answer
229
+ else say_status :error, "Please select a valid answer:", :red
227
230
  end
228
231
  end
232
+ end
229
233
 
230
- unless options[:quiet]
231
- puts "*" * 50
232
- puts "We added the following line to your application's config/routes.rb file:"
233
- puts " "
234
- puts " #{CORE_MOUNT_ROUTE}, at: '/'"
234
+ def apply_template_for(topic, selected)
235
+ template_path = Dir["#{__dir__}/app_templates/#{topic}/*.rb"].find do |path|
236
+ File.basename(path, '.rb') == selected
235
237
  end
238
+
239
+ unless template_path
240
+ say_status :warning, "Unknown #{topic}: #{selected.inspect}, attempting to run it with `rails app:template`"
241
+ template_path = selected
242
+ end
243
+
244
+ say_status :installing, "[#{topic}] #{selected}", :blue
245
+ apply template_path
236
246
  end
237
247
 
238
- def complete
239
- unless options[:quiet]
240
- puts "*" * 50
241
- puts "Solidus has been installed successfully. You're all ready to go!"
242
- puts " "
243
- puts "Enjoy!"
248
+ def with_env(vars)
249
+ original = ENV.to_hash
250
+ vars.each { |k, v| ENV[k] = v }
251
+
252
+ begin
253
+ yield
254
+ ensure
255
+ ENV.replace(original)
244
256
  end
245
257
  end
246
258
 
247
- private
259
+ def detect_frontend_to_install
260
+ # We need to support names that were available in v3.2
261
+ selected_frontend = 'starter' if options[:frontend] == 'solidus_starter_frontend'
262
+ selected_frontend = 'classic' if options[:frontend] == 'solidus_frontend'
263
+ selected_frontend ||= options[:frontend]
264
+
265
+ ENV['FRONTEND'] ||
266
+ selected_frontend ||
267
+ (Bundler.locked_gems.dependencies['solidus_frontend'] && 'classic') ||
268
+ (options[:auto_accept] && 'starter') ||
269
+ ask_with_description(
270
+ default: 'starter',
271
+ limited_to: FRONTENDS,
272
+ desc: <<~TEXT
273
+ Which frontend would you like to use?
274
+
275
+ - [#{set_color 'starter', :bold}] Generate all necessary controllers and views directly in your Rails app (#{set_color :default, :bold}).
276
+ - [#{set_color 'classic', :bold}] Install `solidus_frontend`, was the default in previous solidus versions (#{set_color :deprecated, :bold}).
277
+ - [#{set_color 'none', :bold}] Skip installing a frontend.
278
+
279
+ Selecting `starter` is recommended, however, some extensions are still only compatible with `classic`.
280
+ TEXT
281
+ )
282
+ end
283
+
284
+ def detect_authentication_to_install
285
+ return 'devise' if @selected_frontend == 'starter'
286
+
287
+ if options[:with_authentication] != nil
288
+ say_status :warning, \
289
+ "Using `solidus:install --with-authentication` is now deprecated. " \
290
+ "Please use `--authentication` instead (see --help for the full list of options).",
291
+ :red
292
+
293
+ if options[:with_authentication] == 'false'
294
+ # Don't use the default authentication if the user explicitly
295
+ # requested no authentication system.
296
+ return 'none'
297
+ else
298
+ return 'devise'
299
+ end
300
+ end
301
+
302
+ ENV['AUTHENTICATION'] ||
303
+ options[:authentication] ||
304
+ (Bundler.locked_gems.dependencies['solidus_auth_devise'] && 'devise') ||
305
+ (options[:auto_accept] && 'devise') ||
306
+ ask_with_description(
307
+ default: 'devise',
308
+ limited_to: AUTHENTICATIONS,
309
+ desc: <<~TEXT
310
+ Which authentication would you like to use?
311
+
312
+ - [#{set_color 'devise', :bold}] Install and configure the standard `devise` integration. (#{set_color :default, :bold}).
313
+ - [#{set_color 'existing', :bold}] Integrate and configure an existing `devise` setup.
314
+ - [#{set_color 'custom', :bold}] A starter configuration for rolling your own authentication system.
315
+ - [#{set_color 'none', :bold}] Don't add any configuration for authentication.
316
+
317
+ Selecting `devise` is recommended.
318
+ TEXT
319
+ )
320
+ end
321
+
322
+ def detect_payment_method_to_install
323
+ return 'paypal' if Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform']
324
+ return 'bolt' if Bundler.locked_gems.dependencies['solidus_bolt']
325
+
326
+ descriptions = {
327
+ paypal: "- [#{set_color 'paypal', :bold}] Install `solidus_paypal_commerce_platform` (#{set_color :default, :bold}).",
328
+ bolt: "- [#{set_color 'bolt', :bold}] Install `solidus_bolt`.",
329
+ none: "- [#{set_color 'none', :bold}] Skip installing a payment method.",
330
+ }
331
+
332
+ payment_methods = PAYMENT_METHODS
333
+
334
+ if @selected_frontend != 'classic'
335
+ payment_methods -= ['bolt']
336
+ descriptions.delete(:bolt)
337
+ end
338
+
339
+ selected = options[:payment_method] || (options[:auto_accept] && 'paypal') ||
340
+ ask_with_description(
341
+ default: 'paypal',
342
+ limited_to: payment_methods,
343
+ desc: <<~TEXT
344
+ Which payment method would you like to use?
248
345
 
249
- def bundle_cleanly(&block)
250
- Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
346
+ #{descriptions.values.join("\n")}
347
+ TEXT
348
+ )
251
349
  end
252
350
  end
253
351
  end
@@ -1,24 +1,14 @@
1
1
  # Configure Solidus Preferences
2
2
  # See http://docs.solidus.io/Spree/AppConfiguration.html for details
3
3
 
4
+ # Solidus version defaults for preferences that are not overridden
5
+ Spree.load_defaults '<%= Spree.solidus_version %>'
6
+
4
7
  Spree.config do |config|
5
8
  # Core:
6
-
7
9
  # Default currency for new sites
8
10
  config.currency = "USD"
9
11
 
10
- # from address for transactional emails
11
- config.mails_from = "store@example.com"
12
-
13
- # Use combined first and last name attribute in HTML views and API responses
14
- config.use_combined_first_and_last_name_in_address = true
15
-
16
- # Use legacy Spree::Order state machine
17
- config.use_legacy_order_state_machine = false
18
-
19
- # Use the legacy address' state validation logic
20
- config.use_legacy_address_state_validator = false
21
-
22
12
  # Uncomment to stop tracking inventory levels in the application
23
13
  # config.track_inventory_levels = false
24
14
 
@@ -27,54 +17,17 @@ Spree.config do |config|
27
17
  # any inventory changes.
28
18
  # config.inventory_cache_threshold = 3
29
19
 
30
- # Enable Paperclip adapter for attachments on images and taxons
31
- config.image_attachment_module = 'Spree::Image::PaperclipAttachment'
32
- config.taxon_attachment_module = 'Spree::Taxon::PaperclipAttachment'
33
-
34
- # Disable legacy Solidus custom CanCanCan actions aliases
35
- config.use_custom_cancancan_actions = false
20
+ # Configure adapter for attachments on products and taxons (use ActiveStorageAttachment or PaperclipAttachment)
21
+ config.image_attachment_module = 'Spree::Image::ActiveStorageAttachment'
22
+ config.taxon_attachment_module = 'Spree::Taxon::ActiveStorageAttachment'
36
23
 
37
24
  # Defaults
38
-
39
- # Set this configuration to `true` to raise an exception when
40
- # an order is populated with a line item with a mismatching
41
- # currency. The `false` value will just add a validation error
42
- # and will be the only behavior accepted in future versions.
43
- # See https://github.com/solidusio/solidus/pull/3456 for more info.
44
- config.raise_with_invalid_currency = false
45
-
46
- # Set this configuration to false to always redirect the user to
47
- # /unauthorized when needed, without trying to redirect them to
48
- # their previous location first.
49
- config.redirect_back_on_unauthorized = true
50
-
51
- # Set this configuration to `true` to allow promotions
52
- # with no associated actions to be considered active for use by customers.
53
- # See https://github.com/solidusio/solidus/pull/3749 for more info.
54
- config.consider_actionless_promotion_active = false
55
-
56
- # Set this configuration to `false` to avoid running validations when
57
- # updating an order. Be careful since you can end up having inconsistent
58
- # data in your database turning it on.
59
- # See https://github.com/solidusio/solidus/pull/3645 for more info.
60
- config.run_order_validations_on_order_updater = true
61
-
62
25
  # Permission Sets:
63
26
 
64
27
  # Uncomment and customize the following line to add custom permission sets
65
28
  # to a custom users role:
66
29
  # config.roles.assign_permissions :role_name, ['Spree::PermissionSets::CustomPermissionSet']
67
30
 
68
-
69
- # Frontend:
70
-
71
- # Custom logo for the frontend
72
- # config.logo = "logo/solidus.svg"
73
-
74
- # Template to use when rendering layout
75
- # config.layout = "spree/layouts/spree_application"
76
-
77
-
78
31
  # Admin:
79
32
 
80
33
  # Custom logo for the admin
@@ -96,12 +49,6 @@ Spree.config do |config|
96
49
  # )
97
50
  end
98
51
 
99
- <% if defined?(Spree::Frontend::Engine) -%>
100
- Spree::Frontend::Config.configure do |config|
101
- config.locale = 'en'
102
- end
103
- <% end -%>
104
-
105
52
  <% if defined?(Spree::Backend::Engine) -%>
106
53
  Spree::Backend::Config.configure do |config|
107
54
  config.locale = 'en'
@@ -114,6 +61,12 @@ Spree::Backend::Config.configure do |config|
114
61
  # 'icon-name',
115
62
  # url: 'https://solidus.io/'
116
63
  # )
64
+
65
+ # Custom frontend product path
66
+ #
67
+ # config.frontend_product_path = ->(template_context, product) {
68
+ # template_context.spree.product_path(product)
69
+ # }
117
70
  end
118
71
  <% end -%>
119
72
 
@@ -123,7 +76,9 @@ Spree::Api::Config.configure do |config|
123
76
  end
124
77
  <% end -%>
125
78
 
126
- Spree.user_class = <%= (options[:user_class].blank? ? "Spree::LegacyUser" : options[:user_class]).inspect %>
79
+ <% if options[:user_class].present? -%>
80
+ Spree.user_class = <%= options[:user_class].inspect %>
81
+ <% end -%>
127
82
 
128
83
  # Rules for avoiding to store the current path into session for redirects
129
84
  # When at least one rule is matched, the request path will not be stored
@@ -1,10 +1,10 @@
1
1
  // This is a manifest file that'll be compiled into including all the files listed below.
2
- // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
2
+ // Add new JavaScript code in separate files in this directory and they'll automatically
3
3
  // be included in the compiled file accessible from http://example.com/assets/application.js
4
4
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
5
  // the compiled file.
6
6
  //
7
- //= require jquery
7
+ //= require jquery3
8
8
  //= require rails-ujs
9
9
  //= require spree/backend
10
10
  //= require_tree .
@@ -0,0 +1,30 @@
1
+ # This initializer lets you preview the defaults that have changed on the new
2
+ # Solidus version.
3
+ #
4
+ # It allows you to enable them one by one while you adapt your application.
5
+ # When you're done with all of them, you can safely remove this file and add
6
+ # the updated `load_defaults` calls to the top of the config blocks in your
7
+ # Solidus main initializer. You can also call `Spree.load_defaults(version)` to
8
+ # target all components at once.
9
+
10
+ Spree.config do |config|
11
+ <%= @core_changes %>
12
+ end
13
+
14
+ <% if defined?(Spree::Frontend::Engine) -%>
15
+ Spree::Frontend::Config.configure do |config|
16
+ <%= @frontend_changes %>
17
+ end
18
+ <% end -%>
19
+
20
+ <% if defined?(Spree::Backend::Engine) -%>
21
+ Spree::Backend::Config.configure do |config|
22
+ <%= @backend_changes %>
23
+ end
24
+ <% end -%>
25
+
26
+ <% if defined?(Spree::Api::Engine) -%>
27
+ Spree::Api::Config.configure do |config|
28
+ <%= @api_changes %>
29
+ end
30
+ <% end -%>