solidus_core 3.1.9 → 3.2.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) 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/default_price.rb +28 -4
  6. data/app/models/concerns/spree/user_address_book.rb +11 -1
  7. data/app/models/spree/adjustment.rb +1 -0
  8. data/app/models/spree/carton.rb +1 -1
  9. data/app/models/spree/option_value.rb +9 -0
  10. data/app/models/spree/order.rb +68 -29
  11. data/app/models/spree/order_contents.rb +2 -1
  12. data/app/models/spree/order_inventory.rb +1 -1
  13. data/app/models/spree/order_merger.rb +2 -2
  14. data/app/models/spree/order_taxation.rb +6 -4
  15. data/app/models/spree/order_updater.rb +4 -3
  16. data/app/models/spree/payment_method.rb +11 -0
  17. data/app/models/spree/price.rb +1 -1
  18. data/app/models/spree/product/scopes.rb +21 -3
  19. data/app/models/spree/product.rb +1 -1
  20. data/app/models/spree/promotion/actions/create_adjustment.rb +4 -0
  21. data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -6
  22. data/app/models/spree/promotion/rules/product.rb +20 -8
  23. data/app/models/spree/promotion/rules/store.rb +4 -0
  24. data/app/models/spree/promotion/rules/taxon.rb +4 -0
  25. data/app/models/spree/promotion/rules/user.rb +4 -0
  26. data/app/models/spree/promotion.rb +34 -23
  27. data/app/models/spree/promotion_action.rb +4 -0
  28. data/app/models/spree/promotion_code.rb +8 -4
  29. data/app/models/spree/promotion_handler/cart.rb +26 -6
  30. data/app/models/spree/promotion_rule.rb +5 -0
  31. data/app/models/spree/reimbursement.rb +2 -2
  32. data/app/models/spree/return_item.rb +1 -2
  33. data/app/models/spree/stock/allocator/on_hand_first.rb +2 -2
  34. data/app/models/spree/stock/quantifier.rb +12 -8
  35. data/app/models/spree/stock/simple_coordinator.rb +2 -1
  36. data/app/models/spree/tax/item_tax.rb +3 -2
  37. data/app/models/spree/tax/order_tax.rb +3 -1
  38. data/app/models/spree/tax/tax_location.rb +4 -7
  39. data/app/models/spree/tax_rate.rb +2 -0
  40. data/app/models/spree/variant/price_selector.rb +1 -18
  41. data/app/models/spree/variant.rb +2 -2
  42. data/app/subscribers/spree/mailer_subscriber.rb +4 -0
  43. data/app/subscribers/spree/order_mailer_subscriber.rb +35 -0
  44. data/config/locales/en.yml +7 -253
  45. data/db/migrate/20201127212108_add_type_before_removal_to_spree_payment_methods.rb +7 -0
  46. data/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +20 -0
  47. data/lib/generators/solidus/install/install_generator/bundler_context.rb +97 -0
  48. data/lib/generators/solidus/install/install_generator/install_frontend.rb +50 -0
  49. data/lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb +48 -0
  50. data/lib/generators/solidus/install/install_generator.rb +56 -49
  51. data/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt +6 -16
  52. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js +2 -2
  53. data/lib/spree/app_configuration.rb +29 -3
  54. data/lib/spree/bus.rb +20 -0
  55. data/lib/spree/core/controller_helpers/auth.rb +9 -1
  56. data/lib/spree/core/controller_helpers/current_host.rb +1 -3
  57. data/lib/spree/core/controller_helpers/order.rb +10 -10
  58. data/lib/spree/core/controller_helpers/search.rb +1 -1
  59. data/lib/spree/core/engine.rb +33 -8
  60. data/lib/spree/core/state_machines/order.rb +1 -1
  61. data/lib/spree/core/stock_configuration.rb +18 -0
  62. data/lib/spree/core/validators/email.rb +3 -1
  63. data/lib/spree/core/version.rb +1 -1
  64. data/lib/spree/core.rb +20 -0
  65. data/lib/spree/event/subscriber_registry.rb +4 -6
  66. data/lib/spree/event.rb +1 -1
  67. data/lib/spree/migrations.rb +1 -1
  68. data/lib/spree/permission_sets/default_customer.rb +8 -1
  69. data/lib/spree/permitted_attributes.rb +4 -4
  70. data/lib/spree/preferences/configuration.rb +34 -12
  71. data/lib/spree/preferences/preferable.rb +0 -5
  72. data/lib/spree/preferences/preferable_class_methods.rb +3 -3
  73. data/lib/spree/preferences/preference_differentiator.rb +2 -1
  74. data/lib/spree/preferences/static_model_preferences.rb +0 -2
  75. data/lib/spree/rails_compatibility.rb +99 -0
  76. data/lib/spree/testing_support/bus_helpers.rb +101 -0
  77. data/lib/spree/testing_support/common_rake.rb +47 -19
  78. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
  79. data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
  80. data/lib/spree/testing_support/dummy_app.rb +6 -2
  81. data/lib/spree/testing_support/factories/address_factory.rb +7 -2
  82. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
  83. data/lib/spree/testing_support/factories/order_factory.rb +8 -4
  84. data/lib/spree/testing_support/factories/product_factory.rb +4 -1
  85. data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -4
  86. data/lib/spree/testing_support/factory_bot.rb +1 -1
  87. data/lib/spree/testing_support/order_walkthrough.rb +5 -4
  88. data/lib/spree/testing_support/silence_deprecations.rb +9 -0
  89. data/lib/tasks/payment_method.rake +29 -0
  90. data/lib/tasks/solidus/delete_prices_with_nil_amount.rake +2 -2
  91. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +33 -0
  92. data/solidus_core.gemspec +6 -2
  93. metadata +71 -26
  94. data/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js +0 -10
  95. 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
@@ -762,10 +762,6 @@ en:
762
762
  not_saved:
763
763
  one: '1 error prohibited this %{resource} from being saved:'
764
764
  other: "%{count} errors prohibited this %{resource} from being saved:"
765
- number:
766
- percentage:
767
- format:
768
- precision: 1
769
765
  spree:
770
766
  abbreviation: Abbreviation
771
767
  accept: Accept
@@ -870,6 +866,10 @@ en:
870
866
  new_price: New Price
871
867
  new:
872
868
  new_price: New Price
869
+ master_variant_table:
870
+ master_variant: Master Variant Prices
871
+ table:
872
+ variant_pricing: Variant Prices
873
873
  promotions:
874
874
  actions:
875
875
  calculator_label: Calculated by
@@ -1002,9 +1002,11 @@ en:
1002
1002
  edit_variant: Edit Variant
1003
1003
  form:
1004
1004
  dimensions: Dimensions
1005
+ options: Options
1005
1006
  pricing: Pricing
1006
1007
  pricing_hint: These values are populated from the product details page and
1007
1008
  can be overridden below
1009
+ properties: Properties
1008
1010
  use_product_tax_category: Use Product Tax Category
1009
1011
  new:
1010
1012
  new_variant: New Variant
@@ -1176,257 +1178,10 @@ en:
1176
1178
  country_based: Country Based
1177
1179
  country_name: Name
1178
1180
  country_names:
1179
- AD: Andorra
1180
- AE: United Arab Emirates
1181
- AF: Afghanistan
1182
- AG: Antigua and Barbuda
1183
- AI: Anguilla
1184
- AL: Albania
1185
- AM: Armenia
1186
- AO: Angola
1187
- AQ: Antarctica
1188
- AR: Argentina
1189
- AS: American Samoa
1190
- AT: Austria
1191
- AU: Australia
1192
- AW: Aruba
1193
- AX: Åland Islands
1194
- AZ: Azerbaijan
1195
- BA: Bosnia and Herzegovina
1196
- BB: Barbados
1197
- BD: Bangladesh
1198
- BE: Belgium
1199
- BF: Burkina Faso
1200
- BG: Bulgaria
1201
- BH: Bahrain
1202
- BI: Burundi
1203
- BJ: Benin
1204
- BL: Saint Barthélemy
1205
- BM: Bermuda
1206
- BN: Brunei Darussalam
1207
- BO: Bolivia, Plurinational State of
1208
- BQ: Bonaire, Sint Eustatius and Saba
1209
- BR: Brazil
1210
- BS: Bahamas
1211
- BT: Bhutan
1212
- BV: Bouvet Island
1213
- BW: Botswana
1214
- BY: Belarus
1215
- BZ: Belize
1216
1181
  CA: Canada
1217
- CC: Cocos (Keeling) Islands
1218
- CD: Congo, The Democratic Republic of the
1219
- CF: Central African Republic
1220
- CG: Congo
1221
- CH: Switzerland
1222
- CI: Côte d'Ivoire
1223
- CK: Cook Islands
1224
- CL: Chile
1225
- CM: Cameroon
1226
- CN: China
1227
- CO: Colombia
1228
- CR: Costa Rica
1229
- CU: Cuba
1230
- CV: Cabo Verde
1231
- CW: Curaçao
1232
- CX: Christmas Island
1233
- CY: Cyprus
1234
- CZ: Czechia
1235
- DE: Germany
1236
- DJ: Djibouti
1237
- DK: Denmark
1238
- DM: Dominica
1239
- DO: Dominican Republic
1240
- DZ: Algeria
1241
- EC: Ecuador
1242
- EE: Estonia
1243
- EG: Egypt
1244
- EH: Western Sahara
1245
- ER: Eritrea
1246
- ES: Spain
1247
- ET: Ethiopia
1248
- FI: Finland
1249
- FJ: Fiji
1250
- FK: Falkland Islands (Malvinas)
1251
- FM: Micronesia, Federated States of
1252
- FO: Faroe Islands
1253
- FR: France
1254
1182
  FRA: France
1255
- GA: Gabon
1256
- GB: United Kingdom
1257
- GD: Grenada
1258
- GE: Georgia
1259
- GF: French Guiana
1260
- GG: Guernsey
1261
- GH: Ghana
1262
- GI: Gibraltar
1263
- GL: Greenland
1264
- GM: Gambia
1265
- GN: Guinea
1266
- GP: Guadeloupe
1267
- GQ: Equatorial Guinea
1268
- GR: Greece
1269
- GS: South Georgia and the South Sandwich Islands
1270
- GT: Guatemala
1271
- GU: Guam
1272
- GW: Guinea-Bissau
1273
- GY: Guyana
1274
- HK: Hong Kong
1275
- HM: Heard Island and McDonald Islands
1276
- HN: Honduras
1277
- HR: Croatia
1278
- HT: Haiti
1279
- HU: Hungary
1280
- ID: Indonesia
1281
- IE: Ireland
1282
- IL: Israel
1283
- IM: Isle of Man
1284
- IN: India
1285
- IO: British Indian Ocean Territory
1286
- IQ: Iraq
1287
- IR: Iran, Islamic Republic of
1288
- IS: Iceland
1289
- IT: Italy
1290
1183
  ITA: Italy
1291
- JE: Jersey
1292
- JM: Jamaica
1293
- JO: Jordan
1294
- JP: Japan
1295
- KE: Kenya
1296
- KG: Kyrgyzstan
1297
- KH: Cambodia
1298
- KI: Kiribati
1299
- KM: Comoros
1300
- KN: Saint Kitts and Nevis
1301
- KP: Korea, Democratic People's Republic of
1302
- KR: Korea, Republic of
1303
- KW: Kuwait
1304
- KY: Cayman Islands
1305
- KZ: Kazakhstan
1306
- LA: Lao People's Democratic Republic
1307
- LB: Lebanon
1308
- LC: Saint Lucia
1309
- LI: Liechtenstein
1310
- LK: Sri Lanka
1311
- LR: Liberia
1312
- LS: Lesotho
1313
- LT: Lithuania
1314
- LU: Luxembourg
1315
- LV: Latvia
1316
- LY: Libya
1317
- MA: Morocco
1318
- MC: Monaco
1319
- MD: Moldova, Republic of
1320
- ME: Montenegro
1321
- MF: Saint Martin (French part)
1322
- MG: Madagascar
1323
- MH: Marshall Islands
1324
- MK: North Macedonia
1325
- ML: Mali
1326
- MM: Myanmar
1327
- MN: Mongolia
1328
- MO: Macao
1329
- MP: Northern Mariana Islands
1330
- MQ: Martinique
1331
- MR: Mauritania
1332
- MS: Montserrat
1333
- MT: Malta
1334
- MU: Mauritius
1335
- MV: Maldives
1336
- MW: Malawi
1337
- MX: Mexico
1338
- MY: Malaysia
1339
- MZ: Mozambique
1340
- NA: Namibia
1341
- NC: New Caledonia
1342
- NE: Niger
1343
- NF: Norfolk Island
1344
- NG: Nigeria
1345
- NI: Nicaragua
1346
- NL: Netherlands
1347
- 'NO': Norway
1348
- NP: Nepal
1349
- NR: Nauru
1350
- NU: Niue
1351
- NZ: New Zealand
1352
- OM: Oman
1353
- PA: Panama
1354
- PE: Peru
1355
- PF: French Polynesia
1356
- PG: Papua New Guinea
1357
- PH: Philippines
1358
- PK: Pakistan
1359
- PL: Poland
1360
- PM: Saint Pierre and Miquelon
1361
- PN: Pitcairn
1362
- PR: Puerto Rico
1363
- PS: Palestine, State of
1364
- PT: Portugal
1365
- PW: Palau
1366
- PY: Paraguay
1367
- QA: Qatar
1368
- RE: Réunion
1369
- RO: Romania
1370
- RS: Serbia
1371
- RU: Russia
1372
- RW: Rwanda
1373
- SA: Saudi Arabia
1374
- SB: Solomon Islands
1375
- SC: Seychelles
1376
- SD: Sudan
1377
- SE: Sweden
1378
- SG: Singapore
1379
- SH: Saint Helena, Ascension and Tristan da Cunha
1380
- SI: Slovenia
1381
- SJ: Svalbard and Jan Mayen
1382
- SK: Slovakia
1383
- SL: Sierra Leone
1384
- SM: San Marino
1385
- SN: Senegal
1386
- SO: Somalia
1387
- SR: Suriname
1388
- SS: South Sudan
1389
- ST: Sao Tome and Principe
1390
- SV: El Salvador
1391
- SX: Sint Maarten (Dutch part)
1392
- SY: Syrian Arab Republic
1393
- SZ: Eswatini
1394
- TC: Turks and Caicos Islands
1395
- TD: Chad
1396
- TF: French Southern Territories
1397
- TG: Togo
1398
- TH: Thailand
1399
- TJ: Tajikistan
1400
- TK: Tokelau
1401
- TL: Timor-Leste
1402
- TM: Turkmenistan
1403
- TN: Tunisia
1404
- TO: Tonga
1405
- TR: Turkey
1406
- TT: Trinidad and Tobago
1407
- TV: Tuvalu
1408
- TW: Taiwan
1409
- TZ: Tanzania, United Republic of
1410
- UA: Ukraine
1411
- UG: Uganda
1412
- UM: United States Minor Outlying Islands
1413
1184
  US: United States of America
1414
- UY: Uruguay
1415
- UZ: Uzbekistan
1416
- VA: Holy See (Vatican City State)
1417
- VC: Saint Vincent and the Grenadines
1418
- VE: Venezuela, Bolivarian Republic of
1419
- VG: Virgin Islands, British
1420
- VI: Virgin Islands, U.S.
1421
- VN: Vietnam
1422
- VU: Vanuatu
1423
- WF: Wallis and Futuna
1424
- WS: Samoa
1425
- YE: Yemen
1426
- YT: Mayotte
1427
- ZA: South Africa
1428
- ZM: Zambia
1429
- ZW: Zimbabwe
1430
1185
  coupon: Coupon
1431
1186
  coupon_code: Coupon code
1432
1187
  coupon_code_already_applied: The coupon code has already been applied to this
@@ -2501,7 +2256,6 @@ en:
2501
2256
  value: Value
2502
2257
  variant: Variant
2503
2258
  variant_placeholder: Choose a Variant
2504
- variant_pricing: Variant Pricing
2505
2259
  variant_properties: Variant Properties
2506
2260
  variant_search: Variant Search
2507
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