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.

refactor filter link for option value when the filter is not a color

Łukasz Adamczyk596a47e04eb7
diff --git a/frontend/app/helpers/spree/products_filters_helper.rb b/frontend/app/helpers/spree/products_filters_helper.rb
index 3d7d6939b7..f00b518bc4 100644
--- a/frontend/app/helpers/spree/products_filters_helper.rb
+++ b/frontend/app/helpers/spree/products_filters_helper.rb
@@ -54,6 +54,7 @@ module Spree
new_params = permitted_params.merge(ot_downcase_name => option_value_param, menu_open: 1)
link_to new_params, data: { params: new_params, id: id, filter_name: ot_downcase_name, multiselect: true } do
+ # TODO: refactor this
if color_option_type_name.present? && color_option_type_name.downcase == ot_downcase_name
content_tag :span, class: 'd-inline-block mb-1' do
render partial: 'spree/shared/color_select', locals: {
@@ -62,9 +63,7 @@ module Spree
}
end
else
- content_tag :div, class: "#{FILTER_LINK_CSS_CLASSES} #{ACTIVE_FILTER_LINK_CSS_CLASSES if is_selected}" do
- option_value.name
- end
+ filter_content_tag(option_value.name, opts.merge(is_selected: is_selected))
end
end
end
@@ -98,14 +97,19 @@ module Spree
private
def base_filter_link(url, label, opts = {})
- opts[:css_class] ||= FILTER_LINK_CSS_CLASSES
- opts[:css_active_class] ||= ACTIVE_FILTER_LINK_CSS_CLASSES
opts[:params] ||= url
link_to url, data: { filter_name: opts[:filter_name], id: opts[:id], params: opts[:params], multiselect: opts[:multiselect] } do
- content_tag :div, class: "#{opts[:css_class]} #{opts[:css_active_class] if opts[:is_selected]}" do
- label.to_s
- end
+ filter_content_tag(label, opts)
+ end
+ end
+
+ def filter_content_tag(label, opts = {})
+ opts[:css_class] ||= FILTER_LINK_CSS_CLASSES
+ opts[:css_active_class] ||= ACTIVE_FILTER_LINK_CSS_CLASSES
+
+ content_tag :div, class: "#{opts[:css_class]} #{opts[:css_active_class] if opts[:is_selected]}" do
+ label.to_s
end
end