solidus_core 3.1.8 → 3.2.0.alpha

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.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/products_helper.rb +1 -1
  3. data/app/models/concerns/spree/active_storage_adapter/attachment.rb +23 -10
  4. data/app/models/concerns/spree/active_storage_adapter.rb +1 -1
  5. data/app/models/concerns/spree/user_address_book.rb +11 -1
  6. data/app/models/spree/adjustment.rb +1 -0
  7. data/app/models/spree/carton.rb +1 -1
  8. data/app/models/spree/option_value.rb +9 -0
  9. data/app/models/spree/order.rb +68 -29
  10. data/app/models/spree/order_contents.rb +2 -1
  11. data/app/models/spree/order_inventory.rb +1 -1
  12. data/app/models/spree/order_merger.rb +2 -2
  13. data/app/models/spree/order_taxation.rb +6 -4
  14. data/app/models/spree/order_updater.rb +4 -3
  15. data/app/models/spree/payment_method.rb +11 -0
  16. data/app/models/spree/price.rb +1 -1
  17. data/app/models/spree/product/scopes.rb +21 -3
  18. data/app/models/spree/product.rb +1 -1
  19. data/app/models/spree/promotion/actions/create_adjustment.rb +4 -0
  20. data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -6
  21. data/app/models/spree/promotion/rules/product.rb +20 -8
  22. data/app/models/spree/promotion/rules/store.rb +4 -0
  23. data/app/models/spree/promotion/rules/taxon.rb +4 -0
  24. data/app/models/spree/promotion/rules/user.rb +4 -0
  25. data/app/models/spree/promotion.rb +34 -23
  26. data/app/models/spree/promotion_action.rb +4 -0
  27. data/app/models/spree/promotion_code.rb +8 -4
  28. data/app/models/spree/promotion_handler/cart.rb +26 -6
  29. data/app/models/spree/promotion_rule.rb +5 -0
  30. data/app/models/spree/reimbursement.rb +2 -2
  31. data/app/models/spree/return_item.rb +1 -2
  32. data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
  33. data/app/models/spree/stock/quantifier.rb +12 -8
  34. data/app/models/spree/stock/simple_coordinator.rb +2 -1
  35. data/app/models/spree/tax/item_tax.rb +3 -2
  36. data/app/models/spree/tax/order_tax.rb +3 -1
  37. data/app/models/spree/tax/tax_location.rb +4 -7
  38. data/app/models/spree/tax_rate.rb +2 -0
  39. data/app/models/spree/variant.rb +1 -1
  40. data/app/subscribers/spree/mailer_subscriber.rb +4 -0
  41. data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
  42. data/config/locales/en.yml +7 -249
  43. data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
  44. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
  45. data/lib/generators/solidus/install/install_generator/bundler_context.rb +97 -0
  46. data/lib/generators/solidus/install/install_generator/install_frontend.rb +50 -0
  47. data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +48 -0
  48. data/lib/generators/solidus/install/install_generator.rb +56 -49
  49. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +6 -16
  50. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
  51. data/lib/spree/app_configuration.rb +29 -3
  52. data/lib/spree/bus.rb +20 -0
  53. data/lib/spree/core/controller_helpers/auth.rb +9 -1
  54. data/lib/spree/core/controller_helpers/current_host.rb +1 -3
  55. data/lib/spree/core/controller_helpers/order.rb +10 -10
  56. data/lib/spree/core/controller_helpers/search.rb +1 -1
  57. data/lib/spree/core/engine.rb +33 -8
  58. data/lib/spree/core/state_machines/order.rb +1 -1
  59. data/lib/spree/core/stock_configuration.rb +18 -0
  60. data/lib/spree/core/validators/email.rb +3 -1
  61. data/lib/spree/core/version.rb +1 -1
  62. data/lib/spree/core.rb +20 -0
  63. data/lib/spree/event/subscriber_registry.rb +4 -6
  64. data/lib/spree/event.rb +1 -1
  65. data/lib/spree/migrations.rb +1 -1
  66. data/lib/spree/permission_sets/default_customer.rb +8 -1
  67. data/lib/spree/permitted_attributes.rb +4 -4
  68. data/lib/spree/preferences/configuration.rb +34 -12
  69. data/lib/spree/preferences/preferable_class_methods.rb +1 -1
  70. data/lib/spree/preferences/preference_differentiator.rb +2 -1
  71. data/lib/spree/preferences/static_model_preferences.rb +0 -2
  72. data/lib/spree/rails_compatibility.rb +99 -0
  73. data/lib/spree/testing_support/bus_helpers.rb +101 -0
  74. data/lib/spree/testing_support/common_rake.rb +47 -19
  75. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
  76. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
  77. data/lib/spree/testing_support/dummy_app.rb +6 -2
  78. data/lib/spree/testing_support/factories/address_factory.rb +7 -2
  79. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
  80. data/lib/spree/testing_support/factories/order_factory.rb +8 -4
  81. data/lib/spree/testing_support/factories/product_factory.rb +4 -1
  82. data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
  83. data/lib/spree/testing_support/factory_bot.rb +1 -1
  84. data/lib/spree/testing_support/order_walkthrough.rb +5 -4
  85. data/lib/spree/testing_support/silence_deprecations.rb +9 -0
  86. data/lib/tasks/payment_method.rake +29 -0
  87. data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +2 -2
  88. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
  89. data/solidus_core.gemspec +6 -2
  90. metadata +71 -26
  91. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
  92. data/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +0 -9
@@ -365,7 +365,7 @@ en:
365
365
  amount_authorized: Amount Authorized
366
366
  amount_credited: Amount Credited
367
367
  amount_used: Amount Used
368
- category_id: Credit Type
368
+ category_id: Category
369
369
  created_at: Issued On
370
370
  created_by_id: Created By
371
371
  invalidated_at: Invalidated
@@ -866,6 +866,10 @@ en:
866
866
  new_price: New Price
867
867
  new:
868
868
  new_price: New Price
869
+ master_variant_table:
870
+ master_variant: Master Variant Prices
871
+ table:
872
+ variant_pricing: Variant Prices
869
873
  promotions:
870
874
  actions:
871
875
  calculator_label: Calculated by
@@ -998,9 +1002,11 @@ en:
998
1002
  edit_variant: Edit Variant
999
1003
  form:
1000
1004
  dimensions: Dimensions
1005
+ options: Options
1001
1006
  pricing: Pricing
1002
1007
  pricing_hint: These values are populated from the product details page and
1003
1008
  can be overridden below
1009
+ properties: Properties
1004
1010
  use_product_tax_category: Use Product Tax Category
1005
1011
  new:
1006
1012
  new_variant: New Variant
@@ -1172,257 +1178,10 @@ en:
1172
1178
  country_based: Country Based
1173
1179
  country_name: Name
1174
1180
  country_names:
1175
- AD: Andorra
1176
- AE: United Arab Emirates
1177
- AF: Afghanistan
1178
- AG: Antigua and Barbuda
1179
- AI: Anguilla
1180
- AL: Albania
1181
- AM: Armenia
1182
- AO: Angola
1183
- AQ: Antarctica
1184
- AR: Argentina
1185
- AS: American Samoa
1186
- AT: Austria
1187
- AU: Australia
1188
- AW: Aruba
1189
- AX: Åland Islands
1190
- AZ: Azerbaijan
1191
- BA: Bosnia and Herzegovina
1192
- BB: Barbados
1193
- BD: Bangladesh
1194
- BE: Belgium
1195
- BF: Burkina Faso
1196
- BG: Bulgaria
1197
- BH: Bahrain
1198
- BI: Burundi
1199
- BJ: Benin
1200
- BL: Saint Barthélemy
1201
- BM: Bermuda
1202
- BN: Brunei Darussalam
1203
- BO: Bolivia, Plurinational State of
1204
- BQ: Bonaire, Sint Eustatius and Saba
1205
- BR: Brazil
1206
- BS: Bahamas
1207
- BT: Bhutan
1208
- BV: Bouvet Island
1209
- BW: Botswana
1210
- BY: Belarus
1211
- BZ: Belize
1212
1181
  CA: Canada
1213
- CC: Cocos (Keeling) Islands
1214
- CD: Congo, The Democratic Republic of the
1215
- CF: Central African Republic
1216
- CG: Congo
1217
- CH: Switzerland
1218
- CI: Côte d'Ivoire
1219
- CK: Cook Islands
1220
- CL: Chile
1221
- CM: Cameroon
1222
- CN: China
1223
- CO: Colombia
1224
- CR: Costa Rica
1225
- CU: Cuba
1226
- CV: Cabo Verde
1227
- CW: Curaçao
1228
- CX: Christmas Island
1229
- CY: Cyprus
1230
- CZ: Czechia
1231
- DE: Germany
1232
- DJ: Djibouti
1233
- DK: Denmark
1234
- DM: Dominica
1235
- DO: Dominican Republic
1236
- DZ: Algeria
1237
- EC: Ecuador
1238
- EE: Estonia
1239
- EG: Egypt
1240
- EH: Western Sahara
1241
- ER: Eritrea
1242
- ES: Spain
1243
- ET: Ethiopia
1244
- FI: Finland
1245
- FJ: Fiji
1246
- FK: Falkland Islands (Malvinas)
1247
- FM: Micronesia, Federated States of
1248
- FO: Faroe Islands
1249
- FR: France
1250
1182
  FRA: France
1251
- GA: Gabon
1252
- GB: United Kingdom
1253
- GD: Grenada
1254
- GE: Georgia
1255
- GF: French Guiana
1256
- GG: Guernsey
1257
- GH: Ghana
1258
- GI: Gibraltar
1259
- GL: Greenland
1260
- GM: Gambia
1261
- GN: Guinea
1262
- GP: Guadeloupe
1263
- GQ: Equatorial Guinea
1264
- GR: Greece
1265
- GS: South Georgia and the South Sandwich Islands
1266
- GT: Guatemala
1267
- GU: Guam
1268
- GW: Guinea-Bissau
1269
- GY: Guyana
1270
- HK: Hong Kong
1271
- HM: Heard Island and McDonald Islands
1272
- HN: Honduras
1273
- HR: Croatia
1274
- HT: Haiti
1275
- HU: Hungary
1276
- ID: Indonesia
1277
- IE: Ireland
1278
- IL: Israel
1279
- IM: Isle of Man
1280
- IN: India
1281
- IO: British Indian Ocean Territory
1282
- IQ: Iraq
1283
- IR: Iran, Islamic Republic of
1284
- IS: Iceland
1285
- IT: Italy
1286
1183
  ITA: Italy
1287
- JE: Jersey
1288
- JM: Jamaica
1289
- JO: Jordan
1290
- JP: Japan
1291
- KE: Kenya
1292
- KG: Kyrgyzstan
1293
- KH: Cambodia
1294
- KI: Kiribati
1295
- KM: Comoros
1296
- KN: Saint Kitts and Nevis
1297
- KP: Korea, Democratic People's Republic of
1298
- KR: Korea, Republic of
1299
- KW: Kuwait
1300
- KY: Cayman Islands
1301
- KZ: Kazakhstan
1302
- LA: Lao People's Democratic Republic
1303
- LB: Lebanon
1304
- LC: Saint Lucia
1305
- LI: Liechtenstein
1306
- LK: Sri Lanka
1307
- LR: Liberia
1308
- LS: Lesotho
1309
- LT: Lithuania
1310
- LU: Luxembourg
1311
- LV: Latvia
1312
- LY: Libya
1313
- MA: Morocco
1314
- MC: Monaco
1315
- MD: Moldova, Republic of
1316
- ME: Montenegro
1317
- MF: Saint Martin (French part)
1318
- MG: Madagascar
1319
- MH: Marshall Islands
1320
- MK: North Macedonia
1321
- ML: Mali
1322
- MM: Myanmar
1323
- MN: Mongolia
1324
- MO: Macao
1325
- MP: Northern Mariana Islands
1326
- MQ: Martinique
1327
- MR: Mauritania
1328
- MS: Montserrat
1329
- MT: Malta
1330
- MU: Mauritius
1331
- MV: Maldives
1332
- MW: Malawi
1333
- MX: Mexico
1334
- MY: Malaysia
1335
- MZ: Mozambique
1336
- NA: Namibia
1337
- NC: New Caledonia
1338
- NE: Niger
1339
- NF: Norfolk Island
1340
- NG: Nigeria
1341
- NI: Nicaragua
1342
- NL: Netherlands
1343
- 'NO': Norway
1344
- NP: Nepal
1345
- NR: Nauru
1346
- NU: Niue
1347
- NZ: New Zealand
1348
- OM: Oman
1349
- PA: Panama
1350
- PE: Peru
1351
- PF: French Polynesia
1352
- PG: Papua New Guinea
1353
- PH: Philippines
1354
- PK: Pakistan
1355
- PL: Poland
1356
- PM: Saint Pierre and Miquelon
1357
- PN: Pitcairn
1358
- PR: Puerto Rico
1359
- PS: Palestine, State of
1360
- PT: Portugal
1361
- PW: Palau
1362
- PY: Paraguay
1363
- QA: Qatar
1364
- RE: Réunion
1365
- RO: Romania
1366
- RS: Serbia
1367
- RU: Russia
1368
- RW: Rwanda
1369
- SA: Saudi Arabia
1370
- SB: Solomon Islands
1371
- SC: Seychelles
1372
- SD: Sudan
1373
- SE: Sweden
1374
- SG: Singapore
1375
- SH: Saint Helena, Ascension and Tristan da Cunha
1376
- SI: Slovenia
1377
- SJ: Svalbard and Jan Mayen
1378
- SK: Slovakia
1379
- SL: Sierra Leone
1380
- SM: San Marino
1381
- SN: Senegal
1382
- SO: Somalia
1383
- SR: Suriname
1384
- SS: South Sudan
1385
- ST: Sao Tome and Principe
1386
- SV: El Salvador
1387
- SX: Sint Maarten (Dutch part)
1388
- SY: Syrian Arab Republic
1389
- SZ: Eswatini
1390
- TC: Turks and Caicos Islands
1391
- TD: Chad
1392
- TF: French Southern Territories
1393
- TG: Togo
1394
- TH: Thailand
1395
- TJ: Tajikistan
1396
- TK: Tokelau
1397
- TL: Timor-Leste
1398
- TM: Turkmenistan
1399
- TN: Tunisia
1400
- TO: Tonga
1401
- TR: Turkey
1402
- TT: Trinidad and Tobago
1403
- TV: Tuvalu
1404
- TW: Taiwan
1405
- TZ: Tanzania, United Republic of
1406
- UA: Ukraine
1407
- UG: Uganda
1408
- UM: United States Minor Outlying Islands
1409
1184
  US: United States of America
1410
- UY: Uruguay
1411
- UZ: Uzbekistan
1412
- VA: Holy See (Vatican City State)
1413
- VC: Saint Vincent and the Grenadines
1414
- VE: Venezuela, Bolivarian Republic of
1415
- VG: Virgin Islands, British
1416
- VI: Virgin Islands, U.S.
1417
- VN: Vietnam
1418
- VU: Vanuatu
1419
- WF: Wallis and Futuna
1420
- WS: Samoa
1421
- YE: Yemen
1422
- YT: Mayotte
1423
- ZA: South Africa
1424
- ZM: Zambia
1425
- ZW: Zimbabwe
1426
1185
  coupon: Coupon
1427
1186
  coupon_code: Coupon code
1428
1187
  coupon_code_already_applied: The coupon code has already been applied to this
@@ -2497,7 +2256,6 @@ en:
2497
2256
  value: Value
2498
2257
  variant: Variant
2499
2258
  variant_placeholder: Choose a Variant
2500
- variant_pricing: Variant Pricing
2501
2259
  variant_properties: Variant Properties
2502
2260
  variant_search: Variant Search
2503
2261
  variant_search_placeholder: SKU or Option Value
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddTypeBeforeRemovalToSpreePaymentMethods < ActiveRecord::Migration[5.2]
4
+ def change
5
+ add_column :spree_payment_methods, :type_before_removal, :string
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SetPromotionsWithAnyPolicyToAllIfPossible < ActiveRecord::Migration[5.2]
4
+ def up
5
+ Spree::Promotion.where(match_policy: :any).includes(:promotion_rules).all.each do |promotion|
6
+ if promotion.promotion_rules.length <= 1
7
+ promotion.update!(match_policy: :all)
8
+ else
9
+ raise StandardError, <<~MSG
10
+ You have promotions with a match policy of any and more than one rule. Please
11
+ run `bundle exec rake solidus:split_promotions_with_any_match_policy`.
12
+ MSG
13
+ end
14
+ end
15
+ end
16
+
17
+ def down
18
+ # No-Op
19
+ end
20
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solidus
4
+ class InstallGenerator < Rails::Generators::Base
5
+ # Bundler context during the install process.
6
+ #
7
+ # This class gives access to information about the bundler context in which
8
+ # the install generator is run. I.e., which solidus components are present
9
+ # in the user's Gemfile. It also allows modifying the Gemfile to add or
10
+ # remove gems.
11
+ #
12
+ # @api private
13
+ class BundlerContext
14
+ # Write and remove into and from a Gemfile
15
+ #
16
+ # This custom injector fixes support for path, git and custom sources,
17
+ # which is missing in bundler's upstream injector for a dependency fetched
18
+ # with `Bundled.locked_gems.dependencies`.
19
+ #
20
+ # @api private
21
+ class InjectorWithPathSupport < Bundler::Injector
22
+ private def build_gem_lines(conservative_versioning)
23
+ @deps.map do |d|
24
+ name = d.name.dump
25
+ is_local = d.source.instance_of?(Bundler::Source::Path)
26
+ is_git = d.source.instance_of?(Bundler::Source::Git)
27
+
28
+ requirement = if is_local
29
+ ", path: \"#{d.source.path}\""
30
+ elsif is_git
31
+ ", git: \"#{d.git}\"".yield_self { |g| d.ref ? g + ", ref: \"#{d.ref}\"" : g }
32
+ elsif conservative_versioning
33
+ ", \"#{conservative_version(@definition.specs[d.name][0])}\""
34
+ else
35
+ ", #{d.requirement.as_list.map(&:dump).join(", ")}"
36
+ end
37
+
38
+ source = ", :source => \"#{d.source.remotes.join(",")}\"" unless is_local || is_git || d.source.nil?
39
+
40
+ %(gem #{name}#{requirement}#{source})
41
+ end.join("\n")
42
+ end
43
+ end
44
+
45
+ attr_reader :dependencies, :injector
46
+
47
+ def self.bundle_cleanly(&block)
48
+ Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
49
+ end
50
+
51
+ def initialize
52
+ @dependencies = Bundler.locked_gems.dependencies
53
+ @injector = InjectorWithPathSupport
54
+ end
55
+
56
+ def solidus_in_gemfile?
57
+ !solidus_dependency.nil?
58
+ end
59
+
60
+ def component_in_gemfile?(name)
61
+ !@dependencies["solidus_#{name}"].nil?
62
+ end
63
+
64
+ def break_down_components(components)
65
+ raise <<~MSG unless solidus_in_gemfile?
66
+ solidus meta gem needs to be present in the Gemfile to build the component dependency
67
+ MSG
68
+
69
+ @injector.inject(
70
+ components.map { |component| dependency_for_component(component) }
71
+ )
72
+ end
73
+
74
+ def remove(*args, **kwargs, &block)
75
+ @injector.remove(*args, **kwargs, &block)
76
+ end
77
+
78
+ private
79
+
80
+ def dependency_for_component(component)
81
+ Bundler::Dependency.new(
82
+ "solidus_#{component}",
83
+ solidus_dependency.requirement,
84
+ {
85
+ "source" => solidus_dependency.source,
86
+ "git" => solidus_dependency.source.try(:uri),
87
+ "ref" => solidus_dependency.source.try(:ref)
88
+ }
89
+ )
90
+ end
91
+
92
+ def solidus_dependency
93
+ @dependencies['solidus']
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solidus
4
+ class InstallGenerator < Rails::Generators::Base
5
+ class InstallFrontend
6
+ attr_reader :bundler_context,
7
+ :generator_context
8
+
9
+ def initialize(bundler_context:, generator_context:)
10
+ @bundler_context = bundler_context
11
+ @generator_context = generator_context
12
+ end
13
+
14
+ def call(frontend, installer_adds_auth:)
15
+ case frontend
16
+ when 'solidus_frontend'
17
+ install_solidus_frontend
18
+ when 'solidus_starter_frontend'
19
+ install_solidus_starter_frontend(installer_adds_auth)
20
+ end
21
+ end
22
+
23
+ private
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
32
+
33
+ @generator_context.generate('solidus_frontend:install')
34
+ end
35
+
36
+ def install_solidus_starter_frontend(installer_adds_auth)
37
+ @bundler_context.remove(['solidus_frontend']) if @bundler_context.component_in_gemfile?(:frontend)
38
+
39
+ # TODO: Move installation of solidus_auth_devise to the
40
+ # solidus_starter_frontend template
41
+ BundlerContext.bundle_cleanly { `bundle add solidus_auth_devise` } unless auth_present?(installer_adds_auth)
42
+ `LOCATION="https://raw.githubusercontent.com/solidusio/solidus_starter_frontend/main/template.rb" bin/rails app:template`
43
+ end
44
+
45
+ def auth_present?(installer_adds_auth)
46
+ installer_adds_auth || @bundler_context.component_in_gemfile?(:auth_devise)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solidus
4
+ class InstallGenerator < Rails::Generators::Base
5
+ # Helper for extracting solidus_frontend from solidus meta-gem
6
+ #
7
+ # We're recommending users use newer solidus_starter_frontend. However,
8
+ # we're still shipping solidus_frontend as part of the solidus meta-gem. The
9
+ # reason is that we don't want users updating previous versions to see its
10
+ # storefront gone suddenly.
11
+ #
12
+ # In future solidus releases, solidus_frontend won't be a component anymore.
13
+ # However, until that happens:
14
+ #
15
+ # - For users of the new frontend, we need to prevent pulling
16
+ # solidus_frontend.
17
+ # - For users of the legacy frontend, we need to prevent Bundler from
18
+ # resolving it from the mono-repo while it's still there.
19
+ #
20
+ # This class is a needed companion during the deprecation
21
+ # path. It'll modify the user's Gemfile, breaking the solidus gem down into
22
+ # its components but solidus_frontend.
23
+ class SupportSolidusFrontendExtraction
24
+ attr_reader :bundler_context
25
+
26
+ def initialize(bundler_context:)
27
+ @bundler_context = bundler_context
28
+ end
29
+
30
+ def call
31
+ return unless needs_to_break_down_solidus_meta_gem?
32
+
33
+ break_down_solidus_meta_gem
34
+ end
35
+
36
+ private
37
+
38
+ def break_down_solidus_meta_gem
39
+ @bundler_context.break_down_components(%w[core backend api sample])
40
+ @bundler_context.remove(['solidus'])
41
+ end
42
+
43
+ def needs_to_break_down_solidus_meta_gem?
44
+ @bundler_context.solidus_in_gemfile?
45
+ end
46
+ end
47
+ end
48
+ end
@@ -2,16 +2,22 @@
2
2
 
3
3
  require 'rails/generators'
4
4
  require 'rails/version'
5
+ require_relative 'install_generator/bundler_context'
6
+ require_relative 'install_generator/support_solidus_frontend_extraction'
7
+ require_relative 'install_generator/install_frontend'
5
8
 
6
9
  module Solidus
7
10
  # @private
8
11
  class InstallGenerator < Rails::Generators::Base
9
12
  CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"
10
13
 
11
- PAYMENT_METHODS = {
12
- 'paypal' => 'solidus_paypal_commerce_platform',
13
- 'none' => nil,
14
- }
14
+ LEGACY_FRONTEND = 'solidus_frontend'
15
+ DEFAULT_FRONTEND = 'solidus_starter_frontend'
16
+ FRONTENDS = [
17
+ DEFAULT_FRONTEND,
18
+ LEGACY_FRONTEND,
19
+ 'none'
20
+ ].freeze
15
21
 
16
22
  class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
17
23
  class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)'
@@ -24,11 +30,11 @@ module Solidus
24
30
  class_option :lib_name, type: :string, default: 'spree'
25
31
  class_option :with_authentication, type: :boolean, default: true
26
32
  class_option :enforce_available_locales, type: :boolean, default: nil
27
- class_option :payment_method,
33
+ class_option :frontend,
28
34
  type: :string,
29
- enum: PAYMENT_METHODS.keys,
30
- default: PAYMENT_METHODS.keys.first,
31
- desc: "Indicates which payment method to install."
35
+ enum: FRONTENDS,
36
+ default: nil,
37
+ desc: "Indicates which frontend to install."
32
38
 
33
39
  def self.source_paths
34
40
  paths = superclass.source_paths
@@ -84,16 +90,10 @@ module Solidus
84
90
  empty_directory 'app/assets/images'
85
91
 
86
92
  %w{javascripts stylesheets images}.each do |path|
87
- empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test?
88
- empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test?
93
+ empty_directory "vendor/assets/#{path}/spree/backend" if defined?(Spree::Backend) || Rails.env.test?
89
94
  end
90
95
 
91
- if defined? Spree::Frontend || Rails.env.test?
92
- template "vendor/assets/javascripts/spree/frontend/all.js"
93
- template "vendor/assets/stylesheets/spree/frontend/all.css"
94
- end
95
-
96
- if defined? Spree::Backend || Rails.env.test?
96
+ if defined?(Spree::Backend) || Rails.env.test?
97
97
  template "vendor/assets/javascripts/spree/backend/all.js"
98
98
  template "vendor/assets/stylesheets/spree/backend/all.css"
99
99
  end
@@ -104,17 +104,6 @@ module Solidus
104
104
  end
105
105
 
106
106
  def configure_application
107
- application <<-RUBY
108
- # Load application's model / class decorators
109
- initializer 'spree.decorators' do |app|
110
- config.to_prepare do
111
- Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path|
112
- require_dependency(path)
113
- end
114
- end
115
- end
116
- RUBY
117
-
118
107
  if !options[:enforce_available_locales].nil?
119
108
  application <<-RUBY
120
109
  # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e
@@ -133,6 +122,9 @@ module Solidus
133
122
  Solidus has a default authentication extension that uses Devise.
134
123
  You can find more info at https://github.com/solidusio/solidus_auth_devise.
135
124
 
125
+ Regardless of what you answer here, it'll be installed if you choose
126
+ solidus_starter_frontend as your storefront in a later step.
127
+
136
128
  Would you like to install it? (Y/n)"))
137
129
 
138
130
  @plugins_to_be_installed << 'solidus_auth_devise'
@@ -140,25 +132,6 @@ module Solidus
140
132
  end
141
133
  end
142
134
 
143
- def install_payment_method
144
- name = options[:payment_method]
145
-
146
- unless options[:auto_accept]
147
- available_names = PAYMENT_METHODS.keys
148
-
149
- name = ask("
150
- You can select a payment method to be included in the installation process.
151
- Please select a payment method name:", limited_to: available_names, default: available_names.first)
152
- end
153
-
154
- gem_name = PAYMENT_METHODS.fetch(name)
155
-
156
- if gem_name
157
- @plugins_to_be_installed << gem_name
158
- @plugin_generators_to_run << "#{gem_name}:install"
159
- end
160
- end
161
-
162
135
  def include_seed_data
163
136
  append_file "db/seeds.rb", <<-RUBY.strip_heredoc
164
137
 
@@ -182,7 +155,7 @@ module Solidus
182
155
  gem plugin_name
183
156
  end
184
157
 
185
- bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
158
+ BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
186
159
  run "spring stop" if defined?(Spring)
187
160
 
188
161
  @plugin_generators_to_run.each do |plugin_generator_name|
@@ -190,6 +163,22 @@ module Solidus
190
163
  end
191
164
  end
192
165
 
166
+ def install_frontend
167
+ return if options[:frontend] == 'none'
168
+
169
+ bundler_context = BundlerContext.new
170
+
171
+ frontend = detect_frontend_to_install(bundler_context)
172
+
173
+ support_solidus_frontend_extraction(bundler_context) unless frontend == LEGACY_FRONTEND
174
+
175
+ say_status :installing, frontend
176
+
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'))
180
+ end
181
+
193
182
  def run_migrations
194
183
  if @run_migrations
195
184
  say_status :running, "migrations"
@@ -258,8 +247,26 @@ module Solidus
258
247
 
259
248
  private
260
249
 
261
- def bundle_cleanly(&block)
262
- Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
250
+ def detect_frontend_to_install(bundler_context)
251
+ ENV['FRONTEND'] ||
252
+ options[:frontend] ||
253
+ (bundler_context.component_in_gemfile?(:frontend) && LEGACY_FRONTEND) ||
254
+ (options[:auto_accept] && DEFAULT_FRONTEND) ||
255
+ ask(<<~MSG.indent(8), limited_to: FRONTENDS, default: DEFAULT_FRONTEND)
256
+
257
+ Which frontend would you like to use? solidus_starter_frontend is
258
+ recommended. However, some extensions are still only compatible with
259
+ the now deprecated solidus_frontend.
260
+
261
+ MSG
262
+ end
263
+
264
+ def support_solidus_frontend_extraction(bundler_context)
265
+ say_status "break down", "solidus"
266
+
267
+ SupportSolidusFrontendExtraction.
268
+ new(bundler_context: bundler_context).
269
+ call
263
270
  end
264
271
  end
265
272
  end