Class: Spree::Taxon

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

Instance Method Summary collapse

Methods included from Core::ProductFilters

all_taxons, brand_filter, format_price, price_filter, selective_brand_filter, taxons_below

Instance Method Details

#active_productsObject


60
61
62
63
# File 'app/models/spree/taxon.rb', line 60

def active_products
  scope = products.active
  scope
end

#applicable_filtersObject

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


27
28
29
30
31
32
33
34
35
# File 'app/models/spree/taxon.rb', line 27

def applicable_filters
  fs = []
  # fs << ProductFilters.taxons_below(self)
  ## unless it's a root taxon? left open for demo purposes

  fs << Spree::Core::ProductFilters.price_filter if Spree::Core::ProductFilters.respond_to?(:price_filter)
  fs << Spree::Core::ProductFilters.brand_filter if Spree::Core::ProductFilters.respond_to?(:brand_filter)
  fs
end

#pretty_nameObject


65
66
67
68
69
70
# File 'app/models/spree/taxon.rb', line 65

def pretty_name
  ancestor_chain = self.ancestors.inject("") do |name, ancestor|
    name += "#{ancestor.name} -> "
  end
  ancestor_chain + "#{name}"
end

#seo_titleObject

Return meta_title if set otherwise generates from root name and/or taxon name


38
39
40
41
42
43
44
# File 'app/models/spree/taxon.rb', line 38

def seo_title
  if meta_title
    meta_title
  else
    root? ? name : "#{root.name} - #{name}"
  end
end

Creates permalink based on Stringex's .to_url method


47
48
49
50
51
52
53
# File 'app/models/spree/taxon.rb', line 47

def set_permalink
  if parent.present?
    self.permalink = [parent.permalink, (permalink.blank? ? name.to_url : permalink.split('/').last)].join('/')
  else
    self.permalink = name.to_url if permalink.blank?
  end
end

#to_paramObject

For #2759


56
57
58
# File 'app/models/spree/taxon.rb', line 56

def to_param
  permalink
end