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.

Convert sections to STI

Matthew Kennedyfdfd80e19f10
diff --git a/backend/app/assets/javascripts/spree/backend/cms/section.es6 b/backend/app/assets/javascripts/spree/backend/cms/section.es6
index 82b3759b62..a9e866b547 100644
--- a/backend/app/assets/javascripts/spree/backend/cms/section.es6
+++ b/backend/app/assets/javascripts/spree/backend/cms/section.es6
@@ -1,5 +1,5 @@
document.addEventListener('DOMContentLoaded', function() {
- const sectionKindSelector = $('#cms_section_kind').select2()
+ const sectionKindSelector = $('#cms_section_type').select2()
sectionKindSelector.on('change', function() {
const selectedValue = $(sectionKindSelector).val()
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 b3f6668fea..ad8d7999f1 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
@@ -5,7 +5,7 @@
<div class="d-flex align-items-center overflow-hidden w-100">
<div>
<h5 class="mb-0"><%= section.name %></h5>
- <small class="form-text text-muted mt-0">Type: <%= section.kind %></small>
+ <small class="form-text text-muted mt-0">Type: <%= section.type %></small>
</div>
<div class="ml-4 pl-4 v-seperator">
diff --git a/backend/app/views/spree/admin/cms_sections/_form.html.erb b/backend/app/views/spree/admin/cms_sections/_form.html.erb
index d55563ef13..aaa3230664 100644
--- a/backend/app/views/spree/admin/cms_sections/_form.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/_form.html.erb
@@ -15,10 +15,10 @@
<% end %>
</div>
<div class="col-12 col-md-6">
- <%= f.field_container :kind, class: ['form-group'] do %>
- <%= f.label :kind, Spree.t('admin.navigation.section_type') %>
- <%= f.select(:kind, @cms_section_types, {include_blank: false}) %>
- <%= f.error_message_on :kind %>
+ <%= f.field_container :type, class: ['form-group'] do %>
+ <%= f.label :type, Spree.t('admin.navigation.section_type') %>
+ <%= f.select(:type, @cms_section_types, {include_blank: false}) %>
+ <%= f.error_message_on :type %>
<% end %>
</div>
</div>
@@ -41,21 +41,21 @@
</div>
</div>
- <% if @cms_section.kind.present? %>
+ <% if @cms_section.type.present? %>
<div id="CmsSectionKind"
data-hook="admin_cms_section_form_fields"
- data-panel-kind="<%= @cms_section.kind %>">
+ data-panel-type="<%= @cms_section.type %>">
<div class="row">
<div class="col-12">
<div class="card mb-3">
<div class="card-header">
- <h5 class="mb-0"><%= Spree.t('admin.cms.settings_for', section_kind: @cms_section.kind) %></h5>
+ <h5 class="mb-0"><%#= Spree.t('admin.cms.settings_for', section_type: @cms_section.type) %></h5>
</div>
<div class="card-body">
- <% if @cms_section.kind.present? %>
+ <% if @cms_section.type.present? %>
<div class="row">
<div class="col-12">
- <%= render "spree/admin/cms_sections/types/#{@cms_section.kind.parameterize(separator: '_')}", f: f %>
+ <%= render "spree/admin/cms_sections/types/#{@cms_section.type.parameterize(separator: '_')}", f: f %>
</div>
</div>
<% end %>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_featured_atricle.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featured_atricle.html.erb
similarity index 100%
rename from backend/app/views/spree/admin/cms_sections/types/_featured_atricle.html.erb
rename to backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_featured_atricle.html.erb
diff --git a/backend/app/views/spree/admin/cms_sections/types/_hero.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
similarity index 100%
rename from backend/app/views/spree/admin/cms_sections/types/_hero.html.erb
rename to backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
diff --git a/backend/app/views/spree/admin/cms_sections/types/_promo.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb
similarity index 100%
rename from backend/app/views/spree/admin/cms_sections/types/_promo.html.erb
rename to backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb
diff --git a/backend/app/views/spree/admin/cms_sections/types/_text_block.html.erb b/backend/app/views/spree/admin/cms_sections/types/_text_block.html.erb
deleted file mode 100644
index 176d8f5f97..0000000000
--- a/backend/app/views/spree/admin/cms_sections/types/_text_block.html.erb
+++ /dev/null
@@ -1,16 +0,0 @@
-<%= f.field_container :content, class: ['form-group'] do %>
- <%= f.text_area :content, { rows: "20", class: 'form-control' } %>
- <%= f.error_message_on :content %>
-<% end %>
-
-<script type="text/javascript">
- tinymce.init({
- selector: "#cms_section_content",
- plugins: [
- "image table paste code",
- ],
- menubar: false,
- toolbar:
- "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code ",
- });
-</script>
diff --git a/core/app/models/spree/cms/sections/featured_article.rb b/core/app/models/spree/cms/sections/featured_article.rb
new file mode 100644
index 0000000000..ff91b94cc9
--- /dev/null
+++ b/core/app/models/spree/cms/sections/featured_article.rb
@@ -0,0 +1,4 @@
+module Spree::Cms::Sections
+ class FeaturedArticle < Spree::CmsSection
+ end
+end
diff --git a/core/app/models/spree/cms/sections/hero.rb b/core/app/models/spree/cms/sections/hero.rb
new file mode 100644
index 0000000000..2f8c3965e4
--- /dev/null
+++ b/core/app/models/spree/cms/sections/hero.rb
@@ -0,0 +1,4 @@
+module Spree::Cms::Sections
+ class Hero < Spree::CmsSection
+ end
+end
diff --git a/core/app/models/spree/cms/sections/promo.rb b/core/app/models/spree/cms/sections/promo.rb
new file mode 100644
index 0000000000..b1ad934d90
--- /dev/null
+++ b/core/app/models/spree/cms/sections/promo.rb
@@ -0,0 +1,4 @@
+module Spree::Cms::Sections
+ class Promo < Spree::CmsSection
+ end
+end
diff --git a/core/app/models/spree/cms_section.rb b/core/app/models/spree/cms_section.rb
index cb9af9fb66..fb10466dd8 100644
--- a/core/app/models/spree/cms_section.rb
+++ b/core/app/models/spree/cms_section.rb
@@ -13,7 +13,9 @@ module Spree
accepts_nested_attributes_for :icon, reject_if: :all_blank
SECTION_WIDTHS = ['Edge-to-Edge', 'Full', 'Half']
- SECTION_TYPES = ['Text Block', 'Hero', 'Promo', 'Featured Atricle']
+ SECTION_TYPES = ['Spree::Cms::Sections::Hero',
+ 'Spree::Cms::Sections::Promo',
+ 'Spree::Cms::Sections::Featured Atricle']
SECTION_LINKS_TO = ['Spree::Taxon', 'Spree::Product']
end
diff --git a/core/db/migrate/20210514204251_create_spree_cms_sections.rb b/core/db/migrate/20210514204251_create_spree_cms_sections.rb
index 1c8d371788..86fe4806b8 100644
--- a/core/db/migrate/20210514204251_create_spree_cms_sections.rb
+++ b/core/db/migrate/20210514204251_create_spree_cms_sections.rb
@@ -7,7 +7,7 @@ class CreateSpreeCmsSections < ActiveRecord::Migration[6.0]
t.column :button_text, :string
t.column :content, :text
t.column :width, :string
- t.column :kind, :string
+ t.column :type, :string
t.column :destination, :string
t.column :position, :integer
diff --git a/frontend/app/controllers/spree/cms_pages_controller.rb b/frontend/app/controllers/spree/cms_pages_controller.rb
index 80a3b90e4a..7918d9a458 100644
--- a/frontend/app/controllers/spree/cms_pages_controller.rb
+++ b/frontend/app/controllers/spree/cms_pages_controller.rb
@@ -6,10 +6,10 @@ module Spree
include Spree::CacheHelper
def show
- if @cms_page_x.viewable?
- @cms_page = @cms_page_x
+ if @page&.viewable?
+ @cms_page = @page
elsif spree_current_user&.admin?
- @cms_page = @cms_page_x
+ @cms_page = @page
@edit_mode = true
end
end
@@ -17,18 +17,18 @@ module Spree
private
def accurate_title
- if @cms_page_x
- @cms_page_x.seo_title
+ if @page
+ @page.seo_title
else
super
end
end
def load_cms_page
- @cms_page_x = Spree::CmsPage.
- by_store(current_store).
- by_locale(I18n.locale).
- friendly.find(params[:id])
+ @page = Spree::CmsPage.
+ by_store(current_store).
+ by_locale(I18n.locale).
+ friendly.find(params[:id])
end
end
end
diff --git a/frontend/app/controllers/spree/home_controller.rb b/frontend/app/controllers/spree/home_controller.rb
index 247d240e1a..2a2c0fd4f5 100644
--- a/frontend/app/controllers/spree/home_controller.rb
+++ b/frontend/app/controllers/spree/home_controller.rb
@@ -7,7 +7,7 @@ module Spree
respond_to :html
def index
- if @cms_home_page.viewable?
+ if @cms_home_page&.viewable?
@homepage = @cms_home_page
elsif spree_current_user&.admin?
@homepage = @cms_home_page
diff --git a/frontend/app/helpers/spree/cms_pages_helper.rb b/frontend/app/helpers/spree/cms_pages_helper.rb
index 17fd565dc0..aecde8aaf9 100644
--- a/frontend/app/helpers/spree/cms_pages_helper.rb
+++ b/frontend/app/helpers/spree/cms_pages_helper.rb
@@ -1,11 +1,10 @@
module Spree
module CmsPagesHelper
-
def simple_page?(page)
page.content.present? && !page.sections?
end
def build_section(section)
- preview_type = section.kind.parameterize(separator: '_')
+ preview_type = section.type.parameterize(separator: '_')
case section.width
when 'Half'
diff --git a/frontend/app/views/spree/shared/cms/sections/_featured_atricle.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featured_atricle.html.erb
similarity index 100%
rename from frontend/app/views/spree/shared/cms/sections/_featured_atricle.html.erb
rename to frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_featured_atricle.html.erb
diff --git a/frontend/app/views/spree/shared/cms/sections/_hero.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erb
similarity index 100%
rename from frontend/app/views/spree/shared/cms/sections/_hero.html.erb
rename to frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_hero.html.erb
diff --git a/frontend/app/views/spree/shared/cms/sections/_promo.html.erb b/frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erb
similarity index 100%
rename from frontend/app/views/spree/shared/cms/sections/_promo.html.erb
rename to frontend/app/views/spree/shared/cms/sections/_spree_cms_sections_promo.html.erb
diff --git a/frontend/app/views/spree/shared/cms/sections/_text_block.html.erb b/frontend/app/views/spree/shared/cms/sections/_text_block.html.erb
deleted file mode 100644
index bc0fa3b123..0000000000
--- a/frontend/app/views/spree/shared/cms/sections/_text_block.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<div class="<%= width %>">
- <%= raw section.content %>
-</div>