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.

Add ability to extend/add new CMS sections types (#11694)

Damian Legawiecc89f3ec36cdd
diff --git a/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb b/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb
index 34e7c83b49..c1429f0e94 100644
--- a/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb
+++ b/api/app/controllers/spree/api/v2/platform/cms_sections_controller.rb
@@ -12,7 +12,7 @@ module Spree
def spree_permitted_attributes
stored_attributes = []
- Spree::CmsSection::TYPES.each do |type|
+ Rails.application.config.spree.cms.sections.map(&:to_s).each do |type|
type.constantize.stored_attributes.each do |_name, values|
values.each do |value|
stored_attributes << value
diff --git a/core/app/models/spree/cms_section.rb b/core/app/models/spree/cms_section.rb
index ed359d7087..10b7749ff6 100644
--- a/core/app/models/spree/cms_section.rb
+++ b/core/app/models/spree/cms_section.rb
@@ -33,13 +33,6 @@ module Spree
LINKED_RESOURCE_TYPE = []
- TYPES = ['Spree::Cms::Sections::HeroImage',
- 'Spree::Cms::Sections::FeaturedArticle',
- 'Spree::Cms::Sections::ProductCarousel',
- 'Spree::Cms::Sections::ImageGallery',
- 'Spree::Cms::Sections::SideBySideImages',
- 'Spree::Cms::Sections::RichTextContent']
-
def boundaries
['Container', 'Screen']
end
diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb
index 087ef62c44..bd8a99ba6b 100644
--- a/core/lib/spree/core/engine.rb
+++ b/core/lib/spree/core/engine.rb
@@ -11,9 +11,11 @@ module Spree
:adjusters,
:stock_splitters,
:promotions,
+ :cms,
:line_item_comparison_hooks)
SpreeCalculators = Struct.new(:shipping_methods, :tax_rates, :promotion_actions_create_adjustments, :promotion_actions_create_item_adjustments)
PromoEnvironment = Struct.new(:rules, :actions)
+ CmsEnvironment = Struct.new(:sections)
isolate_namespace Spree
engine_name 'spree'
@@ -121,6 +123,16 @@ module Spree
Promotion::Actions::CreateLineItems,
Promotion::Actions::FreeShipping
]
+
+ Rails.application.config.spree.cms = CmsEnvironment.new
+ Rails.application.config.spree.cms.sections = [
+ Spree::Cms::Sections::HeroImage,
+ Spree::Cms::Sections::FeaturedArticle,
+ Spree::Cms::Sections::ProductCarousel,
+ Spree::Cms::Sections::ImageGallery,
+ Spree::Cms::Sections::SideBySideImages,
+ Spree::Cms::Sections::RichTextContent
+ ]
end
initializer 'spree.promo.register.promotions.actions' do |app|