Class: Taxon

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ProductFilters
Defined in:
app/models/taxon.rb

Instance Method Summary collapse

Methods included from ProductFilters

all_taxons, brand_filter, price_filter, selective_brand_filter, taxons_below

Instance Method Details

#active_productsObject



41
42
43
44
45
# File 'app/models/taxon.rb', line 41

def active_products
  scope = self.products.active
  scope = scope.on_hand unless Spree::Config[:show_zero_stock_products]
  scope
end

#applicable_filtersObject

indicate which filters should be used for a taxon this method should be customized to your own site



21
22
23
24
25
26
27
28
29
# File 'app/models/taxon.rb', line 21

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 .to_url method provided by stringx gem



32
33
34
35
36
37
38
39
# File 'app/models/taxon.rb', line 32

def set_permalink
  if parent_id.nil?
    self.permalink = name.to_url if self.permalink.blank?
  else
    parent_taxon = Taxon.find(parent_id)
    self.permalink = [parent_taxon.permalink, (self.permalink.blank? ? name.to_url : self.permalink.split("/").last)].join('/')
  end
end