Skip to content

Commit

Permalink
Move taxon filter list to frontend
Browse files Browse the repository at this point in the history
These are only really valid in the frontend, and don't we don't gain
anything by it living inside of core.

This moves us forward to being able to deprecate
Spree::Taxon.applicable_filters
  • Loading branch information
Clarke Brunsdon authored and jhawthorn committed Apr 3, 2018
1 parent 7a042d6 commit a0128e7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/app/controllers/spree/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ProductsController < Spree::StoreController
before_action :load_product, only: :show
before_action :load_taxon, only: :index

helper 'spree/taxons'
helper 'spree/taxons', 'spree/taxon_filters'

respond_to :html

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/controllers/spree/taxons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
class TaxonsController < Spree::StoreController
helper 'spree/products'
helper 'spree/products', 'spree/taxon_filters'

respond_to :html

Expand Down
11 changes: 11 additions & 0 deletions frontend/app/helpers/spree/taxon_filters_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spree/core/product_filters'

module Spree
module TaxonFiltersHelper
def applicable_filters_for(_taxon)
[:brand_filter, :price_filter].map do |filter_name|
Spree::Core::ProductFilters.send(filter_name) if Spree::Core::ProductFilters.respond_to?(filter_name)
end.compact
end
end
end
2 changes: 1 addition & 1 deletion frontend/app/views/spree/shared/_filters.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% filters = @taxon.applicable_filters %>
<% filters = applicable_filters_for(@taxon) %>
<% unless filters.empty? %>
<%= form_tag '', method: :get, id: 'sidebar_products_search' do %>
<%= hidden_field_tag 'per_page', params[:per_page] %>
Expand Down
10 changes: 10 additions & 0 deletions frontend/spec/helpers/taxon_filters_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

RSpec.describe Spree::TaxonFiltersHelper, type: :helper do
let(:taxon) { nil }
subject { applicable_filters_for(taxon) }

it "returns the price/brand filters" do
expect(subject.map { |y| y[:name] }).to eq ['Brands', 'Price Range']
end
end

0 comments on commit a0128e7

Please sign in to comment.