Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Storefront: move more layout partials

Damian Legawiec3e5856b56471
diff --git a/storefront/app/views/spree/shared/_head.html.erb b/storefront/app/views/spree/shared/_head.html.erb
index 3cd33f2583..55cdb80d6b 100644
--- a/storefront/app/views/spree/shared/_head.html.erb
+++ b/storefront/app/views/spree/shared/_head.html.erb
@@ -17,7 +17,7 @@
<%= javascript_importmap_tags 'application-spree-storefront' %>
<%= javascript_tag "wishedVariantIds = #{(current_wishlist&.variant_ids&.map(&:to_s) || []).to_json.html_safe};" %>
-<%= stylesheet_link_tag "application.tailwind", defer: true, data: { turbo_track: 'reload' } %>
+<%= stylesheet_link_tag "tailwind", defer: true, data: { turbo_track: 'reload' } %>
<%= stylesheet_link_tag "storefront_page_builder", defer: true, data: { turbo_track: 'reload' } if page_builder_enabled? %>
<%= yield :head %>
diff --git a/storefront/app/views/themes/default/spree/page_sections/_header.html.erb b/storefront/app/views/themes/default/spree/page_sections/_header.html.erb
index 82cf259107..026c2cba7b 100644
--- a/storefront/app/views/themes/default/spree/page_sections/_header.html.erb
+++ b/storefront/app/views/themes/default/spree/page_sections/_header.html.erb
@@ -1,5 +1,5 @@
<% layout = section.preferred_layout %>
-<% show_account_pane = !try_spree_current_user && canonical_path != spree_login_path && canonical_path != spree_signup_path && canonical_path != spree_forgot_password_path %>
+<% show_account_pane = !try_spree_current_user && (defined?(spree_login_path) && canonical_path != spree_login_path) && (defined?(spree_signup_path) && canonical_path != spree_signup_path) && (defined?(spree_forgot_password_path) && canonical_path != spree_forgot_password_path) %>
<header
class='sticky has-[.currency-and-locale-modal:not(.hidden)]:relative top-0 z-50 has-[.currency-and-locale-modal:not(.hidden)]:z-[unset] header-<%= layout %>'
data-controller='header toggle-menu slideover <%= "slideover-account" if show_account_pane %>'
diff --git a/storefront/app/views/themes/default/spree/page_sections/nav/_mobile.html.erb b/storefront/app/views/themes/default/spree/page_sections/nav/_mobile.html.erb
index 51e9aca920..2df95f2178 100644
--- a/storefront/app/views/themes/default/spree/page_sections/nav/_mobile.html.erb
+++ b/storefront/app/views/themes/default/spree/page_sections/nav/_mobile.html.erb
@@ -86,8 +86,10 @@
<%= render 'spree/shared/icons/account' %>
<% end %>
- <%= link_to spree_logout_path, method: :delete, data: { turbo_method: :delete }, class: 'btn-secondary gap-2 flex justify-center items-center w-full mt-2' do %>
- <%= Spree.t(:sign_out) %>
+ <% if defined?(spree_logout_path) %>
+ <%= link_to spree_logout_path, method: :delete, data: { turbo_method: :delete }, class: 'btn-secondary gap-2 flex justify-center items-center w-full mt-2' do %>
+ <%= Spree.t(:sign_out) %>
+ <% end %>
<% end %>
<% else %>
<button
diff --git a/storefront/app/views/themes/default/spree/shared/_cart_pane.html.erb b/storefront/app/views/themes/default/spree/shared/_cart_pane.html.erb
new file mode 100644
index 0000000000..e6bc716396
--- /dev/null
+++ b/storefront/app/views/themes/default/spree/shared/_cart_pane.html.erb
@@ -0,0 +1,38 @@
+<!-- begin sidebar/slideover -->
+<div
+ id="cart-pane"
+ data-slideover-target='overlay'
+ class='fixed inset-0 flex flex-row-reverse z-50 transition-opacity hidden'
+>
+ <div class='fixed inset-0'>
+ <div data-action='click->slideover#toggle' class='absolute inset-0 bg-background opacity-75'></div>
+ </div>
+ <div
+ id='slideover-cart'
+ data-slideover-target='menu'
+ class='relative sidebar-pane flex-1 !flex flex-col w-full bg-background text-text md:border-l border-default transition ease-in-out duration-300 translate-x-full'
+ >
+ <div class='p-4 gap-4 flex-shrink-0 flex items-center justify-between border-b border-default z-50'>
+ <%= button_tag(
+ type: 'button',
+ data: { action: 'slideover#toggle' },
+ class: 'flex items-center justify-center rounded-full focus:outline-none focus:bg-background',
+ aria: { label: 'Close sidebar' }
+ ) do %>
+ <%= render 'spree/shared/icons/close' %>
+ <% end %>
+ <span class='text-xl font-medium uppercase leading-loose'><%= Spree.t(:cart) %></span>
+ <span class='relative block w-6'>
+ <%= render 'spree/shared/icons/cart', color: theme_setting('text_color') %>
+ <span class='cart-counter w-full text-[8px] font-extrabold absolute top-[10px] text-center'>
+ <%= current_order.item_count if current_order.present? && current_order.item_count.to_i > 0 %>
+ </span>
+ <span class='sr-only'><%= Spree.t(:items_in_cart) %>, <%= Spree.t(:view_bag) %></span>
+ </span>
+ </div>
+ <div class='flex-1 h-0 overflow-y-auto'>
+ <%= turbo_frame_tag :cart_contents, class: 'cart-contents', src: spree.cart_path, loading: :lazy %>
+ </div>
+ </div>
+</div>
+<!-- end sidebar/slideover -->
diff --git a/storefront/app/views/themes/default/spree/shared/_flash.html.erb b/storefront/app/views/themes/default/spree/shared/_flash.html.erb
new file mode 100644
index 0000000000..01ea403f1f
--- /dev/null
+++ b/storefront/app/views/themes/default/spree/shared/_flash.html.erb
@@ -0,0 +1,16 @@
+<% if for_template || (key.present? && value.present?) %>
+ <div class="pointer-events-none w-full">
+ <div data-controller="alert" data-alert-hide-class="translate-x-[500px] opacity-0" class="ease-in-out duration-500 w-full relative pointer-events-auto <%= tailwind_classes_for(key) %>">
+ <div class="p-2">
+ <p class="text-sm lg:text-base font-medium text-center uppercase text-text flash-message">
+ <%= value %>
+ </p>
+ <button data-action="alert#close" class="absolute top-2 right-2 h-[22px] lg:h-6">
+ <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
+ <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"/>
+ </svg>
+ </button>
+ </div>
+ </div>
+ </div>
+<% end %>
diff --git a/storefront/app/views/themes/default/spree/shared/_flashes.html.erb b/storefront/app/views/themes/default/spree/shared/_flashes.html.erb
new file mode 100644
index 0000000000..4a74c626bc
--- /dev/null
+++ b/storefront/app/views/themes/default/spree/shared/_flashes.html.erb
@@ -0,0 +1,10 @@
+<template id="flashMessage">
+ <%= render partial: 'spree/shared/flash', locals: { key: nil, value: nil, for_template: true } %>
+</template>
+<div id="flashes" class="fixed z-[9999] w-full top-0">
+ <% if flash.any? %>
+ <% flash.each do |key, value| %>
+ <%= render partial: 'spree/shared/flash', locals: { key: key, value: value, for_template: false } %>
+ <% end %>
+ <% end %>
+</div>
diff --git a/storefront/app/views/themes/default/spree/shared/_json_ld.html.erb b/storefront/app/views/themes/default/spree/shared/_json_ld.html.erb
new file mode 100644
index 0000000000..e9661c110f
--- /dev/null
+++ b/storefront/app/views/themes/default/spree/shared/_json_ld.html.erb
@@ -0,0 +1,32 @@
+<% cache spree_base_cache_scope.call(current_store) do %>
+ <script type="application/ld+json">
+ {
+ "@context": "https://schema.org",
+ "@type": "Organization",
+ "url": <%= current_store.formatted_url_or_custom_domain.to_json.html_safe %>,
+ "sameAs": <%= current_store.social_links.to_json.html_safe %>,
+ <% if current_store.logo && current_store.logo&.attached? && current_store.logo&.variable? %>
+ "logo": <%= main_app.cdn_image_url(current_store.logo.variant(spree_image_variant_options(resize_to_fill: [500, 500]))).to_json.html_safe %>,
+ <% end %>
+ "name": <%= current_store.name.to_json.html_safe %>,
+ "email": <%= current_store.customer_support_email.to_json.html_safe %>
+ }
+ </script>
+<% end %>
+
+<% if canonical_path.include?('search') %>
+ <% potential_action_target = "#{canonical_href(current_store.url_or_custom_domain)}?q={search_term_string}" %>
+ <script type="application/ld+json">
+ {
+ "@context": "https://schema.org",
+ "@type": "WebSite",
+ "name": <%= current_store.name.to_json.html_safe %>,
+ "potentialAction": {
+ "@type": "SearchAction",
+ "target": <%= potential_action_target.to_json.html_safe %>,
+ "query-input": "required name=search_term_string"
+ },
+ "url": <%= current_store.formatted_url_or_custom_domain.to_json.html_safe %>
+ }
+ </script>
+<% end %>
diff --git a/storefront/app/views/themes/default/spree/shared/_logo.html.erb b/storefront/app/views/themes/default/spree/shared/_logo.html.erb
new file mode 100644
index 0000000000..cc8b6af5ae
--- /dev/null
+++ b/storefront/app/views/themes/default/spree/shared/_logo.html.erb
@@ -0,0 +1,42 @@
+<% logo ||= current_store.logo %>
+<% height ||= 64 %>
+<% logo_css ||= '' %>
+
+<%= link_to spree.root_path, id: 'site-logo' do %>
+ <span class='sr-only'><%= current_store.name %></span>
+ <% if logo.present? && logo.attached? && logo.variable? %>
+ <% aspect_ratio = as_aspect_ratio(logo) %>
+ <% logo_style = "aspect-ratio: #{aspect_ratio};" %>
+
+ <% if aspect_ratio.to_f > 10 %>
+ <% mobile_class = "h-[16px]" %>
+ <% desktop_class = "md:h-[32px]" %>
+ <% elsif aspect_ratio.to_f > 5 %>
+ <% mobile_class = "h-[25px]" %>
+ <% desktop_class = "md:h-[32px]" %>
+ <% elsif aspect_ratio.to_f < 3 %>
+ <% mobile_class = "h-[32px]" %>
+ <% desktop_class = "md:h-[64px]" %>
+ <% else %>
+ <% mobile_class = "h-[32px]" %>
+ <% end %>
+
+ <% if defined?(height) && height > 0 %>
+ <% logo_style += "--desktop-height: #{height}px;" %>
+ <% cdn_height = height %>
+ <% desktop_class = "custom-desktop-height" %>
+ <% elsif aspect_ratio.to_f < 3 %>
+ <% cdn_height = 64 %>
+ <% else %>
+ <% cdn_height = 32 %>
+ <% end %>
+
+ <% img_class = "w-auto #{mobile_class} #{desktop_class} #{logo_css}" %>
+
+ <% variant_options = spree_image_variant_options(resize_to_fit: [nil, cdn_height * 3]) %>
+
+ <%= image_tag main_app.cdn_image_url(logo.variant(variant_options)), class: img_class, alt: current_store.name, style: logo_style, height: cdn_height %>
+ <% else %>
+ <h1 class='text-lg uppercase text-center'><%= current_store.name %></h1>
+ <% end %>
+<% end %>
diff --git a/storefront/app/views/themes/default/spree/shared/_search.html.erb b/storefront/app/views/themes/default/spree/shared/_search.html.erb
new file mode 100644
index 0000000000..5660388fa4
--- /dev/null
+++ b/storefront/app/views/themes/default/spree/shared/_search.html.erb
@@ -0,0 +1,32 @@
+<div id="search-suggestions" role="dialog" aria-modal="true">
+ <div class='w-full flex flex-col border-b border-default' data-controller="search-suggestions" data-show-class="h-screen min-h-screen" data-search-suggestions-url-value="<%= spree.search_suggestions_path %>">
+ <div class='hidden lg:flex justify-center w-full mt-4 mb-3' id="header-logo">
+ <%= render 'spree/shared/logo', logo: logo, height: logo_height %>
+ </div>
+ <%= form_with url: spree.search_path, method: :get, local: true do %>
+ <div class='page-container bg-background flex w-full my-2 lg:mb-3 animate-fadeIn'>
+ <%= button_tag class: 'items-center justify-center pr-4', type: :button, data: { action: "click->search-suggestions#hide touch->search-suggestions#hide" } do %>
+ <span class='sr-only'><%= Spree.t(:close) %></span>
+ <%= render 'spree/shared/icons/close', color: 'black' %>
+ <% end %>
+
+ <div class='relative mx-auto w-full md:w-1/2' data-controller='clear-input'>
+ <%= button_tag type: 'submit', class: 'absolute left-2 top-2' do %>
+ <%= render 'spree/shared/icons/search' %>
+ <% end %>
+
+ <%= text_field_tag :q, params[:q], class: 'p-2 lg:text-sm !leading-6 pl-10 !h-auto bg-accent w-full uppercase pr-14 focus:outline-none text-input', placeholder: Spree.t(:search), data: { search_suggestions_target: 'input', clear_input_target: 'input' } %>
+ <%= button_tag class: 'hidden text-sm font-semibold absolute top-2 right-2 uppercase h-6 tracking-widest', data: { clear_input_target: 'button', action: 'click->clear-input#clear touch->clear-input#clear click->search-suggestions#clear touch->search-suggestions#clear' } do %>
+ <%= Spree.t(:clear) %>
+ <% end %>
+ </div>
+ </div>
+ <% end %>
+ <div id="search-suggestions-content" class="flex-grow hidden" data-show-class="animate-fadeIn"></div>
+ </div>
+
+ <!-- rendering search flyover skeleton -->
+ <template id="loading">
+ <%= render 'spree/search/suggestions' %>
+ </template>
+</div>
diff --git a/storefront/spec/controllers/spree/wishlists_controller_spec.rb b/storefront/spec/controllers/spree/wishlists_controller_spec.rb
index 15f373941c..c6ea432d32 100644
--- a/storefront/spec/controllers/spree/wishlists_controller_spec.rb
+++ b/storefront/spec/controllers/spree/wishlists_controller_spec.rb
@@ -12,8 +12,6 @@ describe Spree::WishlistsController, type: :controller do
allow(controller).to receive(:spree_login_path).and_return('/login')
end
- render_views
-
describe '#show' do
context 'when wishlist id and token are provided' do
subject { get :show, params: { id: wishlist.id, token: wishlist.token } }