Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Move frontend preferences out of spree core (#11354)
Damian Legawiec1b0b533e8350
diff --git a/api/lib/spree/api/engine.rb b/api/lib/spree/api/engine.rbindex 4bfab5f6c0..89298616bf 100644--- a/api/lib/spree/api/engine.rb+++ b/api/lib/spree/api/engine.rb@@ -17,7 +17,8 @@ module Spreeinitializer 'spree.api.checking_deprecated_preferences' doSpree::Api::Config.deprecated_preferences.each do |pref|- warn "[DEPRECATION] Spree::Api::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"+ # FIXME: we should only notify about deprecated preferences that are in use, not all of them+ # warn "[DEPRECATION] Spree::Api::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"endenddiff --git a/backend/app/controllers/spree/admin/general_settings_controller.rb b/backend/app/controllers/spree/admin/general_settings_controller.rbindex 2b51004e03..e557fd67fb 100644--- a/backend/app/controllers/spree/admin/general_settings_controller.rb+++ b/backend/app/controllers/spree/admin/general_settings_controller.rb@@ -26,11 +26,6 @@ module Spreehead :no_contentend- def render(*args)- @preferences_currency |= [:show_store_selector]- super- end-privatedef update_currency_settingsdiff --git a/backend/app/helpers/spree/admin/base_helper.rb b/backend/app/helpers/spree/admin/base_helper.rbindex 568b916250..e7bc6d4ee6 100644--- a/backend/app/helpers/spree/admin/base_helper.rb+++ b/backend/app/helpers/spree/admin/base_helper.rb@@ -285,6 +285,14 @@ module Spree'default'endend++ def product_wysiwyg_editor_enabled?+ Spree::Backend::Config[:product_wysiwyg_editor_enabled]+ end++ def taxon_wysiwyg_editor_enabled?+ Spree::Backend::Config[:taxon_wysiwyg_editor_enabled]+ endendendenddiff --git a/backend/app/models/spree/backend_configuration.rb b/backend/app/models/spree/backend_configuration.rbindex a95c6aa11a..da4273815f 100644--- a/backend/app/models/spree/backend_configuration.rb+++ b/backend/app/models/spree/backend_configuration.rb@@ -3,6 +3,8 @@ module Spreepreference :locale, :string, default: Rails.application.config.i18n.default_localepreference :variants_per_page, :integer, default: Kaminari.config.default_per_pagepreference :menus_per_page, :integer, default: Kaminari.config.default_per_page+ preference :product_wysiwyg_editor_enabled, :boolean, default: true+ preference :taxon_wysiwyg_editor_enabled, :boolean, default: trueORDER_TABS ||= [:orders, :payments, :creditcard_payments,:shipments, :credit_cards, :return_authorizations,diff --git a/backend/app/views/spree/admin/general_settings/edit.html.erb b/backend/app/views/spree/admin/general_settings/edit.html.erbindex 787396b4ca..8267e9d2b9 100644--- a/backend/app/views/spree/admin/general_settings/edit.html.erb+++ b/backend/app/views/spree/admin/general_settings/edit.html.erb@@ -75,27 +75,6 @@</div></div></div>-- <div class="card mb-3" id="general-settings-stores" data-hook="general_settings_stores">- <div class="card-header">- <h1 class="card-title mb-0 h5">- <%= Spree.t(:multiple_stores) %>- </h1>- </div>- <div class="card-body">- <div class="alert alert-warning col-12">- <%= Spree.t('show_store_selector.long') %>- </div>- <div class="form-group">- <div class="checkbox">- <label>- <%= check_box('', :show_store_selector, { checked: Spree::Config.show_store_selector }) %>- <%= Spree.t('show_store_selector.short') %>- </label>- </div>- </div>- </div>- </div></div></div>diff --git a/backend/lib/spree/backend/engine.rb b/backend/lib/spree/backend/engine.rbindex e6ea9e70e1..2d217ac9d3 100644--- a/backend/lib/spree/backend/engine.rb+++ b/backend/lib/spree/backend/engine.rb@@ -14,7 +14,8 @@ module Spreeinitializer 'spree.backend.checking_deprecated_preferences' doSpree::Backend::Config.deprecated_preferences.each do |pref|- warn "[DEPRECATION] Spree::Backend::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"+ # FIXME: we should only notify about deprecated preferences that are in use, not all of them+ # warn "[DEPRECATION] Spree::Backend::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"endendenddiff --git a/backend/spec/features/admin/general_settings/prices_settings_presence_spec.rb b/backend/spec/features/admin/general_settings/prices_settings_presence_spec.rbdeleted file mode 100644index 4e00a5e72c..0000000000--- a/backend/spec/features/admin/general_settings/prices_settings_presence_spec.rb+++ /dev/null@@ -1,13 +0,0 @@-require 'spec_helper'--describe 'Currencies settings presence', type: :feature, js: true do- stub_authorization!-- context 'when accessing general settings page' do- it 'Multi Currency settings are present' do- visit spree.edit_admin_general_settings_path-- expect(page).to have_content 'Show Store selector'- end- end-enddiff --git a/backend/spec/features/admin/general_settings/prices_settings_updating_spec.rb b/backend/spec/features/admin/general_settings/prices_settings_updating_spec.rbindex 32210302ae..a3d3ff0d8e 100644--- a/backend/spec/features/admin/general_settings/prices_settings_updating_spec.rb+++ b/backend/spec/features/admin/general_settings/prices_settings_updating_spec.rb@@ -4,50 +4,6 @@ describe 'Updating currencies settings', type: :feature, js: true dolet!(:store) { create(:store, default: true) }stub_authorization!- describe 'enabling currency settings' do- before do- reset_spree_preferences do |config|- config.show_store_selector = false- end- end-- it 'allows to enable currency settings' do- visit spree.edit_admin_general_settings_path-- # Test initial state- expect(page).to have_unchecked_field('show_store_selector')-- # Interact with the form- check('show_store_selector')- click_button 'Update'-- # Test final state- expect(page).to have_content 'General Settings has been successfully updated!'- expect(page).to have_checked_field('show_store_selector')- assert_admin_flash_alert_success('General Settings has been successfully updated!')- end- end-- describe 'disabling currency settings' do- before do- reset_spree_preferences do |config|- config.show_store_selector = true- end- end-- it 'allows to disable currency settings' do- visit spree.edit_admin_general_settings_path-- expect(page).to have_checked_field('show_store_selector')-- uncheck('show_store_selector')- click_button 'Update'-- expect(page).to have_content 'General Settings has been successfully updated!'- expect(page).to have_unchecked_field('show_store_selector')- end- end-describe 'clearing cache' doit 'returns flash alert of type success' dovisit spree.edit_admin_general_settings_pathdiff --git a/backend/spec/features/admin/products/edit/products_spec.rb b/backend/spec/features/admin/products/edit/products_spec.rbindex b0275b60a6..d7eb9f3e25 100644--- a/backend/spec/features/admin/products/edit/products_spec.rb+++ b/backend/spec/features/admin/products/edit/products_spec.rb@@ -7,11 +7,11 @@ describe 'Product Details', type: :feature, js: true docontext 'editing a product with WYSIWYG disabled' dobefore do- Spree::Config.product_wysiwyg_editor_enabled = false+ Spree::Backend::Config.product_wysiwyg_editor_enabled = falsevisit spree.admin_product_path(product)end- after { Spree::Config.product_wysiwyg_editor_enabled = true }+ after { Spree::Backend::Config.product_wysiwyg_editor_enabled = true }it 'displays the product description as a standard input field' doexpect(page).to have_field(id: 'product_description', with: product.description)@@ -21,7 +21,7 @@ describe 'Product Details', type: :feature, js: true docontext 'editing a product with WYSIWYG editer enabled' dobefore do- Spree::Config.product_wysiwyg_editor_enabled = true+ Spree::Backend::Config.product_wysiwyg_editor_enabled = truevisit spree.admin_product_path(product)enddiff --git a/backend/spec/features/admin/taxons_spec.rb b/backend/spec/features/admin/taxons_spec.rbindex 19abdd4a7c..99772a0ba7 100644--- a/backend/spec/features/admin/taxons_spec.rb+++ b/backend/spec/features/admin/taxons_spec.rb@@ -16,9 +16,9 @@ describe 'Taxonomies and taxons', type: :feature, js: true doendcontext 'when WYSIWYG editor is disabled' do- before { Spree::Config.taxon_wysiwyg_editor_enabled = false }+ before { Spree::Backend::Config.taxon_wysiwyg_editor_enabled = false }- after { Spree::Config.taxon_wysiwyg_editor_enabled = true }+ after { Spree::Backend::Config.taxon_wysiwyg_editor_enabled = true }it 'displays the taxon description as a standard input field' dovisit spree.edit_admin_taxonomy_taxon_path(taxonomy, taxonomy.root.id)diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rbindex 1345239f7b..f2ec0c1ce2 100644--- a/core/app/helpers/spree/base_helper.rb+++ b/core/app/helpers/spree/base_helper.rb@@ -65,7 +65,7 @@ module Spreeelsif current_store.logo.attached? && current_store.logo.image?main_app.url_for(current_store.logo)else- Spree::Config[:logo]+ 'logo/spree_50.png'endpath = spree.respond_to?(:root_path) ? spree.root_path : main_app.root_path@@ -269,9 +269,5 @@ module Spreetag('meta', name: 'robots', content: current_store.seo_robots)end-- def taxon_wysiwyg_editor_enabled?- Spree::Config[:taxon_wysiwyg_editor_enabled]- endendenddiff --git a/core/app/helpers/spree/products_helper.rb b/core/app/helpers/spree/products_helper.rbindex ee5e144665..a2e3c28074 100644--- a/core/app/helpers/spree/products_helper.rb+++ b/core/app/helpers/spree/products_helper.rb@@ -44,20 +44,6 @@ module Spreevariants_option_types_presenter(variants, product).optionsend- def product_wysiwyg_editor_enabled?- Spree::Config[:product_wysiwyg_editor_enabled]- end-- # converts line breaks in product description into <p> tags (for html display purposes)- def product_description(product)- description = if Spree::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled?- product.description- else- product.description.to_s.gsub(/(.*?)\r?\n\r?\n/m, '<p>\1</p>')- end- description.blank? ? Spree.t(:product_has_no_description) : description- end-def line_item_description_text(description_text)if description_text.present?truncate(strip_tags(description_text.gsub(' ', ' ').squish), length: 100)diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rbindex a9c22c641f..2c7a3fd447 100644--- a/core/app/models/spree/app_configuration.rb+++ b/core/app/models/spree/app_configuration.rb@@ -35,8 +35,8 @@ module Spreepreference :allow_guest_checkout, :boolean, default: truepreference :alternative_shipping_phone, :boolean, default: false # Request extra phone for ship addrpreference :always_include_confirm_step, :boolean, default: false # Ensures confirmation step is always in checkout_progress bar, but does not force a confirm step if your payment methods do not support it.- preference :always_put_site_name_in_title, :boolean, default: true- preference :title_site_name_separator, :string, default: '-' # When always_put_site_name_in_title is true, insert a separator character before the site name in the title+ preference :always_put_site_name_in_title, :boolean, deprecated: true+ preference :title_site_name_separator, :string, deprecated: truepreference :auto_capture, :boolean, default: false # automatically capture the credit card (as opposed to just authorize and capture later)preference :auto_capture_on_dispatch, :boolean, default: false # Captures payment for each shipment in Shipment#after_ship callback, and makes Shipment.ready when payment authorized.preference :binary_inventory_cache, :boolean, default: false # only invalidate product cache when a stock item changes whether it is in_stock@@ -48,23 +48,21 @@ module Spreepreference :disable_store_presence_validation, :boolean, default: false # when turned off disables Store presence validation for Products and Payment Methodspreference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.preference :expedited_exchanges_days_window, :integer, default: 14 # the amount of days the customer has to return their item after the expedited exchange is shipped in order to avoid being charged- preference :layout, :string, default: 'spree/layouts/spree_application'- preference :logo, :string, default: 'logo/spree_50.png'- preference :mailer_logo, :string, default: 'logo/spree_50.png'- preference :max_level_in_taxons_menu, :integer, default: 1 # maximum nesting level in taxons menu+ preference :layout, :string, deprecated: 'Please use Spree::Frontend::Config[:layout] instead'+ preference :logo, :string, deprecated: true+ preference :mailer_logo, :string, deprecated: true+ preference :max_level_in_taxons_menu, :integer, deprecated: truepreference :products_per_page, :integer, default: 12- preference :product_wysiwyg_editor_enabled, :boolean, default: truepreference :require_master_price, :boolean, default: truepreference :restock_inventory, :boolean, default: true # Determines if a return item is restocked automatically once it has been receivedpreference :return_eligibility_number_of_days, :integer, default: 365preference :send_core_emails, :boolean, default: true # Default mail headers settings- preference :shipping_instructions, :boolean, default: false # Request instructions/info for shipping+ preference :shipping_instructions, :boolean, deprecated: truepreference :show_only_complete_orders_by_default, :boolean, default: truepreference :show_variant_full_price, :boolean, default: false # Displays variant full price or difference with product price. Default false to be compatible with older behaviorpreference :show_products_without_price, :boolean, default: false- preference :show_raw_product_description, :boolean, default: false+ preference :show_raw_product_description, :boolean, deprecated: truepreference :tax_using_ship_address, :boolean, default: true- preference :taxon_wysiwyg_editor_enabled, :boolean, default: truepreference :track_inventory_levels, :boolean, default: true # Determines whether to track on_hand values for variants / products.# Store credits configurations@@ -72,7 +70,7 @@ module Spreepreference :credit_to_new_allocation, :boolean, default: false# Multi store configurations- preference :show_store_selector, :boolean, default: false+ preference :show_store_selector, :boolean, deprecated: true# searcher_class allows spree extension writers to provide their own Search classdef searcher_classdiff --git a/core/lib/spree/core/controller_helpers/common.rb b/core/lib/spree/core/controller_helpers/common.rbindex 2aab4817b5..f30ad19e89 100644--- a/core/lib/spree/core/controller_helpers/common.rb+++ b/core/lib/spree/core/controller_helpers/common.rb@@ -17,6 +17,9 @@ module Spreeattr_writer :titledef title+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)+ ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.+ DEPRECATIONtitle_string = @title.present? ? @title : accurate_titleif title_string.present?if Spree::Config[:always_put_site_name_in_title] && !title_string.include?(default_title)@@ -30,11 +33,17 @@ module Spreeenddef default_title+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)+ ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.+ DEPRECATIONcurrent_store.nameend# this is a hook for subclasses to provide titledef accurate_title+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)+ ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.+ DEPRECATIONcurrent_store.seo_titleend@@ -56,7 +65,12 @@ module Spree# Default layout is: +app/views/spree/layouts/spree_application+#def get_layout- layout ||= Spree::Config[:layout]+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)+ ControllerHelpers::Common is deprecated and will be removed in Spree 5.0.+ DEPRECATION+ return unless defined?(Spree::Frontend)++ layout ||= Spree::Frontend::Config[:layout]endendenddiff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rbindex ef1763fa1c..4cd642af7b 100644--- a/core/lib/spree/core/engine.rb+++ b/core/lib/spree/core/engine.rb@@ -131,7 +131,8 @@ module Spreeinitializer 'spree.core.checking_deprecated_preferences' doSpree::Config.deprecated_preferences.each do |pref|- warn "[DEPRECATION] Spree::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"+ # FIXME: we should only notify about deprecated preferences that are in use, not all of them+ # warn "[DEPRECATION] Spree::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"endenddiff --git a/core/spec/helpers/products_helper_spec.rb b/core/spec/helpers/products_helper_spec.rbindex 1fe01efeea..854ee76cbf 100644--- a/core/spec/helpers/products_helper_spec.rb+++ b/core/spec/helpers/products_helper_spec.rb@@ -117,59 +117,6 @@ module Spreeendend- context '#product_description' do- context 'when configuration is set to sanitize output' do- before { Spree::Config.product_wysiwyg_editor_enabled = false }-- after { Spree::Config.product_wysiwyg_editor_enabled = true }-- # Regression test for #1607- it 'renders a product description without excessive paragraph breaks' do- product.description = %Q{-<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a ligula leo. Proin eu arcu at ipsum dapibus ullamcorper. Pellentesque egestas orci nec magna condimentum luctus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut ac ante et mauris bibendum ultricies non sed massa. Fusce facilisis dui eget lacus scelerisque eget aliquam urna ultricies. Duis et rhoncus quam. Praesent tellus nisi, ultrices sed iaculis quis, euismod interdum ipsum.</p>-<ul>-<li>Lorem ipsum dolor sit amet</li>-<li>Lorem ipsum dolor sit amet</li>-</ul>- }- description = product_description(product)- expect(description.strip).to eq(product.description.strip)- end-- it 'renders a product description with automatic paragraph breaks' do- product.description = %Q{-THIS IS THE BEST PRODUCT EVER!--"IT CHANGED MY LIFE" - Sue, MD}-- description = product_description(product)- expect(description.strip).to eq(%Q{<p>\nTHIS IS THE BEST PRODUCT EVER!</p>"IT CHANGED MY LIFE" - Sue, MD})- end-- it 'renders a product description without any formatting based on configuration' do- initial_description = %Q{- <p>hello world</p>-- <p>tihs is completely awesome and it works</p>-- <p>why so many spaces in the code. and why some more formatting afterwards?</p>- }-- product.description = initial_description-- Spree::Config[:show_raw_product_description] = true- description = product_description(product)- expect(description).to eq(initial_description)- end-- context 'renders a product description default description incase description is blank' do- before { product.description = '' }-- it { expect(product_description(product)).to eq(Spree.t(:product_has_no_description)) }- end- end- end-shared_examples_for 'line item descriptions' docontext 'variant has a blank description' dolet(:description) { nil }diff --git a/core/spec/lib/spree/core/controller_helpers/common_spec.rb b/core/spec/lib/spree/core/controller_helpers/common_spec.rbdeleted file mode 100644index d0acb40419..0000000000--- a/core/spec/lib/spree/core/controller_helpers/common_spec.rb+++ /dev/null@@ -1,38 +0,0 @@-require 'spec_helper'--class FakesController < ApplicationController- include Spree::Core::ControllerHelpers::Common-end--describe Spree::Core::ControllerHelpers::Common, type: :controller do- controller(FakesController) {}- let!(:helper) { Spree::Core::ControllerHelpers::Common }-- describe '#title' do- before do- Spree::Config[:always_put_site_name_in_title] = true- Spree::Config[:title_site_name_separator] = '-'- end-- context 'when title with current store name is present' do- let!(:store) { create(:store, name: 'Spree Test Store', seo_title: 'Spree - Spree Test Store') }-- it 'returns that title' do- allow_any_instance_of(helper).to receive(:current_store).and_return(store)-- expect(controller.send(:title)).to eq store.seo_title- end- end-- context 'when title without current store name is present' do- let!(:store) { create(:store, name: 'Spree Test Store', seo_title: 'Spree') }-- it 'returns title with current store name' do- allow_any_instance_of(helper).to receive(:current_store).and_return(store)-- title = store.seo_title + ' - ' + store.name- expect(controller.send(:title)).to eq title- end- end- end-enddiff --git a/core/spec/models/spree/app_configuration_spec.rb b/core/spec/models/spree/app_configuration_spec.rbindex 19dbc90527..2064b91415 100644--- a/core/spec/models/spree/app_configuration_spec.rb+++ b/core/spec/models/spree/app_configuration_spec.rb@@ -3,16 +3,6 @@ require 'spec_helper'describe Spree::AppConfiguration, type: :model dolet (:prefs) { Rails.application.config.spree.preferences }- it 'is available from the environment' do- prefs.layout = 'my/layout'- expect(prefs.layout).to eq 'my/layout'- end-- it 'is available as Spree::Config for legacy access' do- Spree::Config.layout = 'my/layout'- expect(Spree::Config.layout).to eq 'my/layout'- end-it 'uses base searcher class by default' doprefs.searcher_class = nilexpect(prefs.searcher_class).to eq Spree::Core::Search::Basediff --git a/emails/app/helpers/spree/mail_helper.rb b/emails/app/helpers/spree/mail_helper.rbindex 70af4883d0..9860b2b96c 100644--- a/emails/app/helpers/spree/mail_helper.rb+++ b/emails/app/helpers/spree/mail_helper.rb@@ -21,7 +21,7 @@ module SpreePlease upload a Store logo insteadDEPRECATION- Spree::Config.mailer_logo || Spree::Config.logo+ 'logo/spree_50.png'enddef logo_pathdiff --git a/emails/spec/helpers/spree/mail_helper_spec.rb b/emails/spec/helpers/spree/mail_helper_spec.rbindex c91f684d13..c985ef93e9 100644--- a/emails/spec/helpers/spree/mail_helper_spec.rb+++ b/emails/spec/helpers/spree/mail_helper_spec.rb@@ -57,12 +57,6 @@ module Spreeallow(helper).to receive(:current_store) { store }end- context 'when no custom logo attached' do- it 'shows default mailer logo' do- expect(subject).to eq Spree::Config[:mailer_logo]- end- end-context 'when @order exists' dolet(:logo_image) { File.open(File.expand_path('../../../app/assets/images/logo/spree_50.png', __dir__)) }diff --git a/frontend/app/controllers/spree/locale_controller.rb b/frontend/app/controllers/spree/locale_controller.rbindex 62802114d2..37963cc6f3 100644--- a/frontend/app/controllers/spree/locale_controller.rb+++ b/frontend/app/controllers/spree/locale_controller.rb@@ -1,6 +1,6 @@module Spreeclass LocaleController < Spree::StoreController- REDIRECT_TO_ROOT = /\/(#{Spree::Config[:storefront_pages_path]})\//.freeze+ REDIRECT_TO_ROOT = /\/(pages)\//.freezedef indexrender :index, layout: falsediff --git a/frontend/app/controllers/spree/store_controller.rb b/frontend/app/controllers/spree/store_controller.rbindex b45c363ca2..076a48d781 100644--- a/frontend/app/controllers/spree/store_controller.rb+++ b/frontend/app/controllers/spree/store_controller.rb@@ -1,7 +1,6 @@module Spreeclass StoreController < ApplicationControllerinclude Spree::Core::ControllerHelpers::Auth- include Spree::Core::ControllerHelpers::Commoninclude Spree::Core::ControllerHelpers::Searchinclude Spree::Core::ControllerHelpers::Storeinclude Spree::Core::ControllerHelpers::StrongParameters@@ -12,10 +11,16 @@ module Spreerespond_to :html+ layout :get_layout+helper 'spree/base'helper 'spree/locale'helper 'spree/currency'+ helper_method :title+ helper_method :title=+ helper_method :accurate_title+skip_before_action :verify_authenticity_token, only: :ensure_cart, raise: falsebefore_action :redirect_to_default_locale@@ -43,10 +48,46 @@ module Spreeprotected+ # can be used in views as well as controllers.+ # e.g. <% self.title = 'This is a custom title for this view' %>+ attr_writer :title++ def title+ title_string = @title.present? ? @title : accurate_title+ if title_string.present?+ if Spree::Frontend::Config[:always_put_site_name_in_title] && !title_string.include?(default_title)+ [title_string, default_title].join(" #{Spree::Frontend::Config[:title_site_name_separator]} ")+ else+ title_string+ end+ else+ default_title+ end+ end++ def default_title+ current_store.name+ end++ # this is a hook for subclasses to provide title+ def accurate_title+ current_store.seo_title+ end+def config_localeSpree::Frontend::Config[:locale]end+ # Returns which layout to render.+ #+ # You can set the layout you want to render inside your Spree configuration with the +:layout+ option.+ #+ # Default layout is: +app/views/spree/layouts/spree_application++ #+ def get_layout+ layout ||= Spree::Frontend::Config[:layout]+ end+def store_etag[current_store,diff --git a/frontend/app/helpers/spree/frontend_helper.rb b/frontend/app/helpers/spree/frontend_helper.rbindex b6bd005253..7139afe6c0 100644--- a/frontend/app/helpers/spree/frontend_helper.rb+++ b/frontend/app/helpers/spree/frontend_helper.rb@@ -14,7 +14,7 @@ module Spreeelsif current_store.logo.attached? && current_store.logo.image?main_app.url_for(current_store.logo)else- Spree::Config[:logo]+ 'logo/spree_50.png'endpath = spree.respond_to?(:root_path) ? spree.root_path : main_app.root_path@@ -373,6 +373,24 @@ module Spreecontent_tag :span, nil, class: "flag-icon flag-icon-#{country_iso_code.downcase}"end+ def product_wysiwyg_editor_enabled?+ defined?(Spree::Backend) && Spree::Backend::Config[:product_wysiwyg_editor_enabled]+ end++ def taxon_wysiwyg_editor_enabled?+ defined?(Spree::Backend) && Spree::Backend::Config[:taxon_wysiwyg_editor_enabled]+ end++ # converts line breaks in product description into <p> tags (for html display purposes)+ def product_description(product)+ description = if Spree::Frontend::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled?+ product.description+ else+ product.description.to_s.gsub(/(.*?)\r?\n\r?\n/m, '<p>\1</p>')+ end+ description.blank? ? Spree.t(:product_has_no_description) : description+ end+privatedef formatted_price(value)diff --git a/frontend/app/helpers/spree/navigation_helper.rb b/frontend/app/helpers/spree/navigation_helper.rbindex e46ef0905e..40697b5c4e 100644--- a/frontend/app/helpers/spree/navigation_helper.rb+++ b/frontend/app/helpers/spree/navigation_helper.rb@@ -26,7 +26,7 @@ module SpreeDEPRECATION@spree_nav_cache_key = begin- keys = base_cache_key + [current_store, spree_navigation_data_cache_key, Spree::Config[:logo], stores&.cache_key_with_version, section]+ keys = base_cache_key + [current_store, spree_navigation_data_cache_key, stores&.cache_key_with_version, section]Digest::MD5.hexdigest(keys.join('-'))endenddiff --git a/frontend/app/helpers/spree/store_helper.rb b/frontend/app/helpers/spree/store_helper.rbindex d6acf2d2f2..5ec9c8c46a 100644--- a/frontend/app/helpers/spree/store_helper.rb+++ b/frontend/app/helpers/spree/store_helper.rb@@ -28,7 +28,7 @@ module Spreeenddef should_render_store_chooser?- Spree::Config.show_store_selector && stores.size > 1+ Spree::Frontend::Config[:show_store_selector] && stores.size > 1enddef store_link(store = nil, html_opts = {})diff --git a/frontend/app/models/spree/frontend_configuration.rb b/frontend/app/models/spree/frontend_configuration.rbindex 848b931edc..fd8f257a15 100644--- a/frontend/app/models/spree/frontend_configuration.rb+++ b/frontend/app/models/spree/frontend_configuration.rb@@ -1,10 +1,16 @@module Spreeclass FrontendConfiguration < Preferences::Configuration+ preference :additional_filters_partials, :array, default: %w()+ preference :always_put_site_name_in_title, :boolean, default: truepreference :coupon_codes_enabled, :boolean, default: true # Determines if we show coupon code form at cart and checkoutpreference :http_cache_enabled, :boolean, default: true+ preference :layout, :string, default: 'spree/layouts/spree_application'preference :locale, :string, default: nilpreference :products_filters, :array, default: %w(keywords price sort_by)- preference :additional_filters_partials, :array, default: %w()preference :remember_me_enabled, :boolean, default: true+ preference :shipping_instructions, :boolean, default: false # Request instructions/info for shipping+ preference :show_raw_product_description, :boolean, default: false+ preference :show_store_selector, :boolean, default: false+ preference :title_site_name_separator, :string, default: '-' # When always_put_site_name_in_title is true, insert a separator character before the site name in the titleendenddiff --git a/core/app/services/spree/build_localized_redirect_url.rb b/frontend/app/services/spree/build_localized_redirect_url.rbsimilarity index 93%rename from core/app/services/spree/build_localized_redirect_url.rbrename to frontend/app/services/spree/build_localized_redirect_url.rbindex 3b50f814f9..acc67e0c5f 100644--- a/core/app/services/spree/build_localized_redirect_url.rb+++ b/frontend/app/services/spree/build_localized_redirect_url.rb@@ -6,7 +6,7 @@ module SpreeLOCALE_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- SUPPORTED_PATHS_REGEX = /\/(#{Spree::Config[:storefront_products_path]}|#{Spree::Config[:storefront_taxons_path]}\/|cart|checkout|addresses|content|#{Spree::Config[:storefront_pages_path]})/.freeze+ SUPPORTED_PATHS_REGEX = /\/(products|t\/|cart|checkout|addresses|content|pages)/.freeze# rubocop:disable Lint/UnusedMethodArgumentdef call(url:, locale:, default_locale: nil)diff --git a/frontend/app/views/spree/checkout/_delivery.html.erb b/frontend/app/views/spree/checkout/_delivery.html.erbindex 875cc33447..c3045cb7fc 100644--- a/frontend/app/views/spree/checkout/_delivery.html.erb+++ b/frontend/app/views/spree/checkout/_delivery.html.erb@@ -35,7 +35,7 @@<% end %></div>- <% if Spree::Config[:shipping_instructions] %>+ <% if Spree::Frontend::Config[:shipping_instructions] %><div id="minstrs" data-hook><h4 class="h5"><%= Spree.t(:shipping_instructions) %>diff --git a/frontend/app/views/spree/products/_description.html.erb b/frontend/app/views/spree/products/_description.html.erbindex 49282b6866..8d43a60d29 100644--- a/frontend/app/views/spree/products/_description.html.erb+++ b/frontend/app/views/spree/products/_description.html.erb@@ -1,6 +1,6 @@<h3 class="pt-4 font-weight-bold text-uppercase product-details-subtitle"><%= Spree.t(:description) %></h3>-<% if Spree::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled? %>+<% if Spree::Frontend::Config[:show_raw_product_description] || product_wysiwyg_editor_enabled? %><div id="product-description-long" class="m-0 text-break product-description" data-hook="description"><%= raw product_description(@product) %></div>diff --git a/frontend/app/views/spree/shared/_taxonomies.html.erb b/frontend/app/views/spree/shared/_taxonomies.html.erbdeleted file mode 100644index 61cde28d5b..0000000000--- a/frontend/app/views/spree/shared/_taxonomies.html.erb+++ /dev/null@@ -1,16 +0,0 @@-<% max_level = Spree::Config[:max_level_in_taxons_menu] || 1 %>--<nav id="taxonomies" class="sidebar-item" data-hook aria-label="taxonomies">- <% @taxonomies.each do |taxonomy| %>- <% cache [I18n.locale, taxonomy, max_level, @taxon] do %>- <% if taxonomy.root.children.any? %>- <div class="mt-4">- <h4 class='taxonomy-root h5'>- <%= Spree.t(:shop_by_taxonomy, taxonomy: taxonomy.name) %>- </h4>- <%= taxons_tree(taxonomy.root, @taxon, max_level) %>- </div>- <% end %>- <% end %>- <% end %>-</nav>diff --git a/frontend/config/routes.rb b/frontend/config/routes.rbindex 614d32fbb7..eac853cede 100644--- a/frontend/config/routes.rb+++ b/frontend/config/routes.rb@@ -2,11 +2,11 @@ Spree::Core::Engine.add_routes doscope '(:locale)', locale: /#{Spree.available_locales.join('|')}/, defaults: { locale: nil } doroot to: 'home#index'- resources :products, only: [:index, :show], path: "/#{Spree::Config[:storefront_products_path]}"+ resources :products, only: [:index, :show], path: '/products'- get "/#{Spree::Config[:storefront_products_path]}/:id/related", to: 'products#related'+ get '/products/:id/related', to: 'products#related'# route globbing for pretty nested taxon and product paths- get "/#{Spree::Config[:storefront_taxons_path]}/*id", to: 'taxons#show', as: :nested_taxons+ get '/t/*id', to: 'taxons#show', as: :nested_taxonsget '/product_carousel/:id', to: 'taxons#product_carousel'# non-restful checkout stuff@@ -34,7 +34,7 @@ Spree::Core::Engine.add_routes doget '/api_tokens', to: 'store#api_tokens'post '/ensure_cart', to: 'store#ensure_cart'- get "#{Spree::Config[:storefront_pages_path]}/:slug", to: 'cms_pages#show', as: :page+ get '/pages/:slug', to: 'cms_pages#show', as: :pageget '/forbidden', to: 'errors#forbidden', as: :forbiddenget '/unauthorized', to: 'errors#unauthorized', as: :unauthorizeddiff --git a/frontend/lib/spree/frontend/engine.rb b/frontend/lib/spree/frontend/engine.rbindex 7ffc56f0cf..e316056674 100644--- a/frontend/lib/spree/frontend/engine.rb+++ b/frontend/lib/spree/frontend/engine.rb@@ -20,7 +20,8 @@ module Spreeinitializer 'spree.frontend.checking_deprecated_preferences' doSpree::Frontend::Config.deprecated_preferences.each do |pref|- warn "[DEPRECATION] Spree::Frontend::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"+ # FIXME: we should only notify about deprecated preferences that are in use, not all of them+ # warn "[DEPRECATION] Spree::Frontend::Config[:#{pref[:name]}] is deprecated. #{pref[:message]}"endendenddiff --git a/frontend/spec/controllers/spree/home_controller_spec.rb b/frontend/spec/controllers/spree/home_controller_spec.rbindex 64f7e62745..974b428a91 100644--- a/frontend/spec/controllers/spree/home_controller_spec.rb+++ b/frontend/spec/controllers/spree/home_controller_spec.rb@@ -14,7 +14,7 @@ describe Spree::HomeController, type: :controller doendcontext 'different layout specified in config' do- before { Spree::Config.layout = 'layouts/application' }+ before { Spree::Frontend::Config.layout = 'layouts/application' }it 'renders specified layout' doget :indexdiff --git a/frontend/spec/controllers/spree/store_controller_spec.rb b/frontend/spec/controllers/spree/store_controller_spec.rbindex 9cffa4fbcc..718580e5d1 100644--- a/frontend/spec/controllers/spree/store_controller_spec.rb+++ b/frontend/spec/controllers/spree/store_controller_spec.rb@@ -94,4 +94,32 @@ describe Spree::StoreController, type: :controller doendendend++ describe '#title' do+ before do+ Spree::Frontend::Config[:always_put_site_name_in_title] = true+ Spree::Frontend::Config[:title_site_name_separator] = '-'+ end++ context 'when title with current store name is present' do+ let!(:store) { create(:store, name: 'Spree Test Store', seo_title: 'Spree - Spree Test Store') }++ it 'returns that title' do+ allow(controller).to receive(:current_store).and_return(store)++ expect(controller.send(:title)).to eq store.seo_title+ end+ end++ context 'when title without current store name is present' do+ let!(:store) { create(:store, name: 'Spree Test Store', seo_title: 'Spree') }++ it 'returns title with current store name' do+ allow(controller).to receive(:current_store).and_return(store)++ title = store.seo_title + ' - ' + store.name+ expect(controller.send(:title)).to eq title+ end+ end+ endenddiff --git a/frontend/spec/features/caching/taxons_spec.rb b/frontend/spec/features/caching/taxons_spec.rbdeleted file mode 100644index 35a8e14a46..0000000000--- a/frontend/spec/features/caching/taxons_spec.rb+++ /dev/null@@ -1,21 +0,0 @@-# require 'spec_helper'--# describe 'taxons', type: :feature, caching: true do-# let!(:taxonomy) { create(:taxonomy) }--# before do-# create(:taxon, taxonomy: taxonomy)-# # warm up the cache-# visit spree.root_path-# assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")--# clear_cache_events-# end--# it 'busts the cache when max_level_in_taxons_menu conf changes' do-# Spree::Config[:max_level_in_taxons_menu] = 5-# visit spree.root_path-# assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")-# expect(cache_writes.count).to eq(1)-# end-# enddiff --git a/frontend/spec/features/main_nav_bar_spec.rb b/frontend/spec/features/main_nav_bar_spec.rbindex 8039a7108a..cc19a30815 100644--- a/frontend/spec/features/main_nav_bar_spec.rb+++ b/frontend/spec/features/main_nav_bar_spec.rb@@ -12,9 +12,7 @@ describe 'Main navigation bar', type: :feature dolet!(:stores) { create_list(:store, stores_number, default_country: create(:country)) }before do- reset_spree_preferences do |config|- config.show_store_selector = true- end+ Spree::Frontend::Config[:show_store_selector] = truevisit spree.root_pathend@@ -51,9 +49,7 @@ describe 'Main navigation bar', type: :feature dolet!(:stores) { create_list(:store, stores_number) }before do- reset_spree_preferences do |config|- config.show_store_selector = false- end+ Spree::Frontend::Config[:show_store_selector] = falsevisit spree.root_pathenddiff --git a/frontend/spec/features/products_spec.rb b/frontend/spec/features/products_spec.rbindex 31ee33acf9..ab75468738 100644--- a/frontend/spec/features/products_spec.rb+++ b/frontend/spec/features/products_spec.rb@@ -407,83 +407,6 @@ describe 'Visiting Products', type: :feature, inaccessible: true doendend- context 'when rendering the product description with product_wysiwyg_editor_enabled = false' do- before { Spree::Config.product_wysiwyg_editor_enabled = false }-- after { Spree::Config.product_wysiwyg_editor_enabled = true }-- context 'when <script> tag exists' do- it 'prevents the script from running', js: true do- description = '<script>window.alert("Message")</script>'- product = FactoryBot.create(:base_product, description: description, name: 'Sample', price: '19.99')-- accept_alert(wait: 1) { visit spree.product_path(product) }- fail 'XSS alert exists'-- rescue Capybara::ModalNotFound- end-- it 'returns sanitized js text in html' do- description = '<script>window.alert("Message")</script>'- product = FactoryBot.create(:base_product, description: description, name: 'Sample', price: '19.99')- visit spree.product_path(product)-- within('#product-description-long') do- expect(text).to eq('window.alert("Message")')- end- end- end-- context 'when <a> tag exists' do- it 'returns <a> tag in html' do- description = '<a href="example.com">link</a>'- product = FactoryBot.create(:base_product, description: description, name: 'Sample', price: '19.99')- visit spree.product_path(product)-- within('[data-hook=product_description]') do- node = first('[data-hook=description]')- expect(node).to have_selector 'a'- end- end- end-- context 'when there are multiple lines' do- it 'returns <p> tag in html' do- description = "first paragraph\n\nsecond paragraph"- product = FactoryBot.create(:base_product, description: description, name: 'Sample', price: '19.99')- visit spree.product_path(product)-- within('[data-hook=product_description]') do- node = first('[data-hook=description]')- expect(node).to have_selector 'p'- end- end- end- end-- context 'when rendering the product description with product_wysiwyg_editor_enabled' do- before { Spree::Config.product_wysiwyg_editor_enabled = true }-- context 'when <table> tag exists' do- it 'returns <table> tag in html' do- description = '<table style="border-collapse: collapse; width: 100%; height: 66px;" border="1">- <tbody>- <tr style="height: 22px;">- <td style="width: 17.341967680608363%; height: 22px;">This is the table</td>- </tr>- </tbody>- </table>'- product = FactoryBot.create(:base_product, description: description, name: 'Sample', price: '19.99')- visit spree.product_path(product)-- within('[data-hook=product_description]') do- node = first('[data-hook=description]')- expect(node).to have_selector 'table'- end- end- end- end-context 'product is on sale', js: true dolet(:product) doFactoryBot.create(:base_product, description: 'Testing sample', name: 'Sample', price: '19.99')diff --git a/frontend/spec/features/taxons_spec.rb b/frontend/spec/features/taxons_spec.rbindex fe5a90c087..9b953956c0 100644--- a/frontend/spec/features/taxons_spec.rb+++ b/frontend/spec/features/taxons_spec.rb@@ -44,29 +44,6 @@ describe 'viewing products', type: :feature, inaccessible: true doendend- describe 'viewing taxon when WYSIWYG is enabled' do- before do- visit '/t/category/super-clothing/t-shirts'- end-- it 'renders the html tables in the taxon description' do- expect(page).to have_selector 'table'- end- end-- describe 'viewing taxon when WYSIWYG is disabled' do- before do- Spree::Config.taxon_wysiwyg_editor_enabled = false- visit '/t/category/super-clothing/t-shirts'- end-- after { Spree::Config.taxon_wysiwyg_editor_enabled = true }-- it 'strips out the html tables tags from the description' do- expect(page).not_to have_selector 'table'- end- end-describe 'meta tags and title' doit 'displays metas' dot_shirts.update metasdiff --git a/frontend/spec/helpers/frontend_helper_spec.rb b/frontend/spec/helpers/frontend_helper_spec.rbindex 8a672e7bdb..58712c4d90 100644--- a/frontend/spec/helpers/frontend_helper_spec.rb+++ b/frontend/spec/helpers/frontend_helper_spec.rb@@ -55,5 +55,44 @@ module Spreeit { expect(country_flag_icon('US')).to eq('<span class="flag-icon flag-icon-us"></span>') }it { expect { country_flag_icon(nil) }.not_to raise_error }end++ describe '#product_description' do+ let(:store) { create(:store) }+ let(:product) { create(:product, stores: [store]) }++ context 'when configuration is set to sanitize output' do+ it 'renders a product description with automatic paragraph breaks' do+ product.description = %Q{+THIS IS THE BEST PRODUCT EVER!++"IT CHANGED MY LIFE" - Sue, MD}++ description = product_description(product)+ expect(description.strip).to eq(%Q{<p>\nTHIS IS THE BEST PRODUCT EVER!</p>"IT CHANGED MY LIFE" - Sue, MD})+ end++ it 'renders a product description without any formatting based on configuration' do+ initial_description = %Q{+ <p>hello world</p>++ <p>tihs is completely awesome and it works</p>++ <p>why so many spaces in the code. and why some more formatting afterwards?</p>+ }++ product.description = initial_description++ Spree::Frontend::Config[:show_raw_product_description] = true+ description = product_description(product)+ expect(description).to eq(initial_description)+ end++ context 'renders a product description default description incase description is blank' do+ before { product.description = '' }++ it { expect(product_description(product)).to eq(Spree.t(:product_has_no_description)) }+ end+ end+ endendenddiff --git a/frontend/spec/helpers/store_helper_spec.rb b/frontend/spec/helpers/store_helper_spec.rbindex 9f714a20bf..39fed2b85f 100644--- a/frontend/spec/helpers/store_helper_spec.rb+++ b/frontend/spec/helpers/store_helper_spec.rb@@ -47,9 +47,9 @@ module Spreedescribe '#should_render_store_chooser?' docontext 'enabled' do- before { Spree::Config.show_store_selector = true }+ before { Spree::Frontend::Config.show_store_selector = true }- after { Spree::Config.show_store_selector = false }+ after { Spree::Frontend::Config.show_store_selector = false }context 'with 1 store' doit { expect(should_render_store_chooser?).to be_falsey }diff --git a/core/spec/services/spree/build_localized_redirect_url_spec.rb b/frontend/spec/services/spree/build_localized_redirect_url_spec.rbsimilarity index 100%rename from core/spec/services/spree/build_localized_redirect_url_spec.rbrename to frontend/spec/services/spree/build_localized_redirect_url_spec.rb