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.

Set defaults for each section.

Matthew Kennedy7bfe8c67567e
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 2766363858..990e08411c 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
@@ -47,7 +47,7 @@
<div class="col-12 col-md-6">
<%= 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}, class: 'link_switcher') %>
+ <%= f.select(:linked_resource_type, @cms_section.links_to, {include_blank: false}, class: 'link_switcher') %>
<%= f.error_message_on :linked_resource_type %>
<% end %>
</div>
diff --git a/core/app/models/spree/cms/sections/featured_article.rb b/core/app/models/spree/cms/sections/featured_article.rb
index e6738b21cc..a8f663675c 100644
--- a/core/app/models/spree/cms/sections/featured_article.rb
+++ b/core/app/models/spree/cms/sections/featured_article.rb
@@ -1,5 +1,7 @@
module Spree::Cms::Sections
class FeaturedArticle < Spree::CmsSection
+ after_initialize :default_values
+
def links_to
['Spree::Taxon', 'Spree::Product']
end
@@ -7,5 +9,12 @@ module Spree::Cms::Sections
def widths
['Edge-to-Edge', 'Full', 'Half']
end
+
+ private
+
+ def default_values
+ self.width ||= 'Edge-to-Edge'
+ self.linked_resource_type ||= 'Spree::Taxon'
+ end
end
end
diff --git a/core/app/models/spree/cms/sections/hero.rb b/core/app/models/spree/cms/sections/hero.rb
index 501f8cf6b1..23218c5947 100644
--- a/core/app/models/spree/cms/sections/hero.rb
+++ b/core/app/models/spree/cms/sections/hero.rb
@@ -17,6 +17,7 @@ module Spree::Cms::Sections
def default_values
self.width ||= 'Edge-to-Edge'
+ self.linked_resource_type ||= 'Spree::Taxon'
end
end
end
diff --git a/core/app/models/spree/cms/sections/promo.rb b/core/app/models/spree/cms/sections/promo.rb
index 28184232f9..343f26892c 100644
--- a/core/app/models/spree/cms/sections/promo.rb
+++ b/core/app/models/spree/cms/sections/promo.rb
@@ -1,5 +1,7 @@
module Spree::Cms::Sections
class Promo < Spree::CmsSection
+ after_initialize :default_values
+
has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::Icon'
accepts_nested_attributes_for :icon, reject_if: :all_blank
@@ -10,5 +12,12 @@ module Spree::Cms::Sections
def widths
['Half']
end
+
+ private
+
+ def default_values
+ self.width ||= 'Half'
+ self.linked_resource_type ||= 'Spree::Taxon'
+ end
end
end