Class: Spree::Taxon

Inherits:
Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/spree/taxon.rb

Instance Method Summary collapse

Methods inherited from Base

belongs_to_required_by_default, page, spree_base_scopes

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#active_productsObject


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

def active_products
  products.active
end

#applicable_filtersObject

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


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

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

#child_index=(idx) ⇒ Object

awesome_nested_set sorts by :lft and :rgt. This call re-inserts the child node so that its resulting position matches the observable 0-indexed position. ** Note ** no :position column needed - a_n_s doesn't handle the reordering if

you bring your own :order_column.

See #3390 for background.

84
85
86
# File 'app/models/spree/taxon.rb', line 84

def child_index=(idx)
  move_to_child_with_index(parent, idx.to_i) unless new_record?
end

#pretty_nameObject


71
72
73
74
75
76
# File 'app/models/spree/taxon.rb', line 71

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

#seo_titleObject

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


50
51
52
53
54
55
56
# File 'app/models/spree/taxon.rb', line 50

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

Creates permalink base for friendly_id


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

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