app/helpers/spree/frontend_helper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
... def open_menu(taxon,seach_taxons) (taxon.children.ids.map{|e| e.to_s} & seach_taxons).count>0 ? 'in' : '' if seach_taxons.present? end def taxons_tree(root_taxon, current_taxon, max_level = 1) return '' if max_level < 1 || root_taxon.leaf? if max_level == 2 content_tag :div, class: 'list-group' do taxons = root_taxon.children.map do |taxon| link_to('#' + taxon.id.to_s, class: 'list-group-item', 'aria-expanded': false, data: {toggle: 'collapse', target: '#' + taxon.id.to_s}) {cheveron_change + taxon.name} + taxons_tree(taxon, current_taxon, max_level - 1) end safe_join(taxons, "\n") end else search_taxons = params[:search][:taxons] if params[:search] and params[:search][:taxons] content_tag :div, id: root_taxon.id, class: "list-group collapse #{open_menu(root_taxon, search_taxons)}" do taxons = root_taxon.children.map do |taxon| # link_to(seo_url(taxon), class: 'list-group-item'){content_tag(:span, " ", class: "") + taxon.name} + taxons_tree(taxon, current_taxon, max_level - 1) label = "taxon_#{taxon.id}".gsub(/\s+/, '_') checked = true if params[:search] && params[:search][:taxons] && params[:search][:taxons].include?(taxon.id.to_s) content_tag :div, id: "div_#{label}", class: 'list-group-item' do (check_box_tag label, taxon.id, checked, name: "search[taxons][]", :class => 'event-checkbox filter_check list-group-item', form: 'form_search') + (label_tag label, taxon.name) end end safe_join(taxons, "\n") end end end ... |
app/views/spree/shared/_search.html.erb
1 2 3 4 5 6 7 8 9 10 |
<% @taxons = @taxon && @taxon.parent ? @taxon.parent.children : Spree::Taxon.roots %> <%= form_tag spree.products_path, method: :get, id: 'form_search' do %> <div class="search form-group naz-search"> <%= search_field_tag :keywords, params[:keywords], placeholder: Spree.t(:search), class: "form-control search-input" %> <%= button_tag "", class: "btn btn-default button-image" do %> <i class="fa fa-search awesome-search"></i> <% end %> </div> <% end %> |
lib/spree/core/search/base.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
def add_search_scopes(base_scope) if search product_ids = [] properties_product_ids = [] taxons_product_ids = [] if search[:properties] search[:properties].each do |property_name, property_values| property = Spree::Property.where(name: property_name).first Spree::ProductProperty.where(property_id: property.id).each do |product_property| properties_product_ids << product_property.product_id if property_values.include?(product_property.value) end end end if search[:taxons] search[:taxons].each do |taxon_id| Spree::Taxon.find(taxon_id.to_i).products.ids.each do |id| taxons_product_ids << id if taxons_product_ids.exclude?(id) end end end product_ids = properties_product_ids & taxons_product_ids if properties_product_ids.present? and taxons_product_ids.present? product_ids = properties_product_ids if properties_product_ids.present? and taxons_product_ids.empty? product_ids = taxons_product_ids if properties_product_ids.empty? and taxons_product_ids.present? base_scope = base_scope.where(id: product_ids) end base_scope end |
vendor/assets/javascripts/spree/frontend/all.js
1 2 3 |
$(document).on('click','.filter_check',function(){ $('#form_search').submit(); }); |