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.

Improve sections in front end views.

Matthew Kennedy07fd0d169702
diff --git a/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb b/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb
index ba48768189..d6c69f9378 100644
--- a/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb
+++ b/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb
@@ -12,7 +12,7 @@ module Spree
new_index = params[:new_position_idx].to_i + 1
if @moved_section && new_index
- @moved_section.insert_at(new_index)
+ @moved_section.set_list_position(new_index)
else
head :bad_request
end
diff --git a/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6 b/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6
index 26009eb4b6..d1a885d728 100644
--- a/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6
+++ b/backend/app/assets/javascripts/spree/backend/cms/live_preview.es6
@@ -1,5 +1,9 @@
document.addEventListener('DOMContentLoaded', function() {
- document.getElementById('LiveViewSwitcher').addEventListener('click', function(event) {
+ const LiveViewSwitcher = document.getElementById('LiveViewSwitcher')
+
+ if (!LiveViewSwitcher) return
+
+ LiveViewSwitcher.addEventListener('click', function(event) {
if (event.target && event.target.matches("input[type='radio']")) {
switchLiveViewClass(event.target.id)
}
diff --git a/backend/app/assets/javascripts/spree/backend/cms/section.es6 b/backend/app/assets/javascripts/spree/backend/cms/section.es6
index 10dad3b86a..513ba6d29c 100644
--- a/backend/app/assets/javascripts/spree/backend/cms/section.es6
+++ b/backend/app/assets/javascripts/spree/backend/cms/section.es6
@@ -5,6 +5,9 @@ document.addEventListener('DOMContentLoaded', function() {
const selectedValue = $(sectionKindSelector).val()
const message = document.getElementById('alertToClickUpdate')
const activeSectionKind = document.getElementById('CmsSectionType')
+
+ if (!activeSectionKind) return
+
const panelType = activeSectionKind.dataset.panelSectionType
if (selectedValue === panelType) {
diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_carousel.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_carousel.html.erb
index e71f5403f3..680fc9731a 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_carousel.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_carousel.html.erb
@@ -1,27 +1,6 @@
<div class="row">
- <div class="col-12">
- <%= f.field_container :title, class: ['form-group'] do %>
- <%= f.label :title, Spree.t(:title) %>
- <%= f.text_field :title, class: 'form-control' %>
- <%= f.error_message_on :title %>
- <% end %>
-
- <%= f.field_container :subtitle, class: ['form-group'] do %>
- <%= f.label :subtitle, Spree.t(:subtitle) %>
- <%= f.text_field :subtitle, class: 'form-control' %>
- <%= f.error_message_on :subtitle %>
- <% end %>
- </div>
- <div class="col-12"><hr></div>
- <div class="col-12 col-md-6">
- <%= f.field_container :linked_resource_type, class: ['form-group'] do %>
- <%= f.label :linked_resource_type, Spree.t('admin.navigation.link_to') %>
- <%= f.select(:linked_resource_type, @cms_section.links_to, {include_blank: false}, class: 'link_switcher') %>
- <%= f.error_message_on :linked_resource_type %>
- <% end %>
- </div>
- <div class="col-12 col-md-6">
+ <div class="col-12">
<%= render "spree/admin/shared/link_fields", resource: @cms_section, f: f %>
</div>
</div>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_categorybannersquare.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_categorybannersquare.html.erb
index accbe49dd5..99e45b77b5 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_categorybannersquare.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_categorybannersquare.html.erb
@@ -6,13 +6,6 @@
<%= f.error_message_on :title %>
<% end %>
- <%= f.field_container :subtitle, class: ['form-group'] do %>
- <%= f.label :subtitle, Spree.t(:subtitle) %>
- <%= f.text_field :subtitle, class: 'form-control' %>
- <%= f.error_message_on :subtitle %>
- <% end %>
- </div>
- <div class="col-12 col-md-6">
<%= f.field_container :upper_image, class: ['form-group'] do %>
<% if @cms_section.upper_image.attached? && @cms_section.upper_image.variable? %>
<%= image_tag main_app.url_for(@cms_section.upper_image.variant(resize: '244x104>')) %>
@@ -25,6 +18,13 @@
<%= f.error_message_on :upper_image %>
<% end %>
<% end %>
+ </div>
+ <div class="col-12 col-md-6">
+ <%= f.field_container :subtitle, class: ['form-group'] do %>
+ <%= f.label :subtitle, Spree.t(:title) %>
+ <%= f.text_field :subtitle, class: 'form-control' %>
+ <%= f.error_message_on :subtitle %>
+ <% end %>
<%= f.field_container :lower_image, class: ['form-group'] do %>
<% if @cms_section.lower_image.attached? && @cms_section.lower_image.variable? %>
diff --git a/core/app/models/spree/cms_page.rb b/core/app/models/spree/cms_page.rb
index 21885e1e1b..24127c7c5e 100644
--- a/core/app/models/spree/cms_page.rb
+++ b/core/app/models/spree/cms_page.rb
@@ -8,7 +8,7 @@ module Spree
friendly_id :slug, use: [:slugged, :finders, :history]
belongs_to :store, touch: true
- has_many :cms_sections
+ has_many :cms_sections, dependent: :destroy
has_many :menu_items, as: :linked_resource
before_validation :handle_slug
diff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featuredarticle.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featuredarticle.html.erb
index a31fd54da4..f965d7752a 100644
--- a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featuredarticle.html.erb
+++ b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featuredarticle.html.erb
@@ -2,12 +2,21 @@
<div class="<%= edge_to_edge %>">
<div class="homepage-fashion-trends-box mb-3">
<div class="text-center">
- <div class="homepage-fashion-trends-box-summer-text mb-1"><%= section.title %></div>
- <div class="homepage-fashion-trends-box-fashion-trends-text mb-2"><%= section.subtitle %></div>
+
+ <% if section.title.present? %>
+ <div class="homepage-fashion-trends-box-summer-text mb-1"><%= section.title %></div>
+ <% end %>
+
+ <% if section.subtitle.present? %>
+ <div class="homepage-fashion-trends-box-fashion-trends-text mb-2"><%= section.subtitle %></div>
+ <% end %>
+
<div class="homepage-fashion-trends-box-description-text text-center mb-3">
<%= raw section.content %>
</div>
- <%= link_to section.button_text, spree.nested_taxons_path('trending'), class: 'btn px-5 spree-btn btn-outline-primary' %>
+ <% if section.button_text.present? && section.link.present? %>
+ <%= link_to section.button_text, section.link, class: 'btn px-5 spree-btn btn-outline-primary' %>
+ <% end %>
</div>
</div>
</div>
diff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erb
index a6bbad7a5c..23e717b269 100644
--- a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erb
+++ b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erb
@@ -1,9 +1,40 @@
<div class="<%= width %>">
- <%= link_to spree.nested_taxons_path('streetstyle') do %>
+ <%= link_to section.link do %>
<div class="homepage-bottom-box text-center mb-3">
+
<% if section.icon.present? %>
- <%= image_tag main_app.url_for(section.icon.attachment) %>
- <% end %>
+ <!-- XS to MD -->
+ <div class="d-sm-none" style="--aspect-ratio:54/35;">
+ <img class="lazyload"
+ data-src="<%= main_app.url_for(section.icon.attachment.variant(resize: '768x320>')) %>"
+ data-srcset="<%= main_app.url_for(section.icon.attachment.variant(resize: '768x320>')) %>"
+ alt="<%= section.icon.alt %>">
+ </div>
+
+ <!-- SM to MD -->
+ <div class="d-none d-sm-block d-md-none" style="--aspect-ratio:54/35;">
+ <img class="lazyload"
+ data-src="<%= main_app.url_for(section.icon.attachment.variant(resize: '990x412>')) %>"
+ data-srcset="<%= main_app.url_for(section.icon.attachment.variant(resize: '990x412>')) %>"
+ alt="<%= section.icon.alt %>">
+ </div>
+
+ <!-- MD to LG -->
+ <div class="d-none d-md-block d-lg-none" style="--aspect-ratio:54/35;">
+ <img class="lazyload"
+ data-src="<%= main_app.url_for(section.icon.attachment.variant(resize: '540x350>')) %>"
+ data-srcset="<%= main_app.url_for(section.icon.attachment.variant(resize: '540x350>')) %>"
+ alt="<%= section.icon.alt %>">
+ </div>
+
+ <!-- XL UP -->
+ <div class="d-none d-lg-block" style="--aspect-ratio:54/35;">
+ <img class="lazyload"
+ data-src="<%= main_app.url_for(section.icon.attachment.variant(resize: '2400x1000>')) %>"
+ data-srcset="<%= main_app.url_for(section.icon.attachment.variant(resize: '2400x1000>')) %>"
+ alt="<%= section.icon.alt %>">
+ </div>
+ <% end %>
<div class="homepage-bottom-box-inner" role="img" aria-label="New Collection">
<div class="homepage-bottom-box-inner-small-text">