To jest kod model/spree/taxon.rb
module Spree
class Taxon < ActiveRecord::Base
acts_as_nested_set :dependent => :destroy
belongs_to :taxonomy, :class_name => "Spree::Taxonomy"
has_and_belongs_to_many :products, :join_table => 'spree_products_taxons'
before_create :set_permalink
attr_accessible :name, :parent_id, :position, :icon, :description, :permalink, :taxonomy_id
validates :name, :presence => true
has_attached_file :icon,
:styles => { :mini => '32x32>', :normal => '128x128>' },
:default_style => :mini,
:url => '/spree/taxons/:id/:style/:basename.:extension',
:path => ':rails_root/public/spree/taxons/:id/:style/:basename.:extension',
:default_url => '/assets/default_taxon.png'
include ::Spree::ProductFilters # for detailed defs of filters
# indicate which filters should be used for a taxon
# this method should be customized to your own site
def applicable_filters
fs = []
# fs << ProductFilters.taxons_below(self)
## unless it's a root taxon? left open for demo purposes
fs << ProductFilters.price_filter if ProductFilters.respond_to?(:price_filter)
fs << ProductFilters.brand_filter if ProductFilters.respond_to?(:brand_filter)
fs
end
# Creates permalink based on Stringex's .to_url method
def set_permalink
if parent_id.nil?
self.permalink = name.to_url if permalink.blank?
else
parent_taxon = Taxon.find(parent_id)
self.permalink = [parent_taxon.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last)].join('/')
end
end
def active_products
scope = products.active
scope = scope.on_hand unless Spree::Config[:show_zero_stock_products]
scope
end
end
end
Kod controller/spree/taxons_controller.rb
module Spree
class TaxonsController < BaseController
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
helper 'spree/products'
respond_to :html
def show
@taxon = Taxon.find_by_permalink!(params[:id])
return unless @taxon
@nazwa = accurate_title
@sort_options = {
"Najpopularniejsze" => "descend_by_popularity",
"od A do Z" => "ascend_by_name",
"od Z do A" => "descend_by_name",
"Cena: od Wysokiej do Niskiej" => "descend_by_master_price",
"Cena: od Niskiej do Wysokiej" => "ascend_by_master_price",
}
@searcher = Spree::Config.searcher_class.new(params.merge(:taxon => @taxon.id))
@products = @searcher.retrieve_products
respond_with(@taxon)
end
def get_taxonomies
@taxonomies ||= Spree::Taxonomy.includes(:root => :children)
end
private
def accurate_title
@taxon ? @taxon.name : super
end
end
end
kod views/spree/taxons/show.html.erb
<h3 class="taxon-title"><%= accurate_title %></h3>
<% content_for :sidebar do %>
<div data-hook="taxon_sidebar_navigation">
<%#= render :partial => 'spree/shared/taxonomies' %>
<%= render :partial => 'spree/shared/filters' if @taxon.children.empty? %>
</div>
<% end %>
<div id="column_right">
<div class="produkty_styl" data-hook="taxon_products">
<div id="baner_page">
<%= insert_banner(:category => "#{@nazwa}" ) %>
</div>
<div id="page">
<div id="content_top">
<div id="breadcrumbs">
<%= breadcrumbs(@taxon) %>
</div>
<div id="sort">Sortuj wg:
<%= form_for :taxon, :url => seo_url(@taxon) do |f| %>
<%= select_tag 'product_group_query',
options_for_select(@sort_options.each_pair { |key, value|
[key,value] }), :onchange => "this.form.submit();" %>
<% end %>
</div>
</div>
<%= render :partial => 'spree/shared/products', :locals => { :products => @products, :taxon => @taxon } %>
</div>
</div>
</div>
Rozumiem że zdjęcia Pań mogą rozpraszać, tak więc będę pisać kodem…
Kod /views/spree/shared/_filters.html.erb
<div id="column_left">
<div id="menu_propoz" class="menu_left">
<div class="header">Propozycje</div>
</div>
<% filters = @taxon ? @taxon.applicable_filters : [Spree::ProductFilters.all_taxons] %>
<% unless filters.empty? %>
<%= form_tag '', :method => :get,:id => 'sidebar_products_search' do %>
<% params[:search] ||= {} %>
<%= hidden_field_tag 'per_page', params[:per_page] %>
<% filters.each do |filter| %>
<% labels = filter[:labels] || filter[:conds].map {|m,c| [m,m]} %>
<% next if labels.empty? %>
<% if filter[:name] == 'Sortuj po cenie:' %>
<div class="navigation" data-hook="navigation">
<h6 class="filter-title"> <%= filter[:name] %> </h6>
<ul class="filter_choices" >
<% labels.each do |nm,val| %>
<% label = "#{filter[:name]}_#{nm}".gsub(/\s+/,'_') %>
<li class="nowrap2">
<input type="checkbox"
id="<%= label %>"
name="search[<%= filter[:scope].to_s %>][]"
value="<%= val %>"
<%= params[:search][filter[:scope]] && params[:search][filter[:scope]].include?(val.to_s) ? "checked" : "" %> />
<label class="nowrap" for="<%= label %>"> <%= nm %> </label>
</li>
<% end %>
</ul>
</div>
<% else %>
<div class="navigation" data-hook="navigation">
<div id="wyb_produc">
<div class="flexcroll">
<h6 class="filter-title"> <%= filter[:name] %> </h6>
<ul>
<% labels.each do |nm,val| %>
<% label = "#{filter[:name]}_#{nm}".gsub(/\s+/,'_') %>
<li class="nowrap">
<input type="checkbox"
id="<%= label %>"
name="search[<%= filter[:scope].to_s %>][]"
value="<%= val %>"
<%= params[:search][filter[:scope]] && params[:search][filter[:scope]].include?(val.to_s) ? "checked" : "" %> />
<label class="nowrap" for="<%= label %>"> <%= nm %> </label>
</li>
<% end %>
</ul>
<div class="clearfloat"></div>
</div>
</div>
</div>
<% end %>
<% end %>
<div class="przycisk">
<%= submit_tag t(:search), :name => nil %>
</div>
<% end %>
<% end %>
</div>