Skip to content

Commit

Permalink
Merge pull request spree-contrib#204 from pmilewski/fix/taxons-for-se…
Browse files Browse the repository at this point in the history
…arch

Taxons for search dropdown
  • Loading branch information
pmilewski authored Jul 25, 2019
2 parents e8a53a2 + 75cd901 commit d3e6c40
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/spree/products_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

before_action :can_show_product, only: :show

def index
@searcher = build_searcher(params.merge(include_images: true))
@products = @searcher.retrieve_products
@products = @products.includes(:possible_promotions) if @products.respond_to?(:includes)
@taxonomies = get_taxonomies
end

private

def can_show_product
Expand Down
6 changes: 6 additions & 0 deletions app/overrides/decorate_shared_search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Deface::Override.new(
virtual_path: 'spree/shared/_search',
name: 'filter current store taxons',
replace: "erb[silent]:contains('@taxons = @taxon && @taxon.parent ? @taxon.parent.children : Spree::Taxon.roots')",
text: "<% @taxons = taxons_for_search %>"
)
10 changes: 10 additions & 0 deletions lib/spree_multi_domain/multi_domain_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.included(receiver)
receiver.send :before_action, :add_current_store_id_to_params
receiver.send :helper_method, :current_store
receiver.send :helper_method, :current_tracker
receiver.send :helper_method, :taxons_for_search
end

def current_tracker
Expand All @@ -22,5 +23,14 @@ def get_taxonomies
def add_current_store_id_to_params
params[:current_store_id] = current_store.try(:id)
end

def taxons_for_search
taxons = @taxon && @taxon.parent ? @taxon.parent.children : Spree::Taxon.roots
if current_store.present?
taxons.joins(:taxonomy).where('spree_taxonomies.store_id = ?', current_store.id)
else
taxons
end
end
end
end

0 comments on commit d3e6c40

Please sign in to comment.