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
Open source `StoreCeontroller`, helpers, concerns and layout
Damian Legawiecd18ad56566ef
diff --git a/storefront/app/controllers/concerns/spree/locale_urls.rb b/storefront/app/controllers/concerns/spree/locale_urls.rbnew file mode 100644index 0000000000..fbe324f752--- /dev/null+++ b/storefront/app/controllers/concerns/spree/locale_urls.rb@@ -0,0 +1,23 @@+module Spree+ module LocaleUrls+ extend ActiveSupport::Concern++ included do+ before_action :redirect_to_default_locale+ end++ private++ def default_url_options+ locale = current_locale == current_store.default_locale ? nil : current_locale++ super.merge(locale: locale, currency: currency_param)+ end++ def redirect_to_default_locale+ return if params[:locale].blank? || supported_locale?(params[:locale])++ redirect_to url_for(request.parameters.merge(locale: nil))+ end+ end+enddiff --git a/storefront/app/controllers/concerns/spree/password_protected.rb b/storefront/app/controllers/concerns/spree/password_protected.rbnew file mode 100644index 0000000000..ff5c0d4137--- /dev/null+++ b/storefront/app/controllers/concerns/spree/password_protected.rb@@ -0,0 +1,17 @@+module Spree+ module PasswordProtected+ extend ActiveSupport::Concern++ included do+ before_action :redirect_to_password+ end++ def redirect_to_password+ return if page_builder_enabled?+ return if session[:password_valid]+ return if turbo_frame_request?++ redirect_to password_path, status: 307 if respond_to?(:current_store) && current_store && current_store.prefers_password_protected?+ end+ end+enddiff --git a/storefront/app/controllers/concerns/spree/theme_concern.rb b/storefront/app/controllers/concerns/spree/theme_concern.rbnew file mode 100644index 0000000000..9465971ea0--- /dev/null+++ b/storefront/app/controllers/concerns/spree/theme_concern.rb@@ -0,0 +1,20 @@+module Spree+ module ThemeConcern+ extend ActiveSupport::Concern++ included do+ helper 'spree/theme'+ include Spree::ThemeHelper+ end++ def default_url_options+ if current_theme.present? && current_theme_preview.present?+ super.merge!(theme_id: current_theme.id, theme_preview_id: current_theme_preview.id)+ elsif params[:theme_id].present? && params[:theme_preview_id].blank?+ super.merge!(theme_id: params[:theme_id])+ else+ super+ end+ end+ end+enddiff --git a/storefront/app/controllers/spree/store_controller.rb b/storefront/app/controllers/spree/store_controller.rbnew file mode 100644index 0000000000..8af794fa03--- /dev/null+++ b/storefront/app/controllers/spree/store_controller.rb@@ -0,0 +1,254 @@+module Spree+ class StoreController < BaseController+ include Spree::Core::ControllerHelpers::Order++ include Spree::LocaleUrls+ include Spree::ThemeConcern+ include Spree::StorefrontHelper+ include Spree::PasswordProtected+ include Spree::WishlistHelper+ include Spree::AnalyticsHelper++ layout :choose_layout++ helper 'spree/base'+ helper 'spree/locale'+ helper 'spree/storefront_locale'+ helper 'spree/currency'+ helper 'spree/addresses'+ helper 'spree/wishlist'++ helper_method :title+ helper_method :title=+ helper_method :accurate_title++ helper_method :current_taxon, :store_filter_names++ helper_method :permitted_products_params, :products_filters_params,+ :storefront_products_scope, :storefront_products,+ :default_products_sort, :default_products_finder_params++ prepend_before_action :set_theme_view_paths+ before_action :redirect_to_default_locale+ before_action :render_404_if_store_not_exists+ rescue_from ActionController::InvalidAuthenticityToken, with: :invalid_authenticity_token++ def render_404_if_store_not_exists+ return if current_store.present?++ render 'errors/404', layout: 'application', status: :not_found+ end++ def current_taxon+ @current_taxon ||= (current_store.taxons.find_by(id: params[:taxon_id]) if params[:taxon_id].present?)+ end++ def store_filter_names+ @store_filter_names ||= Spree::OptionType.filterable.order(:position).pluck(:name)+ end++ def store_filter_names_hash+ filter_names = {}+ store_filter_names.each do |filter_name|+ filter_names[filter_name.to_sym] = []+ end+ filter_names+ end++ def permitted_products_params+ @permitted_products_params ||= params.permit(+ :locale,+ :currency,+ :q,+ :page,+ :per_page,+ :sort_by,+ filter: [+ :min_price,+ :max_price,+ :purchasable,+ :out_of_stock,+ {+ options: [store_filter_names_hash],+ taxon_ids: []+ }+ ]+ )+ end++ def default_products_sort+ 'manual'+ end++ def products_filters_params+ @products_filters_params ||= permitted_products_params[:filter]&.compact_blank || {}+ end++ protected++ def set_theme_view_paths+ # add default Spree theme+ prepend_view_path [Spree::Storefront::Engine.root, 'app/views/themes/default'].join('/')+ # add current theme+ prepend_view_path "app/views/themes/#{current_theme.class.name.demodulize.underscore}"+ end++ def choose_layout+ if turbo_frame_request? && !current_theme_preview.present?+ 'turbo_rails/frame'+ else+ 'spree/storefront'+ end+ end++ # 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?+ title_string+ else+ default_title+ end+ end++ def default_title+ @default_title ||= current_store.name+ end++ # this is a hook for subclasses to provide title+ def accurate_title+ @accurate_title ||= current_store.seo_title.presence || current_store.name+ end++ def storefront_products_scope+ current_store.products.active(current_currency)+ end++ def default_products_finder_params+ taxon = @taxon || current_taxon++ filter = permitted_products_params.fetch(:filter, {}).dup++ filter[:taxon_ids] ||= [taxon&.id.to_s].compact+ filter[:taxons] = filter[:taxon_ids].join(',')++ if filter.key?(:min_price) || filter.key?(:max_price)+ min_price = filter[:min_price].presence || 0+ max_price = filter[:max_price].presence || 'Infinity'++ filter[:price] = [min_price, max_price].compact.join(',')+ end++ permitted_products_params.merge(+ store: current_store,+ filter: filter,+ currency: current_currency+ )+ end++ def storefront_products+ @storefront_products ||= begin+ finder_params = default_products_finder_params+ finder_params[:sort_by] ||= @taxon&.sort_order || 'manual'++ products_finder = Spree::Dependencies.products_finder.constantize+ products = products_finder.+ new(scope: storefront_products_scope, params: finder_params).+ execute.+ includes(storefront_products_includes)++ default_per_page = ENV.fetch('STOREFRONT_PRODUCTS_PER_PAGE', '20,40').split(',').map(&:to_i)+ per_page = params[:per_page].present? ? params[:per_page].to_i : default_per_page++ GearedPagination::Recordset.new(products, per_page: per_page).page(params[:page] || 1)+ end+ end++ def storefront_products_includes+ [+ :prices_including_master,+ :variant_images,+ :option_types,+ :option_values,+ { master: [:images, :prices, :stock_items, :stock_locations, { stock_items: :stock_location }],+ variants: [+ :images, :prices, :option_values, :stock_items, :stock_locations,+ { option_values: :option_type, stock_items: :stock_location }+ ],+ taxons: [:taxonomy],+ taggings: [:tag] }+ ]+ end++ def redirect_unauthorized_access+ if try_spree_current_user+ flash[:error] = Spree.t(:authorization_failure)+ redirect_to spree.forbidden_path+ else+ store_location+ if respond_to?(:spree_login_path)+ redirect_to spree_login_path+ else+ redirect_to spree.root_path+ end+ end+ end++ def redirect_back_or_default(default)+ redirect_to(session[:user_return_to] || default)+ end++ def require_user(return_to = nil)+ return if try_spree_current_user++ store_location(return_to)++ respond_to do |format|+ format.html { redirect_to spree_login_path }+ format.turbo_stream { render turbo_stream: turbo_stream.slideover_open('slideover-account', 'account-pane') }+ end+ end++ # this will work for devise out of the box+ # for other auth systems you will need to override this method+ def store_location(location = nil)+ return if try_spree_current_user+ return unless defined?(store_location_for)+ return unless defined?(Devise)++ location ||= request.fullpath++ store_location_for(Devise.mappings.keys.first, location)+ end++ def skip_ahoy+ false+ end++ def redirect_to_cart+ redirect_to spree.cart_path+ end++ def clear_order_token+ cookies.delete(:token)+ end++ def disable_sesion_tracking+ request.session_options[:skip] = true+ end++ def invalid_authenticity_token(exception)+ Spree::ErrorHandler.call(exception: exception)++ flash[:error] = Spree.t(:something_went_wrong)++ respond_to do |format|+ format.html { redirect_back_or_to root_path }+ format.turbo_stream { render turbo_stream: turbo_stream.update('flash', partial: 'spree/shared/flashes') }+ end+ end+ end+enddiff --git a/storefront/app/helpers/spree/analytics_helper.rb b/storefront/app/helpers/spree/analytics_helper.rbnew file mode 100644index 0000000000..8104c6b1d3--- /dev/null+++ b/storefront/app/helpers/spree/analytics_helper.rb@@ -0,0 +1,27 @@+module Spree+ module AnalyticsHelper+ def analytics_event_handlers+ @analytics_event_handlers ||= Spree::Analytics.event_handlers.map do |handler|+ handler.new(user: try_spree_current_user, session: session, request: request)+ end+ end++ def track_event(event_name, record)+ return if current_theme_preview.present?+ return if unsupported_event?(event_name)++ analytics_event_handlers.each do |handler|+ handler.handle_event(event_name, record)+ end+ rescue => e+ Spree::ErrorHandler.call(+ exception: e,+ opts: { report_context: { event_name: event_name, record: record } }+ )+ end++ def unsupported_event?(event_name)+ !Spree::Analytics.events.key?(event_name.to_sym)+ end+ end+enddiff --git a/storefront/app/helpers/spree/fonts_helper.rb b/storefront/app/helpers/spree/fonts_helper.rbnew file mode 100644index 0000000000..03ca12cad5--- /dev/null+++ b/storefront/app/helpers/spree/fonts_helper.rb@@ -0,0 +1,62 @@+module Spree+ module FontsHelper+ def normal_font_family_styles+ return '' if current_theme_or_preview.preferred_font_family.blank?+ return if all_fonts_options.exclude?(current_theme_or_preview.preferred_font_family)++ font_family = current_theme_or_preview.preferred_font_family+ text_font_size = (current_theme_or_preview.preferred_font_size_scale || 100) / 100.0++ <<~CSS+ :root {+ --font-body: #{font_family};+ }++ body {+ font-family: '#{font_family}', sans-serif;+ }++ body {+ font-size: #{text_font_size}rem;+ }+ CSS+ end++ def header_font_family_styles+ return '' if current_theme_or_preview.preferred_header_font_family.blank?+ return if all_fonts_options.exclude?(current_theme_or_preview.preferred_header_font_family)++ font_family = current_theme_or_preview.preferred_header_font_family++ <<~CSS+ h1, h2, h3, h4, h5, h6 {+ font-family: '#{font_family}', sans-serif;+ }+ CSS+ end++ def google_fonts_link_tag+ fonts = [current_theme_or_preview.preferred_font_family, current_theme_or_preview.preferred_header_font_family].compact_blank.uniq++ return if fonts.blank?++ imports = fonts.map do |font|+ next if google_fonts_list.exclude?(font)++ "family=#{font.split(' ').join('+')}"+ end.compact.join('&')++ return if imports.blank?+ return if Rails.env.test?++ stylesheet_link_tag "https://fonts.googleapis.com/css2?#{imports}&display=swap"+ end++ def font_styles+ <<~CSS.html_safe+ #{normal_font_family_styles}+ #{header_font_family_styles}+ CSS+ end+ end+enddiff --git a/storefront/app/helpers/spree/page_helper.rb b/storefront/app/helpers/spree/page_helper.rbnew file mode 100644index 0000000000..5f4efa13d3--- /dev/null+++ b/storefront/app/helpers/spree/page_helper.rb@@ -0,0 +1,62 @@+module Spree+ module PageHelper+ def render_page(page = nil, variables = {})+ page ||= current_page++ sections = current_page_preview.present? ? current_page_preview.sections : page.sections+ sections_html = sections.includes(:links, { asset_attachment: :blob }, { blocks: [:rich_text_text, :links] }).map do |section|+ render_section(section, variables)+ end.join.html_safe++ "<main class='page-contents'>#{sections_html}</main>".html_safe+ end++ def render_section(section, variables = {}, lazy_allowed: true)+ return '' if section.blank?++ variables[:section] = section+ variables[:loaded] = true++ if page_builder_enabled?+ turbo_frame_tag("section-#{section.id}") do+ content_tag(:div,+ data: {+ editor_id: "section-#{section.id}",+ editor_name: section.name,+ editor_link: spree.edit_admin_page_section_path(section)+ }+ ) do+ render(section, **variables)+ end+ end+ elsif section.lazy? && lazy_allowed+ variables[:loaded] = false+ variables[:url_options] = { locale: I18n.locale }++ path = section.lazy_path(variables)++ turbo_frame_tag("section-#{section.id}", src: path, loading: 'eager') do+ render(section, **variables)+ end+ else+ render(section, **variables)+ end+ rescue ActionView::MissingTemplate, ActionView::Template::Error => e+ raise e unless Rails.env.production?++ Rails.logger.error("Missing template for section: #{section.type}")+ Sentry.capture_exception(e, extra: { section: section })+ ''+ end++ def page_builder_link_to(link, options = {}, &block)+ if link.present?+ link_to(spree_storefront_resource_url(link.linkable || link), options.except(:label)) do+ block.present? ? block.call : options[:label]+ end+ else+ block&.call+ end+ end+ end+enddiff --git a/storefront/app/helpers/spree/storefront_helper.rb b/storefront/app/helpers/spree/storefront_helper.rbnew file mode 100644index 0000000000..9e7f8107a7--- /dev/null+++ b/storefront/app/helpers/spree/storefront_helper.rb@@ -0,0 +1,71 @@+module Spree+ module StorefrontHelper+ include BaseHelper++ def render_storefront_partials(section)+ Rails.application.config.spree_storefront.send(section).map do |partial|+ render partial: partial+ end.join.html_safe+ end++ def page_description+ return @page_description if @page_description.present?++ @page_description = object.meta_description if object.respond_to?(:meta_description)++ if @page_description.blank? && [Spree::Product, Spree::Taxon, Spree::Post].include?(object.class)+ @page_description = truncate(strip_tags(object.description.to_s).strip, length: 160, separator: ' ', escape: false)+ end++ @page_description = current_store.meta_description if @page_description.blank?++ @page_description+ end++ def page_image+ return @page_image if @page_image.present?++ if object.is_a? Spree::Product+ @page_image = object.default_image&.attachment+ elsif object.respond_to?(:image)+ @page_image = object.image+ end++ @page_image ||= current_store.social_image++ @page_image+ end++ def tailwind_classes_for(flash_type)+ {+ notice: 'alert-notice',+ success: 'alert-success',+ error: 'alert-error',+ alert: 'alert-warning',+ }.stringify_keys[flash_type.to_s] || flash_type.to_s+ end++ def as_aspect_ratio(attachment)+ return unless attachment.present?+ return unless attachment.analyzed?++ metadata = attachment.metadata+ aspect_ratio = metadata['aspect_ratio'].presence++ return aspect_ratio if aspect_ratio++ width = metadata['width']&.to_f+ return unless width++ height = metadata['height']&.to_f+ return unless height++ width / height+ end++ def svg_country_icon(country_code)+ country_code = :us if country_code.to_s.downcase == "en"+ tag.span(class: "fi fi-#{country_code.downcase}")+ end+ end+enddiff --git a/storefront/app/helpers/spree/storefront_locale_helper.rb b/storefront/app/helpers/spree/storefront_locale_helper.rbnew file mode 100644index 0000000000..f28d7ce87d--- /dev/null+++ b/storefront/app/helpers/spree/storefront_locale_helper.rb@@ -0,0 +1,42 @@+module Spree+ module StorefrontLocaleHelper+ def current_locale+ @current_locale ||= if user_locale?+ try_spree_current_user.selected_locale+ elsif params_locale?+ params[:locale]+ elsif header_locale?+ header_locale+ end+ ensure+ @current_locale ||= default_locale+ end++ def header_locale?+ header_locale.present?+ end++ # Taken from rack-contrib+ # https://github.com/rack/rack-contrib/blob/main/lib/rack/contrib/locale.rb#L58+ def header_locale+ header = request.env['HTTP_ACCEPT_LANGUAGE']++ return if header.nil?++ locales = header.gsub(/\s+/, '').split(",").map do |language_tag|+ locale, quality = language_tag.split(/;q=/i)+ quality = quality ? quality.to_f : 1.0+ [locale, quality]+ end+ locales = locales.+ reject { |(locale, quality)| locale == '*' || quality.zero? }.+ sort_by { |(_, quality)| quality }.+ map(&:first)++ locale_from_header = locales.reverse.find { |locale| supported_locale?(locale) }+ locale_from_header ||= locales.reverse.find { |locale| supported_locale?(locale.first(2)) }&.first(2)++ locale_from_header+ end+ end+enddiff --git a/storefront/app/helpers/spree/theme_helper.rb b/storefront/app/helpers/spree/theme_helper.rbnew file mode 100644index 0000000000..2dafa9a4e8--- /dev/null+++ b/storefront/app/helpers/spree/theme_helper.rb@@ -0,0 +1,236 @@+module Spree+ module ThemeHelper+ def current_page+ @current_page ||= current_theme.pages.find_by(type: 'Spree::Pages::Homepage')+ end++ def current_theme+ @current_theme ||= if params[:theme_id].present?+ current_store.themes.find_by(id: params[:theme_id])+ else+ current_store.default_theme || current_store.themes.first+ end+ ensure+ @current_theme ||= current_store.themes.first+ end++ def current_theme_preview+ return if params[:theme_preview_id].blank?++ @current_theme_preview ||= current_theme.previews.find_by(id: params[:theme_preview_id])+ end++ def current_page_preview+ return if params[:page_preview_id].blank?++ @current_page_preview ||= current_page.previews.find_by(id: params[:page_preview_id])+ end++ def current_page_or_preview+ @current_page_or_preview ||= current_page_preview || current_page+ end++ def current_theme_or_preview+ @current_theme_or_preview ||= current_theme_preview || current_theme+ end++ def current_header_logo+ @current_header_logo ||= current_theme_or_preview.sections.find_by(type: 'Spree::PageSections::Header')&.logo+ end++ def page_builder_enabled?+ @page_builder_enabled ||= (current_theme_preview.present? || current_page_preview.present?) && params[:page_builder] == 'true'+ end++ def theme_layout_sections+ @theme_layout_sections ||= current_theme_or_preview.sections.includes(:links, { asset_attachment: :blob },+ { blocks: [:rich_text_text, :links] }).all.each_with_object({}) do |section, hash|+ hash[section.type.to_s.demodulize.underscore] = section+ end+ rescue StandardError => e+ raise e unless Rails.env.production?++ Rails.logger.error("Error rendering theme: #{e.message}")+ Sentry.capture_exception(e)+ {}+ end++ def theme_setting(name)+ if current_theme_preview.present?+ current_theme_preview.preferences.with_indifferent_access[name]+ elsif current_theme.present?+ current_theme.preferences.with_indifferent_access[name]+ end+ end++ # This helper allows us to specify opacity in Tailwind's color palette+ def theme_setting_rgb_components(name)+ hex_color = theme_setting(name)+ return unless hex_color.present?++ rgb = hex_color[0..6].match(/^#(..)(..)(..)$/).captures.map(&:hex)+ rgb.join(', ')+ end++ # https://makandracards.com/makandra/496431-ruby-how-to-convert-hex-color-codes-to-rgb-or-rgba+ def hex_color_to_rgb(hex)+ return unless hex.present?++ rgb = hex[0..6].match(/^#(..)(..)(..)$/).captures.map(&:hex)+ "rgb(#{rgb.join(', ')})"+ end++ def hex_color_to_rgba(hex)+ return unless hex.present?++ *rgb, alpha = hex.match(/^#(..)(..)(..)(..)?$/).captures.map { |hex_pair| hex_pair&.hex }+ opacity = (alpha || 255) / 255.0+ "rgba(#{rgb.join(', ')}, #{opacity.round(2)})"+ end++ def section_styles(section)+ styles = {}++ bg_color = section.preferred_background_color.presence || theme_setting('background_color')+ styles['background-color'] = bg_color+ styles['--section-background'] = bg_color+ text_color = section.preferred_text_color.presence || theme_setting('text_color')+ styles['color'] = text_color+ styles['--section-color'] = text_color+ styles['border-color'] = section.preferred_border_color.presence || theme_setting('border_color')+ styles['padding-top'] = "#{section.preferred_top_padding.presence}px"+ styles['padding-bottom'] = "#{section.preferred_bottom_padding.presence}px"+ styles['border-top-width'] = "#{section.preferred_top_border_width.presence}px"+ border_bottom_width = "#{section.preferred_bottom_border_width.presence}px"+ styles['border-bottom-width'] = border_bottom_width+ styles['--section--border-bottom-width'] = border_bottom_width++ if section.respond_to?(:preferred_button_text_color) && section.preferred_button_text_color.present?+ styles['--button-text-color'] = section.preferred_button_text_color+ end++ if section.respond_to?(:preferred_button_background_color) && section.preferred_button_background_color.present?+ styles['--button-background-color'] = section.preferred_button_background_color+ end++ styles.map { |k, v| "#{k}: #{v}" }.join(';')+ end++ def section_heading_styles(section)+ styles = {}++ styles['text-transform'] = :uppercase if theme_setting('headings_uppercase')+ if section.respond_to?(:preferred_heading_bottom_padding) && section.preferred_heading_bottom_padding.present?+ styles['padding-bottom'] =+ "#{section.preferred_heading_bottom_padding}px"+ end++ styles.compact_blank.map { |k, v| "#{k}: #{v}" }.join(';')+ end++ def block_attributes(block, allowed_styles: :all)+ has_width_desktop = block.respond_to?(:preferred_width_desktop) && block.preferred_width_desktop.present? ? "width-desktop='true'" : nil++ attributes = {+ data: {+ editor_id: "block-#{block.id}",+ editor_name: block.display_name,+ editor_parent_id: "section-#{block.section_id}",+ editor_link: spree.edit_admin_page_section_block_path(block.section, block)+ },+ style: block_styles(block, allowed_styles: allowed_styles),+ width_desktop: has_width_desktop+ }.compact_blank++ tag.attributes(attributes)+ end++ def link_attributes(link, as_html: true)+ parent_type = case link.parent_type+ when 'Spree::PageSection'+ :section+ when 'Spree::PageBlock'+ :block+ else+ return ''+ end++ attributes = {+ data: {+ editor_id: "link-#{link.id}",+ editor_name: link.label,+ editor_parent_id: "#{parent_type}-#{link.parent_id}",+ editor_link: case parent_type+ when :section+ spree.edit_admin_page_link_path(link, page_section_id: link.parent_id)+ when :block+ spree.edit_admin_page_link_path(link, block_id: link.parent_id)+ end+ }+ }++ if as_html+ tag.attributes(attributes)+ else+ attributes+ end+ end++ def block_styles(block, allowed_styles: :all)+ styles = {}++ styles['text-align'] = block.preferred_text_alignment if block.respond_to?(:preferred_text_alignment) && block.preferred_text_alignment.present?+ styles['width'] = "#{block.preferred_width_desktop}%" if block.respond_to?(:preferred_width_desktop) && block.preferred_width_desktop.present?+ if block.respond_to?(:preferred_container_alignment)+ styles['margin'] = case block.preferred_container_alignment+ when 'center'+ '0 auto'+ when 'right'+ '0 0 0 auto'+ else+ '0 auto 0 0'+ end+ end+ styles['color'] = if block.respond_to?(:preferred_text_color) && block.preferred_text_color.present?+ block.preferred_text_color+ else+ 'var(--section-color)'+ end++ styles['padding-top'] = "#{block.preferred_top_padding}px" if block.respond_to?(:preferred_top_padding) && block.preferred_top_padding.present?+ if block.respond_to?(:preferred_bottom_padding) && block.preferred_bottom_padding.present?+ styles['padding-bottom'] = "#{block.preferred_bottom_padding}px"+ end+ styles['text-transform'] = :uppercase if theme_setting('headings_uppercase') && block.type == 'heading'+ styles['background-color'] = if block.respond_to?(:preferred_background_color) && block.preferred_background_color.present?+ block.preferred_background_color+ else+ 'var(--section-background)'+ end++ if block.respond_to?(:preferred_button_background_color) && block.preferred_button_background_color.present?+ styles['--button-background-color'] = block.preferred_button_background_color+ end+ if block.respond_to?(:preferred_button_text_color) && block.preferred_button_text_color.present?+ styles['--button-text-color'] = block.preferred_button_text_color+ end++ styles = styles.compact_blank+ styles = styles.slice(*allowed_styles) if allowed_styles != :all++ styles.map { |k, v| "#{k}: #{v}" }.join(';')+ end++ def block_background_color_style(block)+ return nil unless block.respond_to?(:preferred_background_color) && block.preferred_background_color.present?++ "background-color: #{block.preferred_background_color};"+ end++ def block_css_classes(block)+ classes = []+ classes << "justify-#{block.preferred_justify}" if block.respond_to?(:preferred_justify) && block.preferred_justify.present?+ classes.join(',')+ end+ end+enddiff --git a/storefront/app/helpers/spree/turbo_helper.rb b/storefront/app/helpers/spree/turbo_helper.rbnew file mode 100644index 0000000000..d2ed9ca44c--- /dev/null+++ b/storefront/app/helpers/spree/turbo_helper.rb@@ -0,0 +1,13 @@+module Spree+ module TurboHelper+ def spree_turbo_update_flashes+ turbo_stream.update 'flash' do+ render 'spree/shared/flashes'+ end+ end++ def spree_turbo_update_cart(order = current_order)+ turbo_stream.update_all '.cart-counter', order.item_count.positive? ? order.item_count : ''+ end+ end+enddiff --git a/storefront/app/helpers/spree/turbo_stream_actions_helper.rb b/storefront/app/helpers/spree/turbo_stream_actions_helper.rbnew file mode 100644index 0000000000..7d9320edb5--- /dev/null+++ b/storefront/app/helpers/spree/turbo_stream_actions_helper.rb@@ -0,0 +1,13 @@+module Spree+ module TurboStreamActionsHelper+ def slideover_open(slideover_name, target)+ turbo_stream_action_tag "#{slideover_name}:open", target: target+ end++ def search_suggestions_close+ turbo_stream_action_tag 'search-suggestions:close'+ end++ ::Turbo::Streams::TagBuilder.prepend(self)+ end+enddiff --git a/storefront/app/helpers/spree/wishlist_helper.rb b/storefront/app/helpers/spree/wishlist_helper.rbnew file mode 100644index 0000000000..f17218987e--- /dev/null+++ b/storefront/app/helpers/spree/wishlist_helper.rb@@ -0,0 +1,7 @@+module Spree+ module WishlistHelper+ def current_wishlist+ @current_wishlist ||= try_spree_current_user&.default_wishlist_for_store(current_store)+ end+ end+enddiff --git a/storefront/app/views/layouts/spree/password.html.erb b/storefront/app/views/layouts/spree/password.html.erbnew file mode 100644index 0000000000..0388e8b235--- /dev/null+++ b/storefront/app/views/layouts/spree/password.html.erb@@ -0,0 +1,34 @@+<!doctype html>+<html lang="<%= I18n.locale %>">+ <head>+ <%= render 'spree/shared/head' %>+ <%= render 'spree/shared/custom_head' %>+ <%= current_store.storefront_custom_code_head&.html_safe %>+ </head>+ <body class="bg-background w-full text-text">+ <%= render_storefront_partials(:body_start_partials) %>+ <%= current_store.storefront_custom_code_body_start&.html_safe %>++ <%= turbo_frame_tag(:flash) do %>+ <%= render 'spree/shared/flashes' %>+ <% end unless page_builder_enabled? %>+ <%= yield %>+ <style>+ .page-contents {+ display: flex;+ flex-direction: column;+ min-height: 100vh;+ justify-content: space-between;+ }+ </style>++ <%= current_store.storefront_custom_code_body_end&.html_safe %>+ <%= render_storefront_partials(:body_end_partials) %>+ </body>+</html>++<% unless Rails.env.test? %>+ <template id="csrf_meta_tags">+ <%= csrf_meta_tags %>+ </template>+<% end %>diff --git a/storefront/app/views/layouts/spree/storefront.html.erb b/storefront/app/views/layouts/spree/storefront.html.erbnew file mode 100644index 0000000000..6e7b5fad21--- /dev/null+++ b/storefront/app/views/layouts/spree/storefront.html.erb@@ -0,0 +1,38 @@+<!doctype html>+<html lang="<%= I18n.locale %>">+ <head>+ <%= render 'spree/shared/head' %>+ <%= render 'spree/shared/custom_head' %>+ <%= render 'spree/shared/json_ld' %>+ <%= current_store.storefront_custom_code_head&.html_safe %>+ </head>+ <body class="bg-background w-full text-text <%= current_page&.slug %>-page <% if current_theme_preview.present? %>inside-page-builder<% end %>">+ <%= render_storefront_partials(:body_start_partials) %>+ <%= current_store.storefront_custom_code_body_start&.html_safe %>++ <% if theme_layout_sections.empty? %>+ <%= render template: 'errors/500' %>+ <% else %>+ <%= render_section(theme_layout_sections['announcement_bar']) if theme_layout_sections['announcement_bar'].present? %>+ <%= render_section(theme_layout_sections['header']) if theme_layout_sections['header'].present? %>++ <%= turbo_frame_tag :flash do %>+ <%= render('spree/shared/flashes') %>+ <% end %>++ <%= yield %>++ <%= render_section(theme_layout_sections['newsletter']) if theme_layout_sections['newsletter'].present? %>+ <%= render_section(theme_layout_sections['footer']) if theme_layout_sections['footer'].present? %>+ <% end %>++ <%= current_store.storefront_custom_code_body_end&.html_safe %>+ <%= render_storefront_partials(:body_end_partials) %>+ </body>+</html>++<% unless Rails.env.test? %>+ <template id="csrf_meta_tags">+ <%= csrf_meta_tags %>+ </template>+<% end %>diff --git a/storefront/app/views/spree/account/wished_items/create.turbo_stream.erb b/storefront/app/views/spree/account/wished_items/create.turbo_stream.erbnew file mode 100644index 0000000000..38b6de7e42--- /dev/null+++ b/storefront/app/views/spree/account/wished_items/create.turbo_stream.erb@@ -0,0 +1,8 @@+<% if flash[:error] %>+ <%= spree_turbo_update_flashes %>+<% end %>++<%= turbo_stream.update "wishlist-icon" do %>+ <%= javascript_tag "wishedVariantIds = #{(current_wishlist.variant_ids).to_json.html_safe};" %>+ <%= render 'spree/shared/wishlist_icon' %>+<% end %>diff --git a/storefront/app/views/spree/account/wished_items/destroy.turbo_stream.erb b/storefront/app/views/spree/account/wished_items/destroy.turbo_stream.erbnew file mode 100644index 0000000000..95c5da588a--- /dev/null+++ b/storefront/app/views/spree/account/wished_items/destroy.turbo_stream.erb@@ -0,0 +1,20 @@+<% if @wished_item.present? %>+ <%= turbo_stream.remove dom_id(@wished_item) %>+<% end %>++<% if current_wishlist.wished_items.none? %>+ <%= turbo_stream.replace 'wishlist' do %>+ <div class="lg:col-span-9 lg:col-start-4 mb-12 lg:mb-24" id="wishlist">+ <%= render 'spree/wishlists/no_wished_items' %>+ </div>+ <% end %>+<% end %>++<% if flash[:error] %>+ <%= spree_turbo_update_flashes %>+<% end %>++<%= turbo_stream.update "wishlist-icon" do %>+ <%= javascript_tag "wishedVariantIds = #{(current_wishlist.variant_ids).to_json.html_safe};" %>+ <%= render 'spree/shared/wishlist_icon' %>+<% end %>