Sha256: 673b185e46a3e3910c424fce8ccacdbf3e16af7d87722c6d1fc8a9c39089fd8e

Contents?: true

Size: 1022 Bytes

Versions: 6

Compression:

Stored size: 1022 Bytes

Contents

class Taxon < ActiveRecord::Base
  acts_as_adjacency_list :foreign_key => 'parent_id', :order => 'position'
  belongs_to :taxonomy
  has_and_belongs_to_many :products
  before_save :set_permalink  
    

  # indicate which filters should be used for a taxon
  # this method should be customized to your own site
  include ProductFilters  # for detailed defs of filters
  def applicable_filters
    fs  = []
    fs << ProductFilters.taxons_below(self)
                          ## unless it's a root taxon? left open for demo purposes
    fs += [ 
            ProductFilters.price_filter,
            ProductFilters.brand_filter,
            ProductFilters.selective_brand_filter(self) ]
  end

  private

  # Creates permalink based on .to_url method provided by stringx gem
  def set_permalink
    self.permalink = (ancestors.reverse + [self]).collect { |taxon| 
      taxon.name.to_url 
    }.join("/") + "/"
  end
  
  # obsolete, kept for backwards compat 
  def escape(str)
    str.blank? ? "" : str.to_url
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
spree-enriquez-0.9.4 app/models/taxon.rb
spree-0.9.4 app/models/taxon.rb
spree-0.9.3 app/models/taxon.rb
spree-0.9.2 app/models/taxon.rb
spree-0.9.1 app/models/taxon.rb
spree-0.9.0 app/models/taxon.rb