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
Allow more options for linking on promotions.
Matthew Kennedyaf53ee439635
diff --git a/backend/app/assets/javascripts/spree/backend/cms/links.es6 b/backend/app/assets/javascripts/spree/backend/cms/links.es6index 6b7ec8f475..4112aba925 100644--- a/backend/app/assets/javascripts/spree/backend/cms/links.es6+++ b/backend/app/assets/javascripts/spree/backend/cms/links.es6@@ -2,23 +2,24 @@ document.addEventListener('DOMContentLoaded', function() {const linkSwitcher = $('.link_switcher').select2()linkSwitcher.on('change', function() {- const selectedLinkToValue = $(linkSwitcher).val()- const message = document.getElementById('linkClickUpdate')- const activePanel = document.querySelector('[data-panel-type]')+ const selectedLinkToValue = $(this).val()+ const linkSwitcherTarget = this.dataset.targetField || 'menu_item_link'+ const activePanel = document.querySelector(`div[data-panel-id='${linkSwitcherTarget}']`)+ const messagePanel = document.querySelector(`div[data-target-message-pannel='${linkSwitcherTarget}']`)const panelType = activePanel.dataset.panelTypeif (selectedLinkToValue === panelType) {activePanel.classList = ''activePanel.classList.add('d-block')- message.classList = ''- message.classList.add('d-none')+ messagePanel.classList = ''+ messagePanel.classList.add('d-none')} else {activePanel.classList = ''activePanel.classList.add('d-none')- message.classList = ''- message.classList.add('d-block')+ messagePanel.classList = ''+ messagePanel.classList.add('d-block')}})})diff --git a/backend/app/views/spree/admin/cms_pages/index.html.erb b/backend/app/views/spree/admin/cms_pages/index.html.erbindex 572b80a366..d9bb97461e 100644--- a/backend/app/views/spree/admin/cms_pages/index.html.erb+++ b/backend/app/views/spree/admin/cms_pages/index.html.erb@@ -88,6 +88,7 @@</tbody></table></div>+<%= render 'spree/admin/shared/index_table_options', collection: @cms_pages, simple: true %><% else %><div class="alert alert-info no-objects-found"><%= raw Spree.t('admin.cms.you_have_no_pages') %>diff --git a/backend/app/views/spree/admin/cms_sections/types/_side_by_side_promotion.html.erb b/backend/app/views/spree/admin/cms_sections/types/_side_by_side_promotion.html.erbindex 2550606b0e..af4e70fa92 100644--- a/backend/app/views/spree/admin/cms_sections/types/_side_by_side_promotion.html.erb+++ b/backend/app/views/spree/admin/cms_sections/types/_side_by_side_promotion.html.erb@@ -1,7 +1,7 @@<div class="row pb-0"><div class="col-12 col-md-6 mb-3"><div class="card p-3">- <h5 class="border-bottom"><%= Spree.t('admin.cms.three_taxon_block.section_one') %></h5>+ <h5 class="border-bottom"><%= Spree.t('admin.cms.side_by_side.left_image') %></h5><%= f.field_container :image_one, class: ['form-group'] do %><% if @cms_section.image_one.attached? && @cms_section.image_one.variable? %><figure class="admin-img-holder">@@ -36,7 +36,8 @@spree_humanize_dropdown_values('Spree::Cms::Sections::SideBySidePromotion',{ const: 'LINKED_RESOURCE_TYPE' }),{ include_blank: false },- class: 'link_switcher') %>+ class: 'link_switcher',+ data: { target_field: :link_one}) %><%= f.error_message_on :link_type_one %><% end %><%= render "spree/admin/shared/cms/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_one, save_to: :link_one, f: f %>@@ -47,7 +48,7 @@<div class="col-12 col-md-6 mb-3"><div class="card p-3">- <h5 class="border-bottom"><%= Spree.t('admin.cms.three_taxon_block.section_two') %></h5>+ <h5 class="border-bottom"><%= Spree.t('admin.cms.side_by_side.right_image') %></h5><%= f.field_container :image_two, class: ['form-group'] do %><% if @cms_section.image_two.attached? && @cms_section.image_two.variable? %><figure class="admin-img-holder">@@ -82,7 +83,8 @@spree_humanize_dropdown_values('Spree::Cms::Sections::SideBySidePromotion',{ const: 'LINKED_RESOURCE_TYPE' }),{ include_blank: false },- class: 'link_switcher') %>+ class: 'link_switcher',+ data: { target_field: :link_two}) %><%= f.error_message_on :link_type_two %><% end %><%= render "spree/admin/shared/cms/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_two, save_to: :link_two, f: f %>diff --git a/backend/app/views/spree/admin/menus/index.html.erb b/backend/app/views/spree/admin/menus/index.html.erbindex ad83abed6c..c7dce66f56 100644--- a/backend/app/views/spree/admin/menus/index.html.erb+++ b/backend/app/views/spree/admin/menus/index.html.erb@@ -94,6 +94,7 @@</tbody></table></div>+<%= render 'spree/admin/shared/index_table_options', collection: @menus, simple: true %><% else %><div class="alert alert-info no-objects-found"><%= Spree.t('admin.navigation.you_have_no_menus') %>diff --git a/backend/app/views/spree/admin/shared/_link_fields.html.erb b/backend/app/views/spree/admin/shared/_link_fields.html.erbindex ad2cb35696..256978c8bd 100644--- a/backend/app/views/spree/admin/shared/_link_fields.html.erb+++ b/backend/app/views/spree/admin/shared/_link_fields.html.erb@@ -1,10 +1,10 @@<% if resource.linked_resource_type.present? %>- <div data-panel-type="<%= resource.linked_resource_type %>">+ <div data-panel-type="<%= resource.linked_resource_type %>" data-panel-id="menu_item_link"><%= render "spree/admin/shared/linkables/#{spree_class_name_as_path(resource.linked_resource_type)}", resource: resource, f: f %></div><% end %>-<div id="linkClickUpdate" class="d-none">+<div class="d-none" data-target-message-pannel="menu_item_link"><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') %>diff --git a/backend/app/views/spree/admin/shared/cms/_link_fields.html.erb b/backend/app/views/spree/admin/shared/cms/_link_fields.html.erbindex ecf89f29e6..c069d3d1c5 100644--- a/backend/app/views/spree/admin/shared/cms/_link_fields.html.erb+++ b/backend/app/views/spree/admin/shared/cms/_link_fields.html.erb@@ -1,10 +1,10 @@<% if linked_type.present? && linked_type.present? %>- <div data-panel-type="<%= linked_type %>">+ <div data-panel-type="<%= linked_type %>" data-panel-id="<%= save_to %>"><%= render "spree/admin/shared/cms/#{spree_class_name_as_path(linked_type)}", resource: resource, save_to: save_to, f: f %></div><% end %>-<div id="linkClickUpdate" class="d-none">+<div class="d-none" data-target-message-pannel="<%= save_to %>"><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') %>diff --git a/core/app/models/spree/cms/sections/featured_article.rb b/core/app/models/spree/cms/sections/featured_article.rbindex c1a18555bc..fdf81e45c9 100644--- a/core/app/models/spree/cms/sections/featured_article.rb+++ b/core/app/models/spree/cms/sections/featured_article.rb@@ -1,5 +1,6 @@module Spree::Cms::Sectionsclass FeaturedArticle < Spree::CmsSection+ before_save :reset_link_attributesafter_initialize :default_valuesstore :content, accessors: [:title, :subtitle, :button_text, :rte_content], coder: JSON@@ -13,6 +14,12 @@ module Spree::Cms::Sectionsprivate+ def reset_link_attributes+ if linked_resource_type_changed?+ self.linked_resource_id = nil+ end+ end+def default_valuesself.gutters ||= 'No Gutters'self.fit ||= 'Screen'diff --git a/core/app/models/spree/cms/sections/full_screen_hero_image.rb b/core/app/models/spree/cms/sections/full_screen_hero_image.rbindex 85b25bd366..58e59bc05b 100644--- a/core/app/models/spree/cms/sections/full_screen_hero_image.rb+++ b/core/app/models/spree/cms/sections/full_screen_hero_image.rb@@ -1,5 +1,6 @@module Spree::Cms::Sectionsclass FullScreenHeroImage < Spree::CmsSection+ before_save :reset_link_attributesafter_initialize :default_valuesstore :content, accessors: [:title, :button_text], coder: JSON@@ -13,6 +14,12 @@ module Spree::Cms::Sectionsprivate+ def reset_link_attributes+ if linked_resource_type_changed?+ self.linked_resource_id = nil+ end+ end+def default_valuesself.gutters ||= 'No Gutters'self.fit ||= 'Screen'diff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 6a0e905092..cf2fe94d5f 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -587,6 +587,8 @@ en:aspect_ratio: Please use an image with the aspect ratio of 12:5 (2400px x 1000px)select_page_type: Select a page typesection_type: Section Type+ subtitle: Subtitle+ set_gutters: Set Guttersclick_button_to_change_page_type: Click the <b>%{button_type}</b> button to load the options for this page type.more_page_settings: '<span class="more">More</span><span class="less">Less</span> Page Settings'seo_settings: SEO Settings@@ -598,9 +600,10 @@ en:page_sections_info: 'The area below represents your %{page_type} displayed in %{store}, add sections and drag them into position'visible: Visibleside_by_side:+ left_image: Left Image+ right_image: Right Imagesection_one_info: 'This section is displayed on the left hand side of the screen and stacks to fullscreen on mobile size screens. Please use an image with an aspect ratio of 54:35 (1468px x 952px).'section_two_info: 'This section is displayed on the right hand side of the screen and stacks to fullscreen on mobile size screens. Please use an image with an aspect ratio of 54:35 (1468px x 952px).'-three_taxon_block:top_left_block: Top Left Blocksection_one_info: 'This section is displayed in the top left of the three image block. Please use an image with an aspect ratio of 18:13 (1080px x 780px).'diff --git a/sample/db/samples/cms_sections.rb b/sample/db/samples/cms_sections.rbindex 60cdee3b38..6557f1f40e 100644--- a/sample/db/samples/cms_sections.rb+++ b/sample/db/samples/cms_sections.rb@@ -189,8 +189,10 @@ end# Side-by-Side PromotionsPAGES.each do |page|- permalink_one = 'streetstyle'- permalink_two = 'special-offers/30-percent-off'++ link_type = 'Spree::Taxon'+ link_one = 'streetstyle'+ link_two = 'special-offers/30-percent-off'case page.localewhen 'en'@@ -236,11 +238,13 @@ PAGES.each do |page|promos_section.title_one = title_onepromos_section.subtitle_one = subtitle_one- promos_section.permalink_one = permalink_one+ promos_section.link_type_one = link_type+ promos_section.link_one = link_onepromos_section.title_two = title_twopromos_section.subtitle_two = subtitle_two- promos_section.permalink_two = permalink_two+ promos_section.link_type_two = link_type+ promos_section.link_two = link_twopromos_section.save!end