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 up image gallery to link to products or taxons, remove missing translations.

Matthew Kennedyce198f008d19
diff --git a/backend/app/views/spree/admin/cms_sections/types/_featured_article.html.erb b/backend/app/views/spree/admin/cms_sections/types/_featured_article.html.erb
index 6382201c93..b012d95d72 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_featured_article.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_featured_article.html.erb
@@ -1,19 +1,19 @@
<div class="row">
<div class="col-12 col-md-4">
<%= f.field_container :title, class: ['form-group'] do %>
- <%= f.label :title, Spree.t(:title) %>
+ <%= f.label :title, Spree.t('admin.cms.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(:subtitle) %>
+ <%= f.label :subtitle, Spree.t('admin.cms.subtitle') %>
<%= f.text_field :subtitle, class: 'form-control' %>
<%= f.error_message_on :subtitle %>
<% end %>
<%= f.field_container :button_text, class: ['form-group'] do %>
- <%= f.label :button_text, Spree.t(:button_text) %>
+ <%= f.label :button_text, Spree.t('admin.cms.button_text') %>
<%= f.text_field :button_text, class: 'form-control' %>
<%= f.error_message_on :button_text %>
<% end %>
@@ -27,7 +27,7 @@
</div>
<div class="col-12 col-md-8">
<%= f.field_container :rte_content, class: ['form-group'] do %>
- <%= f.label :rte_content, Spree.t('content') %>
+ <%= f.label :rte_content, Spree.t('admin.cms.content') %>
<%= f.text_area :rte_content, { rows: "20", class: 'form-control spree-rte' } %>
<%= f.error_message_on :rte_content %>
<% end %>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb b/backend/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb
index 18980c32f7..c6cfb2040e 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb
@@ -1,5 +1,5 @@
<div class="row align-items-center">
- <div id="ImageGalleryLayout" class="col-6 text-center m-auto">
+ <div id="ImageGalleryLayout" class="col-12 col-md-6 text-center m-auto">
<div id="LayoutType">
<div id="Default" class="<% unless @cms_section.layout_style == 'Default' %>d-none<% end %>">
<%= svg_icon name: "default-layout.svg", width: '150', height: '150' %>
@@ -49,20 +49,19 @@
<%= f.error_message_on :title_one %>
<% end %>
- <%= f.field_container :permalink_one, class: ['form-group'] do %>
- <%= f.label :permalink_one, Spree.t('admin.cms.link_to_taxon') %>
- <%= f.select :permalink_one,
- options_from_collection_for_select([@cms_section],
- :permalink_one, :permalink_one, @cms_section.permalink_one || nil),
- { include_blank: true },
- class: 'select2autocomplete',
- data: { autocomplete_placeholder_value: Spree.t('admin.navigation.seach_for_a_taxon'),
- autocomplete_clear_value: true,
- autocomplete_url_value: 'taxons_api_v2',
- autocomplete_return_attr_value: 'permalink',
- autocomplete_custom_return_id_value: 'permalink' } %>
- <%= f.error_message_on :permalink_ones %>
+ <div class="col-12"><hr></div>
+
+ <%= f.field_container :link_type_one, class: ['form-group'] do %>
+ <%= f.label :link_type_one, Spree.t('admin.navigation.link_to') %>
+ <%= f.select(:link_type_one,
+ spree_humanize_dropdown_values('Spree::Cms::Sections::ImageGallery',
+ { const: 'LINKED_RESOURCE_TYPE' }),
+ { include_blank: false },
+ class: 'link_switcher',
+ data: { target_field: :link_one}) %>
+ <%= f.error_message_on :link_type_one %>
<% end %>
+ <%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_one, save_to: :link_one, f: f %>
</div>
</div>
@@ -94,20 +93,19 @@
<%= f.error_message_on :title_two %>
<% end %>
- <%= f.field_container :permalink_two, class: ['form-group'] do %>
- <%= f.label :permalink_two, Spree.t('admin.cms.link_to_taxon') %>
- <%= f.select :permalink_two,
- options_from_collection_for_select([@cms_section],
- :permalink_two, :permalink_two, @cms_section.permalink_two || nil),
- { include_blank: true },
- class: 'select2autocomplete',
- data: { autocomplete_placeholder_value: Spree.t('admin.navigation.seach_for_a_taxon'),
- autocomplete_clear_value: true,
- autocomplete_url_value: 'taxons_api_v2',
- autocomplete_return_attr_value: 'permalink',
- autocomplete_custom_return_id_value: 'permalink' } %>
- <%= f.error_message_on :permalink_two %>
+ <div class="col-12"><hr></div>
+
+ <%= f.field_container :link_type_two, class: ['form-group'] do %>
+ <%= f.label :link_type_two, Spree.t('admin.navigation.link_to') %>
+ <%= f.select(:link_type_two,
+ spree_humanize_dropdown_values('Spree::Cms::Sections::ImageGallery',
+ { const: 'LINKED_RESOURCE_TYPE' }),
+ { include_blank: false },
+ class: 'link_switcher',
+ data: { target_field: :link_two}) %>
+ <%= f.error_message_on :link_type_two %>
<% end %>
+ <%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_two, save_to: :link_two, f: f %>
</div>
</div>
@@ -139,20 +137,19 @@
<%= f.error_message_on :title_three %>
<% end %>
- <%= f.field_container :permalink_three, class: ['form-group'] do %>
- <%= f.label :permalink_three, Spree.t('admin.cms.link_to_taxon') %>
- <%= f.select :permalink_three,
- options_from_collection_for_select([@cms_section],
- :permalink_three, :permalink_three, @cms_section.permalink_three || nil),
- { include_blank: true },
- class: 'select2autocomplete',
- data: { autocomplete_placeholder_value: Spree.t('admin.navigation.seach_for_a_taxon'),
- autocomplete_clear_value: true,
- autocomplete_url_value: 'taxons_api_v2',
- autocomplete_return_attr_value: 'permalink',
- autocomplete_custom_return_id_value: 'permalink' } %>
- <%= f.error_message_on :permalink_three %>
+ <div class="col-12"><hr></div>
+
+ <%= f.field_container :link_type_three, class: ['form-group'] do %>
+ <%= f.label :link_type_three, Spree.t('admin.navigation.link_to') %>
+ <%= f.select(:link_type_three,
+ spree_humanize_dropdown_values('Spree::Cms::Sections::ImageGallery',
+ { const: 'LINKED_RESOURCE_TYPE' }),
+ { include_blank: false },
+ class: 'link_switcher',
+ data: { target_field: :link_three}) %>
+ <%= f.error_message_on :link_type_three %>
<% end %>
+ <%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_three, save_to: :link_three, f: f %>
</div>
</div>
</div>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb b/backend/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb
index 21d5a1cbc0..5a80118c94 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_side_by_side_images.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="text-center"><%= Spree.t('admin.cms.side_by_side.left_image') %></h5>
+ <h4 class="text-center pb-2"><%= Spree.t('admin.cms.side_by_side.left_image') %></h4>
<%= 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">
@@ -49,7 +49,7 @@
<div class="col-12 col-md-6 mb-3">
<div class="card p-3">
- <h5 class="text-center"><%= Spree.t('admin.cms.side_by_side.right_image') %></h5>
+ <h4 class="text-center pb-2"><%= Spree.t('admin.cms.side_by_side.right_image') %></h4>
<%= 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">
diff --git a/core/app/models/spree/cms/sections/image_gallery.rb b/core/app/models/spree/cms/sections/image_gallery.rb
index 0a06a69ba8..b2d60c7485 100644
--- a/core/app/models/spree/cms/sections/image_gallery.rb
+++ b/core/app/models/spree/cms/sections/image_gallery.rb
@@ -2,12 +2,13 @@ module Spree::Cms::Sections
class ImageGallery < Spree::CmsSection
after_initialize :default_values
- LAYOUT_OPTIONS = ['Default', 'Reversed']
- LABEL_OPTIONS = ['Show', 'Hide']
+ LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freeze
+ LAYOUT_OPTIONS = ['Default', 'Reversed'].freeze
+ LABEL_OPTIONS = ['Show', 'Hide'].freeze
- store :content, accessors: [:permalink_one, :title_one,
- :permalink_two, :title_two,
- :permalink_three, :title_three], coder: JSON
+ store :content, accessors: [:link_type_one, :link_one, :title_one,
+ :link_type_two, :link_two, :title_two,
+ :link_type_three, :link_three, :title_three], coder: JSON
store :settings, accessors: [:layout_style, :display_labels], coder: JSON
@@ -16,6 +17,9 @@ module Spree::Cms::Sections
def default_values
self.layout_style ||= 'Default'
self.fit ||= 'Container'
+ self.link_type_one ||= 'Spree::Taxon'
+ self.link_type_two ||= 'Spree::Taxon'
+ self.link_type_three ||= 'Spree::Taxon'
end
end
end
diff --git a/core/app/models/spree/cms/sections/side_by_side_images.rb b/core/app/models/spree/cms/sections/side_by_side_images.rb
index 4bfc685444..4b5b2cd617 100644
--- a/core/app/models/spree/cms/sections/side_by_side_images.rb
+++ b/core/app/models/spree/cms/sections/side_by_side_images.rb
@@ -3,7 +3,7 @@ module Spree::Cms::Sections
after_initialize :default_values
before_save :reset_link_attributes
- LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product']
+ LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freeze
store :content, accessors: [:link_type_one, :link_one, :title_one, :subtitle_one,
:link_type_two, :link_two, :title_two, :subtitle_two], coder: JSON
diff --git a/frontend/app/views/spree/shared/cms/sections/_image_gallery.html.erb b/frontend/app/views/spree/shared/cms/sections/_image_gallery.html.erb
index ec56cb126d..d13fa4f0f3 100644
--- a/frontend/app/views/spree/shared/cms/sections/_image_gallery.html.erb
+++ b/frontend/app/views/spree/shared/cms/sections/_image_gallery.html.erb
@@ -22,24 +22,33 @@
<% labels_class = 'homepage-taxon-box-text' %>
<% end %>
-<% if section.permalink_one.present? %>
- <% link_one = spree.nested_taxons_path(section.permalink_one) %>
+<% if section.link_one.present? && section.link_type_one == 'Spree::Taxon' %>
+ <% link_one = spree.nested_taxons_path(section.link_one) %>
+ <% link_one_classes = 'homepage-taxon-box bg-light' %>
+<% elsif section.link_one.present? && section.link_type_one == 'Spree::Product' %>
+ <% link_one = spree.product_path(section.link_one) %>
<% link_one_classes = 'homepage-taxon-box bg-light' %>
<% else %>
<% link_one = nil %>
<% link_one_classes = 'homepage-taxon-box bg-light pointer-events-none cursor-default' %>
<% end %>
-<% if section.permalink_two.present? %>
- <% link_two = spree.nested_taxons_path(section.permalink_two) %>
+<% if section.link_two.present? && section.link_type_two == 'Spree::Taxon' %>
+ <% link_two = spree.nested_taxons_path(section.link_two) %>
+ <% link_two_classes = 'homepage-taxon-box bg-light' %>
+<% elsif section.link_two.present? && section.link_type_two == 'Spree::Product' %>
+ <% link_two = spree.product_path(section.link_two) %>
<% link_two_classes = 'homepage-taxon-box bg-light' %>
<% else %>
<% link_two = nil %>
<% link_two_classes = 'homepage-taxon-box bg-light pointer-events-none cursor-default' %>
<% end %>
-<% if section.permalink_three.present? %>
- <% link_three = spree.nested_taxons_path(section.permalink_two) %>
+<% if section.link_three.present? && section.link_type_three == 'Spree::Taxon' %>
+ <% link_three = spree.nested_taxons_path(section.link_three) %>
+ <% link_three_classes = 'homepage-taxon-box bg-light' %>
+<% elsif section.link_three.present? && section.link_type_three == 'Spree::Product' %>
+ <% link_three = spree.product_path(section.link_three) %>
<% link_three_classes = 'homepage-taxon-box bg-light' %>
<% else %>
<% link_three = nil %>
diff --git a/frontend/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb b/frontend/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb
index 66445fbe95..589a9aeb5f 100644
--- a/frontend/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb
+++ b/frontend/app/views/spree/shared/cms/sections/_side_by_side_images.html.erb
@@ -1,7 +1,3 @@
-<!-- This looks messy having all this ERB logic in the view file, but section settings, classes and links are
- section specific; no two are the same. Therefore it might be better to leave them in the view file they
- pertain to vs moving this to view helper files. -->
-
<% if section.gutters? %>
<% section_one_padding = 'pr-md-2' %>
<% section_two_padding = 'pl-md-2' %>
diff --git a/sample/db/samples/cms_sections.rb b/sample/db/samples/cms_sections.rb
index 300147cca2..0e78e11638 100644
--- a/sample/db/samples/cms_sections.rb
+++ b/sample/db/samples/cms_sections.rb
@@ -44,9 +44,9 @@ end
# Three Taxons
PAGES.each do |page|
- permalink_one = 'men'
- permalink_two = 'women'
- permalink_three = 'sportswear'
+ link_one = 'men'
+ link_two = 'women'
+ link_three = 'sportswear'
case page.locale
when 'en'
@@ -82,9 +82,9 @@ PAGES.each do |page|
cms_page: page
).first_or_create!
- three_taxon_section.permalink_one = permalink_one
- three_taxon_section.permalink_two = permalink_two
- three_taxon_section.permalink_three = permalink_three
+ three_taxon_section.link_one = link_one
+ three_taxon_section.link_two = link_two
+ three_taxon_section.link_three = link_three
three_taxon_section.title_one = title_one
three_taxon_section.title_two = title_two
@@ -189,8 +189,6 @@ end
# Side-by-Side Promotions
PAGES.each do |page|
-
- link_type = 'Spree::Taxon'
link_one = 'streetstyle'
link_two = 'special-offers/30-percent-off'
@@ -238,12 +236,10 @@ PAGES.each do |page|
promos_section.title_one = title_one
promos_section.subtitle_one = subtitle_one
- promos_section.link_type_one = link_type
promos_section.link_one = link_one
promos_section.title_two = title_two
promos_section.subtitle_two = subtitle_two
- promos_section.link_type_two = link_type
promos_section.link_two = link_two
promos_section.save!