spree_frontend 4.3.0 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +192 -0
  3. data/.codeclimate.yml +36 -0
  4. data/.deepsource.toml +19 -0
  5. data/.editorconfig +22 -0
  6. data/.eslintignore +7 -0
  7. data/.eslintrc +36 -0
  8. data/.gem_release.yml +7 -0
  9. data/.github/CONTRIBUTING.md +1 -0
  10. data/.github/ISSUE_TEMPLATE/bug_report.md +47 -0
  11. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  12. data/.github/ISSUE_TEMPLATE.md +39 -0
  13. data/.github/dependabot.yml +32 -0
  14. data/.gitignore +58 -0
  15. data/.rubocop.yml +197 -0
  16. data/.solargraph.yml +20 -0
  17. data/.stylelintignore +4 -0
  18. data/.stylelintrc +6 -0
  19. data/CODE_OF_CONDUCT.md +22 -0
  20. data/Gemfile +58 -3
  21. data/LICENSE +1 -1
  22. data/README.md +88 -0
  23. data/SECURITY.md +1 -0
  24. data/app/assets/config/spree_frontend_manifest.js +1 -0
  25. data/app/assets/javascripts/spree/{api → frontend/api}/main.js +4 -4
  26. data/app/assets/javascripts/spree/{api → frontend/api}/storefront/cart.js +1 -1
  27. data/app/assets/javascripts/spree/frontend/checkout/address.js +3 -3
  28. data/app/assets/javascripts/spree/frontend/currency.js +6 -7
  29. data/app/assets/javascripts/spree/frontend/locale.es6 +1 -2
  30. data/app/assets/javascripts/{spree.js → spree/frontend/main.js} +5 -5
  31. data/app/assets/javascripts/spree/frontend/{turbolinks_scroll_fix.js → turbo_scroll_fix.js} +3 -3
  32. data/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js +1 -1
  33. data/app/assets/javascripts/spree/frontend/views/spree/product/related.js +1 -1
  34. data/app/assets/javascripts/spree/frontend/views/spree/products/cart_form.js +8 -8
  35. data/app/assets/javascripts/spree/frontend/views/spree/products/description.js +1 -1
  36. data/app/assets/javascripts/spree/frontend/views/spree/products/index.js +1 -1
  37. data/app/assets/javascripts/spree/frontend/views/spree/shared/mobile_navigation.js +4 -4
  38. data/app/assets/javascripts/spree/frontend/views/spree/shared/variant_select.js +3 -3
  39. data/app/assets/javascripts/spree/frontend.js +10 -17
  40. data/app/controllers/spree/addresses_controller.rb +4 -4
  41. data/app/controllers/spree/checkout_controller.rb +2 -2
  42. data/app/controllers/spree/locale_controller.rb +3 -2
  43. data/app/controllers/spree/orders_controller.rb +1 -1
  44. data/app/controllers/spree/store_controller.rb +42 -1
  45. data/app/helpers/spree/frontend_helper.rb +32 -8
  46. data/app/helpers/spree/navigation_helper.rb +2 -2
  47. data/app/helpers/spree/products_filters_helper.rb +1 -1
  48. data/app/helpers/spree/store_helper.rb +1 -1
  49. data/app/services/spree/build_localized_redirect_url.rb +101 -0
  50. data/app/views/spree/checkout/_delivery.html.erb +1 -1
  51. data/app/views/spree/checkout/edit.html.erb +1 -1
  52. data/app/views/spree/checkout/registration.html.erb +1 -1
  53. data/app/views/spree/orders/_line_item.html.erb +1 -1
  54. data/app/views/spree/orders/_line_item_data.html.erb +1 -1
  55. data/app/views/spree/products/_color_option_type.html.erb +2 -2
  56. data/app/views/spree/products/_description.html.erb +1 -1
  57. data/app/views/spree/products/_filters_desktop.html.erb +3 -3
  58. data/app/views/spree/products/_filters_mobile.html.erb +2 -2
  59. data/app/views/spree/products/_thumbnails.html.erb +2 -2
  60. data/app/views/spree/shared/_head.html.erb +3 -2
  61. data/app/views/spree/shared/_line_item.html.erb +1 -1
  62. data/app/views/spree/shared/_link_to_account.html.erb +3 -1
  63. data/app/views/spree/shared/_login.html.erb +1 -1
  64. data/app/views/spree/shared/_main_nav_bar.html.erb +1 -1
  65. data/app/views/spree/shared/_nav_bar.html.erb +1 -1
  66. data/app/views/spree/shared/_order_details.html.erb +1 -1
  67. data/app/views/spree/shared/_paths.html.erb +1 -1
  68. data/app/views/spree/shared/_translations.html.erb +1 -1
  69. data/app/views/spree/shared/carousel/_single.html.erb +2 -2
  70. data/app/views/spree/shared/carousel/_thumbnails.html.erb +1 -1
  71. data/app/views/spree/shared/cms/sections/_hero_image.html.erb +9 -9
  72. data/app/views/spree/shared/cms/sections/_image_gallery.html.erb +21 -21
  73. data/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb +14 -14
  74. data/app/views/spree/taxons/_header.html.erb +1 -1
  75. data/app/views/spree/users/_address_controls.html.erb +1 -1
  76. data/config/routes.rb +4 -4
  77. data/lib/generators/spree/frontend/install/install_generator.rb +1 -1
  78. data/lib/spree/frontend/configuration.rb +18 -0
  79. data/lib/spree/frontend/engine.rb +3 -7
  80. data/lib/spree/frontend/version.rb +9 -0
  81. data/lib/spree/frontend.rb +2 -1
  82. data/license.md +13 -0
  83. data/spree_frontend.gemspec +5 -4
  84. metadata +58 -22
  85. data/app/models/spree/frontend_configuration.rb +0 -10
  86. data/app/views/spree/shared/_taxonomies.html.erb +0 -16
@@ -21,7 +21,7 @@ Spree.ready(function($) {
21
21
  this.closeAllCategories = this.closeAllCategories.bind(this);
22
22
 
23
23
  window.addEventListener('resize', this.onResize);
24
- window.addEventListener('turbolinks:request-start', this.onCloseClick);
24
+ window.addEventListener('turbo:request-start', this.onCloseClick);
25
25
 
26
26
  this.burgerButton.addEventListener('click', this.onBurgerClick, false);
27
27
  this.closeButton.addEventListener('click', this.onCloseClick, false);
@@ -77,7 +77,7 @@ Spree.ready(function($) {
77
77
 
78
78
  MobileNavigationManager.prototype.openCategory = function(category) {
79
79
  this.openedCategories.push(category);
80
- var subList = document.querySelector('ul[data-category=' + category + ']');
80
+ var subList = document.querySelector('ul[data-category="' + category + '"]');
81
81
  if (subList) {
82
82
  this.mobileNavigationList.classList.add('mobile-navigation-list-subcategory-shown');
83
83
  this.mobileNavigationList.scrollTop = 0
@@ -89,7 +89,7 @@ Spree.ready(function($) {
89
89
 
90
90
  MobileNavigationManager.prototype.closeCurrentCategory = function() {
91
91
  var category = this.openedCategories.pop();
92
- var subList = document.querySelector('ul[data-category=' + category + ']');
92
+ var subList = document.querySelector('ul[data-category="' + category + '"]');
93
93
  if (subList) {
94
94
  subList.classList.remove('shown');
95
95
  }
@@ -101,7 +101,7 @@ Spree.ready(function($) {
101
101
  }
102
102
 
103
103
  MobileNavigationManager.prototype.closeCategory = function(category) {
104
- var subList = document.querySelector('ul[data-category=' + category + ']');
104
+ var subList = document.querySelector('ul[data-category="' + category + '"]');
105
105
  subList.style.transition = 'none';
106
106
  subList.classList.remove('shown');
107
107
  setTimeout(function(){ subList.style.transition = ''; }, 500);
@@ -8,7 +8,7 @@ this.initializeQueryParamsCheck = function () {
8
8
 
9
9
  function verifyVariantIdMatch() {
10
10
  this.variants.forEach(function(variant) {
11
- if (parseInt(variant.id) === parseInt(variantIdFromUrl)) this.urlQueryMatchFound = true
11
+ if (variant.id.toString() === variantIdFromUrl.toString()) this.urlQueryMatchFound = true
12
12
  })
13
13
  }
14
14
 
@@ -23,7 +23,7 @@ this.setSelectedVariantFromUrl = function () {
23
23
 
24
24
  this.getVariantOptionsById = function(variantIdFromUrl) {
25
25
  this.variants.forEach(function(variant) {
26
- if (parseInt(variant.id) === parseInt(variantIdFromUrl)) this.sortOptionValues(variant.option_values)
26
+ if (variant.id.toString() === variantIdFromUrl.toString()) this.sortOptionValues(variant.option_values)
27
27
  })
28
28
  }
29
29
 
@@ -36,7 +36,7 @@ function buildArray(item) {
36
36
  var target = container.querySelectorAll('.product-variants-variant-values-radio')
37
37
 
38
38
  target.forEach(function(inputTag) {
39
- if (parseInt(inputTag.value) === item.id && inputTag.dataset.presentation === item.presentation) {
39
+ if (inputTag.value.toString() === item.id.toString() && inputTag.dataset.presentation === item.presentation) {
40
40
  this.selectedOptions.push(inputTag)
41
41
  }
42
42
  })
@@ -4,14 +4,13 @@
4
4
  //= require bootstrap
5
5
  //= require jquery.payment
6
6
  //= require cleave
7
- //= require spree
7
+ //= require spree/frontend/main
8
8
  //= require polyfill.min
9
9
  //= require fetch.umd
10
- //= require spree/api/main
10
+ //= require spree/frontend/api/main
11
11
  //= require ./lazysizes.config
12
12
  //= require lazysizes.min
13
13
  //= require accounting.min
14
- //= require turbolinks
15
14
  //= require spree/frontend/account
16
15
  //= require spree/frontend/api_tokens
17
16
  //= require spree/frontend/carousel-noconflict
@@ -40,31 +39,25 @@
40
39
  //= require spree/frontend/views/spree/shared/nav_bar
41
40
  //= require spree/frontend/views/spree/shared/product_added_modal
42
41
  //= require spree/frontend/views/spree/shared/quantity_select
43
- //= require spree/frontend/turbolinks_scroll_fix
42
+ //= require spree/frontend/turbo_scroll_fix
44
43
  //= require spree/frontend/main_nav_bar
45
44
  //= require spree/frontend/login
46
45
 
47
- Spree.routes.api_tokens = Spree.pathFor('api_tokens')
48
- Spree.routes.ensure_cart = Spree.pathFor('ensure_cart')
46
+ Spree.routes.api_tokens = Spree.localizedPathFor('api_tokens')
47
+ Spree.routes.ensure_cart = Spree.localizedPathFor('ensure_cart')
49
48
  Spree.routes.api_v2_storefront_cart_apply_coupon_code = Spree.localizedPathFor('api/v2/storefront/cart/apply_coupon_code')
50
49
  Spree.routes.api_v2_storefront_cart_remove_coupon_code = function(couponCode) { return Spree.localizedPathFor('api/v2/storefront/cart/remove_coupon_code/' + couponCode) }
51
50
  Spree.routes.api_v2_storefront_destroy_credit_card = function(id) { return Spree.localizedPathFor('api/v2/storefront/account/credit_cards/' + id) }
52
51
  Spree.routes.product = function(id) { return Spree.localizedPathFor('products/' + id) }
53
52
  Spree.routes.product_related = function(id) { return Spree.localizedPathFor('products/' + id + '/related') }
54
53
  Spree.routes.product_carousel = function (taxonId) { return Spree.localizedPathFor('product_carousel/' + taxonId) }
55
- Spree.routes.set_locale = function(locale) { return Spree.pathFor('locale/set?switch_to_locale=' + locale) }
56
- Spree.routes.set_currency = function(currency) { return Spree.pathFor('currency/set?switch_to_currency=' + currency) }
57
-
58
- Spree.showProgressBar = function () {
59
- if (!Turbolinks.supported) { return }
60
- Turbolinks.controller.adapter.progressBar.setValue(0)
61
- Turbolinks.controller.adapter.progressBar.show()
62
- }
54
+ Spree.routes.set_locale = function(locale) { return Spree.localizedPathFor('locale/set?switch_to_locale=' + locale) }
55
+ Spree.routes.set_currency = function(currency) { return Spree.localizedPathFor('currency/set?switch_to_currency=' + currency) }
63
56
 
64
57
  Spree.clearCache = function () {
65
- if (!Turbolinks.supported) { return }
58
+ if (!window.Turbo) { return }
66
59
 
67
- Turbolinks.clearCache()
60
+ Turbo.clearCache()
68
61
  }
69
62
 
70
63
  Spree.setCurrency = function (currency) {
@@ -81,5 +74,5 @@ Spree.setCurrency = function (currency) {
81
74
 
82
75
  SPREE_CURRENCY = currency
83
76
 
84
- Turbolinks.visit(window.location.pathname + queryString, { action: 'replace' })
77
+ Turbo.visit(window.location.pathname + queryString, { action: 'replace' })
85
78
  }
@@ -10,7 +10,7 @@ module Spree
10
10
  flash[:notice] = I18n.t(:successfully_created, scope: :address_book)
11
11
  redirect_to spree.account_path
12
12
  else
13
- render action: 'new'
13
+ render action: 'new', status: :unprocessable_entity
14
14
  end
15
15
  end
16
16
 
@@ -27,7 +27,7 @@ module Spree
27
27
  flash[:notice] = Spree.t(:successfully_updated, scope: :address_book)
28
28
  redirect_back_or_default(addresses_path)
29
29
  else
30
- render :edit
30
+ render :edit, status: :unprocessable_entity
31
31
  end
32
32
  end
33
33
 
@@ -45,11 +45,11 @@ module Spree
45
45
  end
46
46
 
47
47
  def create_service
48
- Spree::Dependencies.account_create_address_service.constantize
48
+ Spree::Dependencies.address_create_service.constantize
49
49
  end
50
50
 
51
51
  def update_service
52
- Spree::Dependencies.account_update_address_service.constantize
52
+ Spree::Dependencies.address_update_service.constantize
53
53
  end
54
54
  end
55
55
  end
@@ -46,7 +46,7 @@ module Spree
46
46
  redirect_to spree.checkout_state_path(@order.state)
47
47
  end
48
48
  else
49
- render :edit
49
+ render :edit, status: :unprocessable_entity
50
50
  end
51
51
  end
52
52
 
@@ -190,7 +190,7 @@ module Spree
190
190
  def rescue_from_spree_gateway_error(exception)
191
191
  flash.now[:error] = Spree.t(:spree_gateway_error_flash_for_checkout)
192
192
  @order.errors.add(:base, exception.message)
193
- render :edit
193
+ render :edit, status: :unprocessable_entity
194
194
  end
195
195
 
196
196
  def check_authorization
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  class LocaleController < Spree::StoreController
3
- REDIRECT_TO_ROOT = /\/(#{Spree::Config[:storefront_pages_path]})\//.freeze
3
+ REDIRECT_TO_ROOT = /\/(pages)\//.freeze
4
4
 
5
5
  def index
6
6
  render :index, layout: false
@@ -27,10 +27,11 @@ module Spree
27
27
  private
28
28
 
29
29
  def should_build_new_url?
30
+ return false if request.env['HTTP_REFERER'].blank?
30
31
  if request.env['HTTP_REFERER'].match(REDIRECT_TO_ROOT)
31
32
  false
32
33
  else
33
- request.env['HTTP_REFERER'].present? && request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
34
+ request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
34
35
  end
35
36
  end
36
37
  end
@@ -25,7 +25,7 @@ module Spree
25
25
  end
26
26
  end
27
27
  else
28
- respond_with(@order)
28
+ respond_with(@order, status: :unprocessable_entity)
29
29
  end
30
30
  end
31
31
 
@@ -1,7 +1,6 @@
1
1
  module Spree
2
2
  class StoreController < ApplicationController
3
3
  include Spree::Core::ControllerHelpers::Auth
4
- include Spree::Core::ControllerHelpers::Common
5
4
  include Spree::Core::ControllerHelpers::Search
6
5
  include Spree::Core::ControllerHelpers::Store
7
6
  include Spree::Core::ControllerHelpers::StrongParameters
@@ -12,10 +11,16 @@ module Spree
12
11
 
13
12
  respond_to :html
14
13
 
14
+ layout :get_layout
15
+
15
16
  helper 'spree/base'
16
17
  helper 'spree/locale'
17
18
  helper 'spree/currency'
18
19
 
20
+ helper_method :title
21
+ helper_method :title=
22
+ helper_method :accurate_title
23
+
19
24
  skip_before_action :verify_authenticity_token, only: :ensure_cart, raise: false
20
25
 
21
26
  before_action :redirect_to_default_locale
@@ -43,10 +48,46 @@ module Spree
43
48
 
44
49
  protected
45
50
 
51
+ # can be used in views as well as controllers.
52
+ # e.g. <% self.title = 'This is a custom title for this view' %>
53
+ attr_writer :title
54
+
55
+ def title
56
+ title_string = @title.present? ? @title : accurate_title
57
+ if title_string.present?
58
+ if Spree::Frontend::Config[:always_put_site_name_in_title] && !title_string.include?(default_title)
59
+ [title_string, default_title].join(" #{Spree::Frontend::Config[:title_site_name_separator]} ")
60
+ else
61
+ title_string
62
+ end
63
+ else
64
+ default_title
65
+ end
66
+ end
67
+
68
+ def default_title
69
+ current_store.name
70
+ end
71
+
72
+ # this is a hook for subclasses to provide title
73
+ def accurate_title
74
+ current_store.seo_title
75
+ end
76
+
46
77
  def config_locale
47
78
  Spree::Frontend::Config[:locale]
48
79
  end
49
80
 
81
+ # Returns which layout to render.
82
+ #
83
+ # You can set the layout you want to render inside your Spree configuration with the +:layout+ option.
84
+ #
85
+ # Default layout is: +app/views/spree/layouts/spree_application+
86
+ #
87
+ def get_layout
88
+ layout ||= Spree::Frontend::Config[:layout]
89
+ end
90
+
50
91
  def store_etag
51
92
  [
52
93
  current_store,
@@ -9,12 +9,18 @@ module Spree
9
9
  end
10
10
 
11
11
  def logo(image_path = nil, options = {})
12
- image_path ||= if current_store.logo.attached? && current_store.logo.variable?
13
- main_app.url_for(current_store.logo.variant(resize: '244x104>'))
14
- elsif current_store.logo.attached? && current_store.logo.image?
15
- main_app.url_for(current_store.logo)
12
+ logo_attachment = if defined?(Spree::StoreLogo) && current_store.logo.is_a?(Spree::StoreLogo)
13
+ current_store.logo.attachment # Spree v5
14
+ else
15
+ current_store.logo # Spree 4.x
16
+ end
17
+
18
+ image_path ||= if logo_attachment&.attached? && logo_attachment&.variable?
19
+ main_app.cdn_image_url(logo_attachment.variant(resize: '244x104>'))
20
+ elsif logo_attachment&.attached? && logo_attachment&.image?
21
+ main_app.cdn_image_url(current_store.logo)
16
22
  else
17
- Spree::Config[:logo]
23
+ asset_path('logo/spree_50.png')
18
24
  end
19
25
 
20
26
  path = spree.respond_to?(:root_path) ? spree.root_path : main_app.root_path
@@ -165,7 +171,7 @@ module Spree
165
171
  image = default_image_for_product_or_variant(product)
166
172
 
167
173
  image_url = if image.present?
168
- main_app.url_for(image.url('plp'))
174
+ main_app.cdn_image_url(image.url('plp'))
169
175
  else
170
176
  asset_path('noimage/plp.svg')
171
177
  end
@@ -200,7 +206,7 @@ module Spree
200
206
  widths = { lg: 1200, md: 992, sm: 768, xs: 576 }
201
207
  set = []
202
208
  widths.each do |key, value|
203
- file = main_app.url_for(image.url("plp_and_carousel_#{key}"))
209
+ file = main_app.cdn_image_url(image.url("plp_and_carousel_#{key}"))
204
210
 
205
211
  set << "#{file} #{value}w"
206
212
  end
@@ -352,7 +358,7 @@ module Spree
352
358
  def spree_social_link(service)
353
359
  return '' if current_store.send(service).blank?
354
360
 
355
- link_to "https://#{service}.com/#{current_store.send(service)}", target: :blank, rel: 'nofollow noopener', 'aria-label': service do
361
+ link_to "https://#{service}.com/#{current_store.send(service)}", target: '_blank', rel: 'nofollow noopener', 'aria-label': service do
356
362
  content_tag :figure, id: service, class: 'px-2' do
357
363
  icon(name: service, width: 22, height: 22)
358
364
  end
@@ -373,6 +379,24 @@ module Spree
373
379
  content_tag :span, nil, class: "flag-icon flag-icon-#{country_iso_code.downcase}"
374
380
  end
375
381
 
382
+ def product_wysiwyg_editor_enabled?
383
+ defined?(Spree::Backend) && Spree::Backend::Config[:product_wysiwyg_editor_enabled]
384
+ end
385
+
386
+ def taxon_wysiwyg_editor_enabled?
387
+ defined?(Spree::Backend) && Spree::Backend::Config[:taxon_wysiwyg_editor_enabled]
388
+ end
389
+
390
+ # converts line breaks in product description into <p> tags (for html display purposes)
391
+ def product_description(product)
392
+ description = if Spree::Frontend::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled?
393
+ product.description
394
+ else
395
+ product.description.to_s.gsub(/(.*?)\r?\n\r?\n/m, '<p>\1</p>')
396
+ end
397
+ description.blank? ? Spree.t(:product_has_no_description) : description
398
+ end
399
+
376
400
  private
377
401
 
378
402
  def formatted_price(value)
@@ -26,7 +26,7 @@ module Spree
26
26
  DEPRECATION
27
27
 
28
28
  @spree_nav_cache_key = begin
29
- keys = base_cache_key + [current_store, spree_navigation_data_cache_key, Spree::Config[:logo], stores&.cache_key_with_version, section]
29
+ keys = base_cache_key + [current_store, spree_navigation_data_cache_key, stores&.cache_key_with_version, section]
30
30
  Digest::MD5.hexdigest(keys.join('-'))
31
31
  end
32
32
  end
@@ -67,7 +67,7 @@ module Spree
67
67
  "/#{I18n.locale}"
68
68
  end
69
69
 
70
- if Spree::MenuItem::DYNAMIC_RESOURCE_TYPE.include? item.linked_resource_type
70
+ if ['Spree::Product', 'Spree::Taxon', 'Spree::CmsPage'].include?(item.linked_resource_type)
71
71
  output_locale.to_s + item.link
72
72
  elsif item.linked_resource_type == 'Home Page'
73
73
  "/#{locale_param}"
@@ -67,7 +67,7 @@ module Spree
67
67
  }
68
68
  end
69
69
  else
70
- filter_content_tag(option_value.name, opts.merge(is_selected: is_selected))
70
+ filter_content_tag(option_value.presentation, opts.merge(is_selected: is_selected))
71
71
  end
72
72
  end
73
73
  end
@@ -28,7 +28,7 @@ module Spree
28
28
  end
29
29
 
30
30
  def should_render_store_chooser?
31
- Spree::Config.show_store_selector && stores.size > 1
31
+ Spree::Frontend::Config[:show_store_selector] && stores.size > 1
32
32
  end
33
33
 
34
34
  def store_link(store = nil, html_opts = {})
@@ -0,0 +1,101 @@
1
+ require 'uri'
2
+
3
+ module Spree
4
+ class BuildLocalizedRedirectUrl
5
+ prepend Spree::ServiceModule::Base
6
+
7
+ LOCALE_REGEX = /^\/[A-Za-z]{2}\/|^\/[A-Za-z]{2}-[A-Za-z]{2}\/|^\/[A-Za-z]{2}$|^\/[A-Za-z]{2}-[A-Za-z]{2}$/.freeze
8
+
9
+ SUPPORTED_PATHS_REGEX = /\/(products|t\/|cart|checkout|addresses|content|pages)/.freeze
10
+
11
+ # rubocop:disable Lint/UnusedMethodArgument
12
+ def call(url:, locale:, default_locale: nil)
13
+ run :initialize_url_object
14
+ run :generate_new_path
15
+ run :append_locale_param
16
+ run :build_url
17
+ end
18
+ # rubocop:enable Lint/UnusedMethodArgument
19
+
20
+ protected
21
+
22
+ def initialize_url_object(url:, locale:, default_locale:)
23
+ success(
24
+ url: URI(url),
25
+ locale: locale,
26
+ default_locale_supplied: default_locale_supplied?(locale, default_locale)
27
+ )
28
+ end
29
+
30
+ def generate_new_path(url:, locale:, default_locale_supplied:)
31
+ unless supported_path?(url.path)
32
+ return success(
33
+ url: url,
34
+ locale: locale,
35
+ path: cleanup_path(url.path),
36
+ default_locale_supplied: default_locale_supplied,
37
+ locale_added_to_path: false
38
+ )
39
+ end
40
+
41
+ new_path = if default_locale_supplied
42
+ maches_locale_regex?(url.path) ? url.path.gsub(LOCALE_REGEX, '/') : url.path
43
+ else
44
+ maches_locale_regex?(url.path) ? url.path.gsub(LOCALE_REGEX, "/#{locale}/") : "/#{locale}#{url.path}"
45
+ end
46
+
47
+ success(
48
+ url: url,
49
+ locale: locale,
50
+ path: cleanup_path(new_path),
51
+ default_locale_supplied: default_locale_supplied,
52
+ locale_added_to_path: true
53
+ )
54
+ end
55
+
56
+ def append_locale_param(url:, locale:, path:, default_locale_supplied:, locale_added_to_path:)
57
+ return success(url: url, path: path, query: url.query) if locale_added_to_path
58
+
59
+ query_params = Rack::Utils.parse_nested_query(url.query)
60
+
61
+ if default_locale_supplied
62
+ query_params.delete('locale')
63
+ else
64
+ query_params.merge!('locale' => locale)
65
+ end
66
+
67
+ query_string = query_params.any? ? query_params.to_query : nil
68
+
69
+ success(url: url, path: path, query: query_string)
70
+ end
71
+
72
+ def build_url(url:, path:, query:)
73
+ localized_url = builder_class(url).build(host: url.host, port: url.port, path: path, query: query).to_s
74
+ success(localized_url)
75
+ end
76
+
77
+ private
78
+
79
+ def supported_path?(path)
80
+ return true if path.blank? || path == '/' || maches_locale_regex?(path)
81
+
82
+ path.match(SUPPORTED_PATHS_REGEX)
83
+ end
84
+
85
+ def maches_locale_regex?(path)
86
+ path.match(LOCALE_REGEX)[0].gsub('/', '') if path.match(LOCALE_REGEX)
87
+ end
88
+
89
+ def default_locale_supplied?(locale, default_locale)
90
+ default_locale.present? && default_locale.to_s == locale.to_s
91
+ end
92
+
93
+ def cleanup_path(path)
94
+ path.chomp('/').gsub('//', '/')
95
+ end
96
+
97
+ def builder_class(url)
98
+ url.scheme == 'http' ? URI::HTTP : URI::HTTPS
99
+ end
100
+ end
101
+ end
@@ -35,7 +35,7 @@
35
35
  <% end %>
36
36
  </div>
37
37
 
38
- <% if Spree::Config[:shipping_instructions] %>
38
+ <% if Spree::Frontend::Config[:shipping_instructions] %>
39
39
  <div id="minstrs" data-hook>
40
40
  <h4 class="h5">
41
41
  <%= Spree.t(:shipping_instructions) %>
@@ -33,7 +33,7 @@ end
33
33
  </div>
34
34
 
35
35
  <div class="row checkout-content" data-hook="checkout_content">
36
- <%= form_for @order, url: spree.update_checkout_path(@order.state), html: { id: "checkout_form_#{@order.state}", class: "w-100 d-lg-flex align-items-lg-baseline flex-wrap position-relative" } do |form| %>
36
+ <%= form_for @order, url: spree.update_checkout_path(@order.state), html: { id: "checkout_form_#{@order.state}", class: "w-100 d-lg-flex align-items-lg-baseline flex-wrap position-relative", data: { turbo: false } } do |form| %>
37
37
  <div class="<%= if @order.state != 'confirm' then 'col-lg-6' else 'col-md-12' end %>" data-hook="checkout_form_wrapper">
38
38
  <%= form.hidden_field :state_lock_version %>
39
39
  <%= render @order.state, form: form %>
@@ -15,7 +15,7 @@
15
15
  </div>
16
16
  <% path = spree.respond_to?(:update_checkout_registration_path) ? spree.update_checkout_registration_path : spree_signup_path %>
17
17
 
18
- <%= form_for @order, url: path, method: :put, html: { id: 'checkout_form_registration' } do |f| %>
18
+ <%= form_for @order, url: path, method: :put, html: { id: 'checkout_form_registration', data: { turbo: false } } do |f| %>
19
19
  <div class="form-group">
20
20
  <p class="form-group checkout-content-inner-field">
21
21
  <%= f.email_field :email, class: 'spree-flat-input', placeholder: Spree.t(:email) %>
@@ -16,7 +16,7 @@
16
16
  <% variant.option_values.sort { |ov| ov.option_type.position }.each do |ov| %>
17
17
  <li class="item-details">
18
18
  <% # TODO: rework option values so options_text method can be used here %>
19
- <%= "#{ov.option_type.presentation}: #{ov.name.titleize}" %>
19
+ <%= "#{ov.option_type.presentation}: #{ov.presentation}" %>
20
20
  </li>
21
21
  <% end %>
22
22
  </ul>
@@ -22,7 +22,7 @@
22
22
  <% end %>
23
23
 
24
24
  <div class="shopping-cart-item-delete <%= additional_classes %>" data-hook="cart_item_delete">
25
- <%= link_to '#', class: 'delete', id: "delete_#{dom_id(line_item)}", data: { turbolinks: false, id: dom_id(line_item), variant_sku: line_item.sku, variant_name: line_item.name, variant_price: line_item.price, variant_options: line_item.options_text }, aria: { label: Spree.t('cart_page.remove_from_cart') } do %>
25
+ <%= link_to '#', class: 'delete', id: "delete_#{dom_id(line_item)}", data: { turbo: false, id: dom_id(line_item), variant_sku: line_item.sku, variant_name: line_item.name, variant_price: line_item.price, variant_options: line_item.options_text }, aria: { label: Spree.t('cart_page.remove_from_cart') } do %>
26
26
  <%= icon(name: 'garbage',
27
27
  classes: 'shopping-cart-item-delete-icon',
28
28
  width: 18.9,
@@ -9,14 +9,14 @@
9
9
  <li>
10
10
  <%= label_tag "variant_option_value_id_#{option_type[:id]}_#{option_value[:id]}",
11
11
  class: "m-1 m-sm-2 m-md-1 color-select-label",
12
- title: option_value[:name]&.humanize,
12
+ title: option_value[:presentation],
13
13
  data: { toggle: "tooltip", placement: "bottom" } do %>
14
14
 
15
15
  <%= radio_button_tag "variant_option_value_id_#{option_type[:id]}",
16
16
  option_value[:id],
17
17
  option_value[:is_default] && index == 0,
18
18
  class: "product-variants-variant-values-radio",
19
- aria: { label: option_value[:name] },
19
+ aria: { label: option_value[:presentation] },
20
20
  data: {
21
21
  "option-type-index" => index,
22
22
  "presentation" => option_value[:presentation],
@@ -1,6 +1,6 @@
1
1
  <h3 class="pt-4 font-weight-bold text-uppercase product-details-subtitle"><%= Spree.t(:description) %></h3>
2
2
 
3
- <% if Spree::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled? %>
3
+ <% if Spree::Frontend::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled? %>
4
4
  <div id="product-description-long" class="m-0 text-break product-description" data-hook="description">
5
5
  <%= raw product_description(@product) %>
6
6
  </div>
@@ -9,7 +9,7 @@
9
9
  <% option_type_name = ot_filter_param.titleize %>
10
10
  <% collapsed = params[ot_filter_param].blank? %>
11
11
 
12
- <button class="card-header <%= 'collapsed' if collapsed %> px-1 plp-filters-card-header" id="filters<%= option_type_name %>" data-toggle="collapse" data-target="#collapseFilter<%= option_type_name %>" aria-expanded="<%= !collapsed %>" aria-controls="collapseFilter<%= option_type_name %>" role="heading" aria-level="2">
12
+ <button class="card-header <%= 'collapsed' if collapsed %> px-1 plp-filters-card-header" id="filters<%= ot_filter_param %>" data-toggle="collapse" data-target="#collapseFilter<%= ot_filter_param %>" aria-expanded="<%= !collapsed %>" aria-controls="collapseFilter<%= ot_filter_param %>" role="heading" aria-level="2">
13
13
  <%= option_type.presentation %>
14
14
  <%= icon(name: 'plus',
15
15
  classes: 'mt-1 float-right arrow plp-filters-card-header-arrow--plus',
@@ -20,7 +20,7 @@
20
20
  width: 16,
21
21
  height: 16) %>
22
22
  </button>
23
- <div id="collapseFilter<%= option_type_name %>" class="collapse <%= 'show' unless collapsed %>" aria-labelledby="filters<%= option_type_name %>">
23
+ <div id="collapseFilter<%= ot_filter_param %>" class="collapse <%= 'show' unless collapsed %>" aria-labelledby="filters<%= ot_filter_param %>">
24
24
  <div class="card-body px-0 pt-1">
25
25
  <%= render 'spree/shared/option_values',
26
26
  option_type: option_type,
@@ -36,7 +36,7 @@
36
36
  <% property_name = property.name %>
37
37
  <% collapsed = params.dig(:properties, property.filter_param).blank? %>
38
38
  <button class="card-header <%= 'collapsed' if collapsed %> px-1 plp-filters-card-header" id="filters<%= property_name %>" data-toggle="collapse" data-target="#collapseFilter<%= property_name %>" aria-expanded="<%= !collapsed %>" aria-controls="collapseFilter<%= property_name %>" role="heading" aria-level="2">
39
- <%= property.presentation.titleize %>
39
+ <%= property.presentation %>
40
40
  <%= icon(name: 'plus',
41
41
  classes: 'mt-1 float-right arrow plp-filters-card-header-arrow--plus',
42
42
  width: 16,
@@ -16,7 +16,7 @@
16
16
 
17
17
  <div class="card plp-overlay-card">
18
18
  <div class="card-header text-uppercase <%= 'collapsed' if params[ot_downcase_name].blank? %> plp-overlay-card-header" data-toggle="collapse" id="filtersMobile<%= option_type_name %>" data-target="#collapseFilterMobile<%= option_type_name %>" aria-expanded="true" aria-controls="collapseFilterMobile<%= option_type_name %>" role="heading" aria-level="3">
19
- <%= option_type_name %>
19
+ <%= option_type.presentation %>
20
20
  <%= icon(name: 'arrow-right',
21
21
  classes: 'spree-icon-arrow spree-icon-arrow-right mt-1 float-right arrow plp-overlay-card-header-arrow',
22
22
  width: 16,
@@ -36,7 +36,7 @@
36
36
  <% collapsed = params.dig(:properties, property.filter_param).blank? %>
37
37
  <div class="card plp-overlay-card">
38
38
  <div class="card-header text-uppercase <%= 'collapsed' if collapsed %> plp-overlay-card-header" data-toggle="collapse" id="filtersMobile<%= property_name %>" data-target="#collapseFilterMobile<%= property_name %>" aria-expanded="true" aria-controls="collapseFilterMobile<%= property_name %>" role="heading" aria-level="3">
39
- <%= property_name %>
39
+ <%= property.presentation %>
40
40
  <%= icon(name: 'arrow-right',
41
41
  classes: 'spree-icon-arrow spree-icon-arrow-right mt-1 float-right arrow plp-overlay-card-header-arrow',
42
42
  width: 16,
@@ -3,7 +3,7 @@
3
3
  <ul id="product-thumbnails" class="thumbnails d-flex w-100 pl-0 my-4" data-hook>
4
4
  <% @product.images.each do |i| %>
5
5
  <li class='tmb-all mr-2 tmb-<%= i.viewable.id %>'>
6
- <%= link_to(image_tag(main_app.url_for(i.url(:mini)), class: "img-thumbnail d-inline-block"), main_app.url_for(i.url(:product))) %>
6
+ <%= link_to(image_tag(main_app.cdn_image_url(i.url(:mini)), class: "img-thumbnail d-inline-block"), main_app.cdn_image_url(i.url(:product))) %>
7
7
  </li>
8
8
  <% end %>
9
9
 
@@ -11,7 +11,7 @@
11
11
  <% @product.variant_images.each do |i| %>
12
12
  <% next if @product.images.include?(i) %>
13
13
  <li class='vtmb mr-2 tmb-<%= i.viewable.id %>'>
14
- <%= link_to(image_tag(main_app.url_for(i.url(:mini)), class: "img-thumbnail"), main_app.url_for(i.url(:product))) %>
14
+ <%= link_to(image_tag(main_app.cdn_image_url(i.url(:mini)), class: "img-thumbnail"), main_app.cdn_image_url(i.url(:product))) %>
15
15
  </li>
16
16
  <% end %>
17
17
  <% end %>