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
Improve code
Matthew Kennedybb2d797ac55d
diff --git a/backend/app/helpers/spree/admin/base_helper.rb b/backend/app/helpers/spree/admin/base_helper.rbindex 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.rbindex 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 Spreemodule Adminmodule CmsPageHelperdef 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+ )enddef preview_url(page)+ return unless frontend_available?+if page.homepage?- '/'+ spree.root_pathelse- Spree::Core::Engine.routes.url_helpers.page_path(page.slug)+ spree.page_path(page.slug)endenddiff --git a/backend/app/views/spree/admin/cms_pages/_section_template.html.erb b/backend/app/views/spree/admin/cms_pages/_section_template.html.erbindex 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.rbindex 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::Sectionsenddef widths- ['Edge-to-Edge']+ ['Full']endprivatedef default_values- self.width ||= 'Edge-to-Edge'+ self.width ||= 'Full'+ self.boundary ||= 'Screen'self.linked_resource_type ||= 'Spree::Taxon'endenddiff --git a/frontend/app/assets/javascripts/spree/frontend.js b/frontend/app/assets/javascripts/spree/frontend.jsindex 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/thumbnailsdiff --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.jsindex 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 viewportSpree.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.es6new file mode 100644index 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.scssindex 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.rbindex 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 Spreecase section.widthwhen '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.erbindex 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.erbindex 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.erbindex 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>