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 code

Matthew Kennedybb2d797ac55d
diff --git a/backend/app/helpers/spree/admin/base_helper.rb b/backend/app/helpers/spree/admin/base_helper.rb
index d3dc155bb6..250cd0cedb 100644
--- a/backend/app/helpers/spree/admin/base_helper.rb
+++ b/backend/app/helpers/spree/admin/base_helper.rb
@@ -200,16 +200,6 @@ module Spree
)
end
- def page_preview_link(page)
- return unless frontend_available?
-
- button_link_to(
- Spree.t(:preview_page),
- spree.page_url(page),
- class: 'btn-outline-secondary', icon: 'view.svg', id: 'admin_preview_product', target: :blank
- )
- end
-
def taxon_preview_link(taxon)
return unless frontend_available?
diff --git a/backend/app/helpers/spree/admin/cms_page_helper.rb b/backend/app/helpers/spree/admin/cms_page_helper.rb
index 4f83a27302..7e84bc6cf9 100644
--- a/backend/app/helpers/spree/admin/cms_page_helper.rb
+++ b/backend/app/helpers/spree/admin/cms_page_helper.rb
@@ -2,23 +2,49 @@ module Spree
module Admin
module CmsPageHelper
def build_page_section(section)
- case section.width
- when 'Half'
- css_width = 'col-6'
- when 'Full'
- css_width = 'col-12'
- when 'Edge-to-Edge'
- css_width = 'col-12 px-0 edge'
- end
+ css_width = case section.width
+ when 'Half'
+ 'col-6'
+ else
+ 'col-12'
+ end
+
+ boundary = case section.boundary
+ when 'Screen'
+ 'px-0 edge'
+ else
+ ''
+ end
- render 'spree/admin/cms_pages/section_template', section: section, width: css_width
+ render 'spree/admin/cms_pages/section_template',
+ section: section,
+ width: css_width,
+ boundary: boundary
+ end
+
+ def page_preview_link(page)
+ return unless frontend_available?
+
+ url = if page.homepage?
+ spree.root_url
+ else
+ spree.page_url(page.slug)
+ end
+
+ button_link_to(
+ Spree.t(:preview_page),
+ url,
+ class: 'btn-outline-secondary', icon: 'view.svg', id: 'admin_preview_product', target: :blank
+ )
end
def preview_url(page)
+ return unless frontend_available?
+
if page.homepage?
- '/'
+ spree.root_path
else
- Spree::Core::Engine.routes.url_helpers.page_path(page.slug)
+ spree.page_path(page.slug)
end
end
diff --git a/backend/app/views/spree/admin/cms_pages/_section_template.html.erb b/backend/app/views/spree/admin/cms_pages/_section_template.html.erb
index d4d4abea16..44a38112a4 100644
--- a/backend/app/views/spree/admin/cms_pages/_section_template.html.erb
+++ b/backend/app/views/spree/admin/cms_pages/_section_template.html.erb
@@ -1,4 +1,4 @@
-<div class="<%= width %> removeable" data-section-id="<%= section.id %>">
+<div class="<%= width %> <%= boundary %> removeable" data-section-id="<%= section.id %>">
<div class="row m-0 mb-1 pb-0 border bg-white">
<div class="col move-handle d-flex flex-nowrap pr-0">
diff --git a/core/app/models/spree/cms/sections/carousel.rb b/core/app/models/spree/cms/sections/carousel.rb
index c4af60e4a5..3b2f32f461 100644
--- a/core/app/models/spree/cms/sections/carousel.rb
+++ b/core/app/models/spree/cms/sections/carousel.rb
@@ -7,13 +7,14 @@ module Spree::Cms::Sections
end
def widths
- ['Edge-to-Edge']
+ ['Full']
end
private
def default_values
- self.width ||= 'Edge-to-Edge'
+ self.width ||= 'Full'
+ self.boundary ||= 'Screen'
self.linked_resource_type ||= 'Spree::Taxon'
end
end
diff --git a/frontend/app/assets/javascripts/spree/frontend.js b/frontend/app/assets/javascripts/spree/frontend.js
index 73a60d8a07..34f24075fb 100644
--- a/frontend/app/assets/javascripts/spree/frontend.js
+++ b/frontend/app/assets/javascripts/spree/frontend.js
@@ -31,6 +31,7 @@
//= require spree/frontend/views/spree/products/modal_carousel
//= require spree/frontend/views/spree/products/price_filters
//= require spree/frontend/views/spree/shared/carousel
+//= require spree/frontend/views/spree/shared/cms_sections
//= require spree/frontend/views/spree/shared/carousel/single
//= require spree/frontend/views/spree/shared/carousel/swipes
//= require spree/frontend/views/spree/shared/carousel/thumbnails
diff --git a/frontend/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js b/frontend/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js
index c2a04ae379..76677c3ae6 100644
--- a/frontend/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js
+++ b/frontend/app/assets/javascripts/spree/frontend/views/spree/home/product_carousels.js
@@ -23,13 +23,13 @@ Spree.loadCarousel = function (element, div) {
}
Spree.loadsCarouselElements = function () {
- $('div[data-product-carousel]').each(function (_index, element) { Spree.loadCarousel(element, this) })
+ $('div[data-product-carousel-taxon-id]').each(function (_index, element) { Spree.loadCarousel(element, this) })
}
document.addEventListener('turbolinks:load', function () {
- var homePage = $('body#home')
+ var carouselPresent = $('div[data-product-carousel-taxon-id]')
- if (homePage.length) {
+ if (carouselPresent.length) {
// load Carousels straight away if they are in the viewport
Spree.loadsCarouselElements()
diff --git a/frontend/app/assets/javascripts/spree/frontend/views/spree/shared/cms_sections.es6 b/frontend/app/assets/javascripts/spree/frontend/views/spree/shared/cms_sections.es6
new file mode 100644
index 0000000000..b5ffe65e87
--- /dev/null
+++ b/frontend/app/assets/javascripts/spree/frontend/views/spree/shared/cms_sections.es6
@@ -0,0 +1,19 @@
+// Fix for odd - even css targeting when user skips a half size section.
+document.addEventListener('turbolinks:load', function() {
+ const featurePageContent = document.getElementById('featurePageContent')
+
+ if (!featurePageContent) return
+
+ const halfWidthElements = featurePageContent.querySelectorAll('.cms_half_section')
+
+ halfWidthElements.forEach(function(elem) {
+ if (elem.nextElementSibling && !elem.nextElementSibling.classList.contains('cms_half_section')) {
+ if (elem.previousElementSibling && elem.previousElementSibling.classList.contains('cms_half_section')) return
+
+ const el = document.createElement('aside');
+ el.classList.add('col-6', 'cms_half_section', 'd-none')
+
+ elem.insertAdjacentElement('afterend', el);
+ }
+ })
+})
diff --git a/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss b/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss
index e73b3e7339..e7f7d1bf00 100644
--- a/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss
+++ b/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss
@@ -292,7 +292,6 @@
margin-right: -50vw;
}
-
aside {
.full-width {
width: calc(50vw - #{$grid-gutter-width / 2});
diff --git a/frontend/app/helpers/spree/cms_pages_helper.rb b/frontend/app/helpers/spree/cms_pages_helper.rb
index 0331666909..794623a67f 100644
--- a/frontend/app/helpers/spree/cms_pages_helper.rb
+++ b/frontend/app/helpers/spree/cms_pages_helper.rb
@@ -10,7 +10,7 @@ module Spree
case section.width
when 'Half'
element = 'aside'
- css_width = 'col-6'
+ css_width = 'col-6 cms_half_section'
when 'Full'
element = 'div'
css_width = 'col-12'
diff --git a/frontend/app/views/spree/cms_pages/show.html.erb b/frontend/app/views/spree/cms_pages/show.html.erb
index 377193e8bd..8d19495040 100644
--- a/frontend/app/views/spree/cms_pages/show.html.erb
+++ b/frontend/app/views/spree/cms_pages/show.html.erb
@@ -9,7 +9,7 @@
</div>
<% else %>
<div class="container">
- <div class="row">
+ <div id="featurePageContent" class="row">
<% @cms_page.cms_sections.each do |section| %>
<%= build_section(section) %>
<% end %>
diff --git a/frontend/app/views/spree/home/index.html.erb b/frontend/app/views/spree/home/index.html.erb
index 1214b7e9c2..56e57a5ae6 100644
--- a/frontend/app/views/spree/home/index.html.erb
+++ b/frontend/app/views/spree/home/index.html.erb
@@ -2,7 +2,7 @@
<% if @homepage %>
<div class="container">
- <div class="row">
+ <div id="featurePageContent" class="row">
<% @homepage.cms_sections.each do |section| %>
<%= build_section(section) %>
<% end %>
diff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb
index de1ad2303a..8283703800 100644
--- a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb
+++ b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_carousel.html.erb
@@ -1,5 +1,5 @@
-<div class="<%= width %>">
- <div class="<%= boundary %>">
- <div data-product-carousel data-product-carousel-taxon-id='<%= section.linked_resource.permalink %>' class="my-3"></div>
+<div class="col-12">
+ <div class="full-width">
+ <div data-product-carousel-taxon-id='<%= section.linked_resource.permalink %>' class="my-3"></div>
</div>
</div>