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.

Active Record Base Store & Rails 5 (#11207)

Matthew Kennedydb10808ee1cf
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 c6cfb2040e..370e958c6e 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
@@ -50,16 +50,17 @@
<% end %>
<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 %>
+ <% unless rails_5? %>
+ <%= 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 %>
<% end %>
<%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_one, save_to: :link_one, f: f %>
</div>
@@ -94,16 +95,17 @@
<% end %>
<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 %>
+ <% unless rails_5? %>
+ <%= 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 %>
<% end %>
<%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_two, save_to: :link_two, f: f %>
</div>
@@ -138,16 +140,17 @@
<% end %>
<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 %>
+ <% unless rails_5? %>
+ <%= 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 %>
<% end %>
<%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_three, save_to: :link_three, f: f %>
</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 db95d5b3c6..718d8cc9fe 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
@@ -34,16 +34,17 @@
<% end %>
<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::SideBySideImages',
- { const: 'LINKED_RESOURCE_TYPE' }),
- { include_blank: false },
- class: 'link_switcher',
- data: { target_field: :link_one}) %>
- <%= f.error_message_on :link_type_one %>
+ <% unless rails_5? %>
+ <%= 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::SideBySideImages',
+ { const: 'LINKED_RESOURCE_TYPE' }),
+ { include_blank: false },
+ class: 'link_switcher',
+ data: { target_field: :link_one}) %>
+ <%= f.error_message_on :link_type_one %>
+ <% end %>
<% end %>
<%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_one, save_to: :link_one, f: f %>
</div>
@@ -85,15 +86,17 @@
<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::SideBySideImages',
- { const: 'LINKED_RESOURCE_TYPE' }),
- { include_blank: false },
- class: 'link_switcher',
- data: { target_field: :link_two}) %>
- <%= f.error_message_on :link_type_two %>
+ <% unless rails_5? %>
+ <%= 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::SideBySideImages',
+ { const: 'LINKED_RESOURCE_TYPE' }),
+ { include_blank: false },
+ class: 'link_switcher',
+ data: { target_field: :link_two}) %>
+ <%= f.error_message_on :link_type_two %>
+ <% end %>
<% end %>
<%= render "spree/admin/shared/link_fields", resource: @cms_section, linked_type: @cms_section.link_type_two, save_to: :link_two, f: f %>
</div>
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 4884d8dc6f..6f4be70843 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -171,6 +171,10 @@ module Spree
Spree::Core::Engine.frontend_available?
end
+ def rails_5?
+ Rails::VERSION::STRING < '6.0'
+ end
+
# we should always try to render image of the default variant
# same as it's done on PDP
def default_image_for_product(product)
diff --git a/core/app/models/spree/cms/sections/image_gallery.rb b/core/app/models/spree/cms/sections/image_gallery.rb
index 0fc77c0eda..17f8d03185 100644
--- a/core/app/models/spree/cms/sections/image_gallery.rb
+++ b/core/app/models/spree/cms/sections/image_gallery.rb
@@ -3,7 +3,12 @@ module Spree::Cms::Sections
after_initialize :default_values
before_save :reset_link_attributes
- LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freeze
+ LINKED_RESOURCE_TYPE = if Rails::VERSION::STRING < '6.0'
+ ['Spree::Taxon'].freeze
+ else
+ ['Spree::Taxon', 'Spree::Product'].freeze
+ end
+
LAYOUT_OPTIONS = ['Default', 'Reversed'].freeze
LABEL_OPTIONS = ['Show', 'Hide'].freeze
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 4f0168b94d..12f813c22f 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,11 @@ module Spree::Cms::Sections
after_initialize :default_values
before_save :reset_link_attributes
- LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freeze
+ LINKED_RESOURCE_TYPE = if Rails::VERSION::STRING < '6.0'
+ ['Spree::Taxon'].freeze
+ else
+ ['Spree::Taxon', 'Spree::Product'].freeze
+ end
store :content, accessors: [:link_type_one, :link_one, :title_one, :subtitle_one,
:link_type_two, :link_two, :title_two, :subtitle_two], coder: JSON