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.

Allow for edge-to-edge page sections when using half width items. Set dynamic path for page preview.

Matthew Kennedy3f0229e180db
diff --git a/backend/app/helpers/spree/admin/cms_page_helper.rb b/backend/app/helpers/spree/admin/cms_page_helper.rb
index ea4ca7fe91..4f83a27302 100644
--- a/backend/app/helpers/spree/admin/cms_page_helper.rb
+++ b/backend/app/helpers/spree/admin/cms_page_helper.rb
@@ -14,6 +14,14 @@ module Spree
render 'spree/admin/cms_pages/section_template', section: section, width: css_width
end
+ def preview_url(page)
+ if page.homepage?
+ '/'
+ else
+ Spree::Core::Engine.routes.url_helpers.page_path(page.slug)
+ end
+ end
+
def linkable_as_path(item)
item.parameterize(separator: '_')
end
diff --git a/backend/app/views/spree/admin/cms_pages/edit.html.erb b/backend/app/views/spree/admin/cms_pages/edit.html.erb
index df1015a7d3..10bf3b51b9 100644
--- a/backend/app/views/spree/admin/cms_pages/edit.html.erb
+++ b/backend/app/views/spree/admin/cms_pages/edit.html.erb
@@ -62,7 +62,7 @@
<div class="embed-responsive embed-responsive-4by3">
<iframe class="embed-responsive-item"
id="pageLivePreview"
- src="http://localhost:3000"
+ src="<%= preview_url(@cms_page) %>"
sandbox="allow-same-origin allow-forms allow-popups allow-scripts allow-modals">
</iframe>
</div>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featuredarticle.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featuredarticle.html.erb
index 1a45eb6305..1ea6682264 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featuredarticle.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featuredarticle.html.erb
@@ -18,11 +18,19 @@
<%= f.error_message_on :button_text %>
<% end %>
- <%= f.field_container :width, class: ['form-group'] do %>
- <%= f.label :width, Spree.t('admin.navigation.width') %>
- <%= f.select(:width, @cms_section.widths, {include_blank: false}, class: 'select2') %>
- <%= f.error_message_on :width %>
- <% end %>
+ <div class="row">
+ <%= f.field_container :width, class: ['form-group col-6'] do %>
+ <%= f.label :width, Spree.t('admin.navigation.width') %>
+ <%= f.select(:width, @cms_section.widths, {include_blank: false}, class: 'select2') %>
+ <%= f.error_message_on :width %>
+ <% end %>
+
+ <%= f.field_container :boundary, class: ['form-group col-6'] do %>
+ <%= f.label :boundary, Spree.t('admin.navigation.boundary') %>
+ <%= f.select(:boundary, @cms_section.boundaries, {include_blank: false}, class: 'select2') %>
+ <%= f.error_message_on :boundary %>
+ <% end %>
+ </div>
</div>
<div class="col-12 col-md-8">
<%= f.field_container :content, class: ['form-group'] do %>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
index 616eb88871..bf1ff9a226 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
@@ -6,17 +6,17 @@
<%= f.error_message_on :title %>
<% end %>
- <%= f.field_container :width, class: ['form-group'] do %>
- <%= f.label :width, Spree.t('admin.navigation.width') %>
- <%= f.select(:width, @cms_section.widths, {include_blank: false}, class: 'select2') %>
- <%= f.error_message_on :width %>
- <% end %>
-
<%= f.field_container :button_text, class: ['form-group'] do %>
<%= f.label :button_text, Spree.t(:button_text) %>
<%= f.text_field :button_text, class: 'form-control' %>
<%= f.error_message_on :button_text %>
<% end %>
+
+ <%= f.field_container :boundary, class: ['form-group'] do %>
+ <%= f.label :boundary, Spree.t('admin.navigation.boundary') %>
+ <%= f.select(:boundary, @cms_section.boundaries, {include_blank: false}, class: 'select2') %>
+ <%= f.error_message_on :boundary %>
+ <% end %>
</div>
<div class="col-12 col-md-6">
<% @cms_section.build_icon unless @cms_section.icon %>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb
index 990e08411c..eb9aea83b9 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb
@@ -12,10 +12,10 @@
<%= f.error_message_on :subtitle %>
<% end %>
- <%= f.field_container :width, class: ['form-group'] do %>
- <%= f.label :width, Spree.t('admin.navigation.width') %>
- <%= f.select(:width, @cms_section.widths, {include_blank: false}, class: 'select2') %>
- <%= f.error_message_on :width %>
+ <%= f.field_container :boundary, class: ['form-group'] do %>
+ <%= f.label :boundary, Spree.t('admin.navigation.boundary') %>
+ <%= f.select(:boundary, @cms_section.boundaries, {include_blank: false}, class: 'select2') %>
+ <%= f.error_message_on :boundary %>
<% end %>
</div>
<div class="col-12 col-md-6">
diff --git a/core/app/models/spree/cms/pages/homepage.rb b/core/app/models/spree/cms/pages/homepage.rb
index 784ae1f3d4..e3fd0a4ea4 100644
--- a/core/app/models/spree/cms/pages/homepage.rb
+++ b/core/app/models/spree/cms/pages/homepage.rb
@@ -1,5 +1,6 @@
module Spree::Cms::Pages
class Homepage < Spree::CmsPage
+ before_save :empty_slug
validates :type, uniqueness: { scope: [:store, :locale] }
def sections?
@@ -8,7 +9,7 @@ module Spree::Cms::Pages
private
- def handle_slug
+ def empty_slug
self.slug = nil
end
end
diff --git a/core/app/models/spree/cms/sections/featured_article.rb b/core/app/models/spree/cms/sections/featured_article.rb
index a8f663675c..6f3ca9f25b 100644
--- a/core/app/models/spree/cms/sections/featured_article.rb
+++ b/core/app/models/spree/cms/sections/featured_article.rb
@@ -7,13 +7,14 @@ module Spree::Cms::Sections
end
def widths
- ['Edge-to-Edge', 'Full', 'Half']
+ ['Full', 'Half']
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/core/app/models/spree/cms/sections/hero.rb b/core/app/models/spree/cms/sections/hero.rb
index 23218c5947..f9809038a9 100644
--- a/core/app/models/spree/cms/sections/hero.rb
+++ b/core/app/models/spree/cms/sections/hero.rb
@@ -10,13 +10,14 @@ module Spree::Cms::Sections
end
def widths
- ['Edge-to-Edge', 'Full']
+ ['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/core/app/models/spree/cms/sections/promo.rb b/core/app/models/spree/cms/sections/promo.rb
index 343f26892c..a6e2a54d73 100644
--- a/core/app/models/spree/cms/sections/promo.rb
+++ b/core/app/models/spree/cms/sections/promo.rb
@@ -9,6 +9,8 @@ module Spree::Cms::Sections
['Spree::Taxon', 'Spree::Product']
end
+ # Overide this per section type
+
def widths
['Half']
end
@@ -17,6 +19,7 @@ module Spree::Cms::Sections
def default_values
self.width ||= 'Half'
+ self.boundary ||= 'Container'
self.linked_resource_type ||= 'Spree::Taxon'
end
end
diff --git a/core/app/models/spree/cms_section.rb b/core/app/models/spree/cms_section.rb
index 20caea79e6..6a23af6bd0 100644
--- a/core/app/models/spree/cms_section.rb
+++ b/core/app/models/spree/cms_section.rb
@@ -16,12 +16,19 @@ module Spree
'Spree::Cms::Sections::CategoryBannerSquare',
'Spree::Cms::Sections::CategoryBannerTall']
+ # Overide this per section type
def links_to
[]
end
+ # Overide this per section type
+ def boundaries
+ ['Container', 'Screen']
+ end
+
+ # Overide this per section type
def widths
- []
+ ['Full', 'Half']
end
end
end
diff --git a/core/db/migrate/20210512191732_create_spree_cms_pages.rb b/core/db/migrate/20210512191732_create_spree_cms_pages.rb
index 117b13b385..c363612f0c 100644
--- a/core/db/migrate/20210512191732_create_spree_cms_pages.rb
+++ b/core/db/migrate/20210512191732_create_spree_cms_pages.rb
@@ -1,4 +1,4 @@
-class CreateSpreeCmsPages < ActiveRecord::Migration[6.0]
+class CreateSpreeCmsPages < ActiveRecord::Migration[5.2]
def change
create_table :spree_cms_pages do |t|
t.column :title, :string, null: false
diff --git a/core/db/migrate/20210514204251_create_spree_cms_sections.rb b/core/db/migrate/20210514204251_create_spree_cms_sections.rb
index 86fe4806b8..db500b9451 100644
--- a/core/db/migrate/20210514204251_create_spree_cms_sections.rb
+++ b/core/db/migrate/20210514204251_create_spree_cms_sections.rb
@@ -1,4 +1,4 @@
-class CreateSpreeCmsSections < ActiveRecord::Migration[6.0]
+class CreateSpreeCmsSections < ActiveRecord::Migration[5.2]
def change
create_table :spree_cms_sections do |t|
t.column :name, :string, null: false
@@ -7,6 +7,8 @@ class CreateSpreeCmsSections < ActiveRecord::Migration[6.0]
t.column :button_text, :string
t.column :content, :text
t.column :width, :string
+ t.column :width_small, :string
+ t.column :boundary, :string
t.column :type, :string
t.column :destination, :string
t.column :position, :integer
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 416e7116fc..e73b3e7339 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
@@ -133,7 +133,7 @@
&-fashion-trends-box {
background: $secondary-background;
color: $secondary-font-color;
- padding: 30px 0px;
+ padding: 30px 15px;
@include media-breakpoint-up(md) {
padding: 60px 0px;
@@ -178,13 +178,12 @@
color: $font-color;
margin: auto;
font-size: font-px-to-rem(12px);
- width: 283px;
+ max-width: 283px;
@include media-breakpoint-up(md) {
font-size: font-px-to-rem(16px);
width: 90%;
max-width: 608px;
-
}
}
.spree-btn {
@@ -192,58 +191,35 @@
border: solid 2px theme-color('primary');
font-size: font-px-to-rem(12px);
font-weight: bold;
+ max-width: 100%;
@include media-breakpoint-up(md) {
font-size: font-px-to-rem(22px);
- width: 400px;
- padding-top: 0.7rem;
}
@include media-breakpoint-up(lg) {
font-size: font-px-to-rem(20px);
- width: 497.2px;
}
}
}
}
&-bottom-box {
- background: $secondary-background;
- color: $secondary-font-color;
- display: flex;
- justify-content: center;
- flex-direction: column;
- text-align: center;
- height: 168px;
- overflow: hidden;
-
img {
width: 100%;
object-fit: cover;
}
- @include media-breakpoint-up(md) {
- height: 363px;
- }
- @include media-breakpoint-up(lg) {
- height: 350px;
- }
-
&-inner {
background: $primary-background;
margin: auto;
- padding: 10px 30px;
position: absolute;
- width: 70%;
- left: 15%;
-
- @include media-breakpoint-up(md) {
- padding: 30px 100px;
- }
+ max-height: 70%;
+ min-width: 60%;
+ max-width: 80%;
&-small-text {
font-weight: 500;
line-height: 0.9;
letter-spacing: 0.25px;
- text-align: center;
color: theme-color('primary');
font-size: font-px-to-rem(10px);
@@ -259,9 +235,12 @@
font-weight: 600;
line-height: 1.2;
letter-spacing: 0.38px;
- text-align: center;
color: $font-color;
- font-size: font-px-to-rem(15px);
+ font-size: font-px-to-rem(14px);
+
+ @include media-breakpoint-up(sm) {
+ font-size: font-px-to-rem(22px);
+ }
@include media-breakpoint-up(md) {
font-size: font-px-to-rem(27px);
@@ -312,3 +291,26 @@
margin-left: -50vw;
margin-right: -50vw;
}
+
+
+aside {
+ .full-width {
+ width: calc(50vw - #{$grid-gutter-width / 2});
+ position: relative;
+ left: 100%;
+ right: 100%;
+ margin-left: calc(-50vw + #{$grid-gutter-width / 2});
+ margin-right: 0;
+ }
+
+ &:nth-of-type(even) {
+ .full-width {
+ width: calc(50vw - #{$grid-gutter-width / 2});
+ position: relative;
+ left: 0;
+ right: 100%;
+ margin-left: 0vw;
+ margin-right: 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 9589670c84..0331666909 100644
--- a/frontend/app/helpers/spree/cms_pages_helper.rb
+++ b/frontend/app/helpers/spree/cms_pages_helper.rb
@@ -9,17 +9,27 @@ module Spree
case section.width
when 'Half'
- edge_to_edge = ''
+ element = 'aside'
css_width = 'col-6'
when 'Full'
- edge_to_edge = ''
- css_width = 'col-12'
- when 'Edge-to-Edge'
- edge_to_edge = 'full-width'
+ element = 'div'
css_width = 'col-12'
+ else
+ element = 'div'
+ css_width = ''
end
- render "spree/shared/cms/sections/#{preview_type}", section: section, width: css_width, edge_to_edge: edge_to_edge
+ boundary = case section.boundary
+ when 'Screen'
+ 'full-width'
+ else
+ ''
+ end
+
+ render "spree/shared/cms/sections/#{preview_type}", section: section,
+ width: css_width,
+ boundary: boundary,
+ element: element
end
end
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 e6c87f8c28..de1ad2303a 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="<%= edge_to_edge %>">
+ <div class="<%= boundary %>">
<div data-product-carousel data-product-carousel-taxon-id='<%= section.linked_resource.permalink %>' class="my-3"></div>
</div>
</div>
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 f965d7752a..8df7c62806 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
@@ -1,5 +1,5 @@
-<div class="<%= width %>">
- <div class="<%= edge_to_edge %>">
+<<%= element %> class="<%= width %>">
+ <div class="<%= boundary %>">
<div class="homepage-fashion-trends-box mb-3">
<div class="text-center">
@@ -15,9 +15,9 @@
<%= raw section.content %>
</div>
<% if section.button_text.present? && section.link.present? %>
- <%= link_to section.button_text, section.link, class: 'btn px-5 spree-btn btn-outline-primary' %>
+ <%= link_to section.button_text, section.link, class: 'btn text-center spree-btn btn-outline-primary' %>
<% end %>
</div>
</div>
</div>
-</div>
+</<%= element %>>
diff --git a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erb
index 45d82101c5..bc4efb542f 100644
--- a/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erb
+++ b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erb
@@ -1,5 +1,5 @@
<div class="<%= width %>">
- <div class="<%= edge_to_edge %>">
+ <div class="<%= boundary %>">
<div class="homepage-hero-image mb-3 position-relative p-0">
<% if section.icon.present? %>
<!-- XS to MD -->
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 23e717b269..ad59355839 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,49 +1,44 @@
-<div class="<%= width %>">
- <%= link_to section.link do %>
- <div class="homepage-bottom-box text-center mb-3">
+<aside class="<%= width %>">
+ <div class="<%= boundary %>">
+ <%= link_to section.link do %>
+ <div class="d-flex
+ align-items-center
+ justify-content-center
+ bg-light text-center
+ mb-3
+ overflow-hidden
+ homepage-bottom-box"
+ style="--aspect-ratio:54/35;">
- <% if section.icon.present? %>
- <!-- 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>
+ <% if section.icon.present? %>
+ <!-- XS to MD -->
+ <img class="d-md-none lazyload"
+ data-src="<%= main_app.url_for(section.icon.attachment.variant(resize: '387x250>')) %>"
+ data-srcset="<%= main_app.url_for(section.icon.attachment.variant(resize: '387x250>')) %>"
+ alt="<%= section.icon.alt %>">
- <!-- 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>
+ <!-- MD to XL -->
+ <img class="d-none d-md-block d-xl-none lazyload"
+ data-src="<%= main_app.url_for(section.icon.attachment.variant(resize: '734x476>')) %>"
+ data-srcset="<%= main_app.url_for(section.icon.attachment.variant(resize: '734x476>')) %>"
+ alt="<%= section.icon.alt %>">
- <!-- 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 %>
+ <!-- XL UP -->
+ <img class="d-none d-xl-block lazyload"
+ data-src="<%= main_app.url_for(section.icon.attachment.variant(resize: '1468x952>')) %>"
+ data-srcset="<%= main_app.url_for(section.icon.attachment.variant(resize: '1468x952>')) %>"
+ alt="<%= section.icon.alt %>">
+ <% end %>
- <div class="homepage-bottom-box-inner" role="img" aria-label="New Collection">
- <div class="homepage-bottom-box-inner-small-text">
- <%= section.title %>
- </div>
- <div class="homepage-bottom-box-inner-big-text">
- <%= section.subtitle %>
+ <div class="homepage-bottom-box-inner p-1 p-sm-2 p-md-3 p-lg-5" role="img" aria-label="New Collection">
+ <div class="homepage-bottom-box-inner-small-text">
+ <%= section.title %>
+ </div>
+ <div class="homepage-bottom-box-inner-big-text">
+ <%= section.subtitle %>
+ </div>
</div>
</div>
- </div>
- <% end %>
-</div>
+ <% end %>
+ </div>
+</aside>