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
Update
Matthew Kennedy1746f1c47cfe
diff --git a/backend/app/assets/javascripts/spree/backend.js b/backend/app/assets/javascripts/spree/backend.jsindex cecf9afa58..0cfaf5deb5 100644--- a/backend/app/assets/javascripts/spree/backend.js+++ b/backend/app/assets/javascripts/spree/backend.js@@ -51,7 +51,7 @@//= require spree/backend/progress//= require spree/backend/promotions//= require spree/backend/menus/_index-//= require spree/backend/cms_pages/_index+//= require spree/backend/cms/_index//= require spree/backend/returns/expedited_exchanges_warning//= require spree/backend/returns/return_item_selection//= require spree/backend/shipmentsdiff --git a/backend/app/assets/javascripts/spree/backend/cms/_index.es6 b/backend/app/assets/javascripts/spree/backend/cms/_index.es6new file mode 100644index 0000000000..e62a28d019--- /dev/null+++ b/backend/app/assets/javascripts/spree/backend/cms/_index.es6@@ -0,0 +1,2 @@+//= require spree/backend/cms/page+//= require spree/backend/cms/sectiondiff --git a/backend/app/assets/javascripts/spree/backend/cms_pages/_index.es6 b/backend/app/assets/javascripts/spree/backend/cms/page.es6similarity index 99%rename from backend/app/assets/javascripts/spree/backend/cms_pages/_index.es6rename to backend/app/assets/javascripts/spree/backend/cms/page.es6index 60fe8480d3..f5cee19c29 100644--- a/backend/app/assets/javascripts/spree/backend/cms_pages/_index.es6+++ b/backend/app/assets/javascripts/spree/backend/cms/page.es6@@ -16,7 +16,6 @@ const el = document.getElementById('cmsPagesectionsArea')}})-function handleSectionReposition(evt) {const data = {section_id: parseInt(evt.item.dataset.sectionId, 10),diff --git a/backend/app/assets/javascripts/spree/backend/cms/section.es6 b/backend/app/assets/javascripts/spree/backend/cms/section.es6new file mode 100644index 0000000000..7d5e06be7d--- /dev/null+++ b/backend/app/assets/javascripts/spree/backend/cms/section.es6@@ -0,0 +1,27 @@+document.addEventListener('DOMContentLoaded', function() {+ $('#cms_section_linked_resource_type').select2()+ $('#cms_section_item_type').select2()++ $('#cms_section_linked_resource_type').on('change', function() {+ const selectedLinkTo = $('#cms_section_linked_resource_type').val()+ const message = document.getElementById('alertToClickUpdate')+ const activePanel = document.getElementById('linkResourcePanel')+ const panelType = activePanel.dataset.panelType++ if (selectedLinkTo === panelType) {+ activePanel.classList = ''+ activePanel.classList.add('d-block')++ message.classList = ''+ message.classList.add('d-none')+ } else {+ activePanel.classList = ''+ activePanel.classList.add('d-none')++ message.classList = ''+ message.classList.add('d-block')+ }+ });+++})diff --git a/backend/app/controllers/spree/admin/cms_sections_controller.rb b/backend/app/controllers/spree/admin/cms_sections_controller.rbindex 88ba950985..a85f92384f 100644--- a/backend/app/controllers/spree/admin/cms_sections_controller.rb+++ b/backend/app/controllers/spree/admin/cms_sections_controller.rb@@ -32,6 +32,7 @@ module Spreedef load_data@cms_section_widths = Spree::CmsSection::SECTION_WIDTHS@cms_section_types = Spree::CmsSection::SECTION_TYPES+ @cms_section_links_to = Spree::CmsSection::SECTION_LINKS_TOendendenddiff --git a/backend/app/views/spree/admin/cms_sections/_form.html.erb b/backend/app/views/spree/admin/cms_sections/_form.html.erbindex 82603f7ae7..a7b27f2646 100644--- a/backend/app/views/spree/admin/cms_sections/_form.html.erb+++ b/backend/app/views/spree/admin/cms_sections/_form.html.erb@@ -37,10 +37,23 @@</div></div>-<% if @cms_section.kind.present? %>-<div class="row">- <div class="col-12">- <%= render "spree/admin/cms_sections/types/#{@cms_section.kind.parameterize(separator: '_')}", f: f %>+<div data-hook="admin_cms_section_form_fields">+ <div class="row">+ <div class="col-12 col-md-6">+ <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>+ </div>+ <div class="card-body">+ <% if @cms_section.kind.present? %>+ <div class="row">+ <div class="col-12">+ <%= render "spree/admin/cms_sections/types/#{@cms_section.kind.parameterize(separator: '_')}", f: f %>+ </div>+ </div>+ <% end %>+ </div>+ </div>+ </div></div></div>-<% end %>diff --git a/backend/app/views/spree/admin/cms_sections/_link_inputx.html.erb b/backend/app/views/spree/admin/cms_sections/_link_inputx.html.erbnew file mode 100644index 0000000000..f8e7bae951--- /dev/null+++ b/backend/app/views/spree/admin/cms_sections/_link_inputx.html.erb@@ -0,0 +1,54 @@+<div id="linkResourcePanel" data-panel-type="<%= @cms_section.linked_resource_type %>">+<% resorce_holder = [] %>+<% id_holder = nil %>+<% name_holder = nil %>+<% active_id_holder = nil %>++<% if @cms_section.linked_resource_type == 'Spree::Taxon' %>+ <% label_text = Spree.t('taxon') %>++ <% if @cms_section.linked_resource %>+ <% resorce_holder = [@cms_section.linked_resource] %>+ <% id_holder = :id %>+ <% name_holder = :pretty_name %>+ <% active_id_holder = @cms_section.linked_resource.id %>+ <% end %>++ <script>+ document.addEventListener('DOMContentLoaded', function() {+ $('.autocomplete').select2Autocomplete({+ data_attrbute_name: 'taxons',+ placeholder: "<%= Spree.t('admin.navigation.seach_for_a_taxon') %>",+ allow_clear: true,+ apiUrl: Spree.routes.taxons_api_v2,+ return_attribute: 'pretty_name',+ })+ })+ </script>+<% elsif @cms_section.linked_resource_type == 'Spree::Product' %>+ <% label_text = Spree.t('product') %>+ <% if @cms_section.linked_resource %>+ <% resorce_holder = [@cms_section.linked_resource] %>+ <% id_holder = :id %>+ <% name_holder = :name %>+ <% active_id_holder = @cms_section.linked_resource.id %>+ <% end %>++ <script>+ document.addEventListener('DOMContentLoaded', function() {+ $('.autocomplete').select2Autocomplete({+ data_attrbute_name: 'products',+ placeholder: "<%= Spree.t('admin.navigation.seach_for_a_product') %>",+ allow_clear: true,+ apiUrl: Spree.routes.products_api_v2,+ })+ })+ </script>+<% end %>++<%= f.field_container :linked_resource_id, class: ['form-group'] do %>+ <%= f.label :linked_resource_id, label_text %>+ <%= f.select :linked_resource_id, options_from_collection_for_select(resorce_holder, id_holder, name_holder, active_id_holder), { include_blank: true }, class: 'autocomplete' %>+ <%= f.error_message_on :linked_resource_id %>+<% end %>+</div>diff --git a/backend/app/views/spree/admin/cms_sections/linked_resorce_forms.html.erb/_ptoduct.html.erb b/backend/app/views/spree/admin/cms_sections/linked_resorce_forms.html.erb/_ptoduct.html.erbnew file mode 100644index 0000000000..772e7b2e3a--- /dev/null+++ b/backend/app/views/spree/admin/cms_sections/linked_resorce_forms.html.erb/_ptoduct.html.erb@@ -0,0 +1 @@+_ptoduct.html.erbdiff --git a/backend/app/views/spree/admin/cms_sections/linked_resorce_forms.html.erb/_taxon.html.erb b/backend/app/views/spree/admin/cms_sections/linked_resorce_forms.html.erb/_taxon.html.erbnew file mode 100644index 0000000000..d210710427--- /dev/null+++ b/backend/app/views/spree/admin/cms_sections/linked_resorce_forms.html.erb/_taxon.html.erb@@ -0,0 +1 @@+_taxon.html.erbdiff --git a/backend/app/views/spree/admin/cms_sections/types/_hero.html.erb b/backend/app/views/spree/admin/cms_sections/types/_hero.html.erbindex 159ecf2efe..2711382f15 100644--- a/backend/app/views/spree/admin/cms_sections/types/_hero.html.erb+++ b/backend/app/views/spree/admin/cms_sections/types/_hero.html.erb@@ -1,3 +1,15 @@+<%= 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(:button_text) %>+ <%= f.text_field :subtitle, class: 'form-control' %>+ <%= f.error_message_on :subtitle %>+<% end %>+<% @cms_section.build_icon unless @cms_section.icon %><%= f.fields_for :icon do |icon_field| %><%= f.field_container :icon_attachment do %>@@ -21,3 +33,21 @@<% end %><% end %><% end %>++<%= 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}) %>+ <%= f.error_message_on :linked_resource_type %>+<% end %>++<%= render 'link_inputx', linked_resource_type: @cms_section.linked_resource_type, f: f %>++<div id="alertToClickUpdate" class="d-none">+ <div class="alert alert-warning mt-3">+ <% if %w[new create].include? controller.action_name %>+ <%= raw Spree.t('admin.navigation.click_create_to_load_new_link') %>+ <% else %>+ <%= raw Spree.t('admin.navigation.click_update_to_load_new_link') %>+ <% end %>+ </div>+</div>diff --git a/core/app/models/spree/cms_section.rb b/core/app/models/spree/cms_section.rbindex 5f6cf99bb2..9895d57df1 100644--- a/core/app/models/spree/cms_section.rb+++ b/core/app/models/spree/cms_section.rb@@ -3,6 +3,8 @@ module Spreeacts_as_list scope: :cms_pagebelongs_to :cms_page+ belongs_to :linked_resource, polymorphic: true+default_scope { order(position: :asc) }has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::Icon'@@ -10,5 +12,7 @@ module SpreeSECTION_WIDTHS = ['Full', 'Half']SECTION_TYPES = ['Text Block', 'Hero']++ SECTION_LINKS_TO = ['None', 'Spree::Taxon', 'Spree::Product']endenddiff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 498d9a8efe..4e4e695d3f 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -534,6 +534,7 @@ en:adjustments: Adjustmentsadmin:cms:+ settings_for: 'Available Options For %{section_kind}'page_sections: '%{page_name} Sections'page_sections_info: 'The area below represents your %{page_type} displayed in %{store}, add sections and drag them into position'tab:diff --git a/frontend/app/helpers/spree/cms_pages_helper.rb b/frontend/app/helpers/spree/cms_pages_helper.rbnew file mode 100644index 0000000000..52e8e5b10a--- /dev/null+++ b/frontend/app/helpers/spree/cms_pages_helper.rb@@ -0,0 +1,16 @@+module Spree+ module CmsPagesHelper+ def build_section(section)+ preview_type = section.kind.parameterize(separator: '_')++ case section.width+ when 'Full'+ css_width = 'col-12'+ when 'Half'+ css_width = 'col-6'+ end++ render "spree/cms_pages/sections/#{preview_type}", section: section, width: css_width+ end+ end+enddiff --git a/frontend/app/views/spree/cms_pages/sections/_hero.html.erb b/frontend/app/views/spree/cms_pages/sections/_hero.html.erbnew file mode 100644index 0000000000..14372075a5--- /dev/null+++ b/frontend/app/views/spree/cms_pages/sections/_hero.html.erb@@ -0,0 +1,14 @@+<div class="homepage-hero-image mb-3 position-relative">+ <% if section.icon.present? %>+ <%= image_tag main_app.url_for(section.icon.attachment) %>+ <% end %>++ <div class="hero-content">+ <div class="homepage-hero-image-text mb-2 mx-auto pb-3 pb-md-4">+ <%= section.title %>+ </div>+ <div>+ <%= link_to section.subtitle, spree.products_path, class: 'btn btn-primary spree-btn px-5' %>+ </div>+ </div>+</div>diff --git a/frontend/app/views/spree/cms_pages/sections/_text_block.html.erb b/frontend/app/views/spree/cms_pages/sections/_text_block.html.erbnew file mode 100644index 0000000000..a414f1cb53--- /dev/null+++ b/frontend/app/views/spree/cms_pages/sections/_text_block.html.erb@@ -0,0 +1 @@+<%= raw section.content %>diff --git a/frontend/app/views/spree/cms_pages/show.html.erb b/frontend/app/views/spree/cms_pages/show.html.erbindex a19038d015..1f1982dac0 100644--- a/frontend/app/views/spree/cms_pages/show.html.erb+++ b/frontend/app/views/spree/cms_pages/show.html.erb@@ -1,9 +1,13 @@+<% if @cms_page.content.present? && @cms_page.kind == 'Standard Page' %><div class="container">- <% if @cms_page.content.present? %>- <div class="row my-5">- <div class="col-12">- <%= @cms_page.content.html_safe %>- </div>+ <div class="row my-5">+ <div class="col-12">+ <%= @cms_page.content.html_safe %></div>- <% end %>+ </div></div>+<% else %>+ <% @cms_page.cms_sections.each do |section| %>+ <%= build_section(section) %>+ <% end %>+<% end %>