Class: Spree::Taxon
- Defined in:
- app/models/spree/taxon.rb
Instance Method Summary collapse
-
#active_products ⇒ ActiveRecord::Relation<Spree::Product>
The active products the belong to this taxon.
-
#applicable_filters ⇒ Array
Filters that should be used for a taxon.
- #child_index=(idx) ⇒ Object
-
#pretty_name ⇒ String
This taxon’s ancestors names followed by its own name, separated by arrows.
-
#seo_title ⇒ String
Meta_title if set otherwise a string containing the root name and taxon name.
-
#set_permalink ⇒ Object
Sets this taxons permalink to a valid url encoded string based on its name and its parents permalink (if present.).
-
#to_param ⇒ String
This taxon’s permalink.
Methods inherited from Base
#initialize_preference_defaults, page, preference
Methods included from Preferences::Preferable
#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#active_products ⇒ ActiveRecord::Relation<Spree::Product>
Returns the active products the belong to this taxon.
74 75 76 |
# File 'app/models/spree/taxon.rb', line 74 def active_products products.active end |
#applicable_filters ⇒ Array
This method is meant to be overridden on a store by store basis.
Returns filters that should be used for a taxon.
37 38 39 40 41 42 43 44 45 |
# File 'app/models/spree/taxon.rb', line 37 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
88 89 90 91 92 93 94 95 96 |
# File 'app/models/spree/taxon.rb', line 88 def child_index=(idx) # 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 - awesom_nested_set doesn't handle the # reordering if you bring your own :order_column. move_to_child_with_index(parent, idx.to_i) unless self.new_record? end |
#pretty_name ⇒ String
Returns this taxon’s ancestors names followed by its own name, separated by arrows.
80 81 82 83 84 85 |
# File 'app/models/spree/taxon.rb', line 80 def pretty_name ancestor_chain = self.ancestors.inject("") do |name, ancestor| name += "#{ancestor.name} -> " end ancestor_chain + "#{name}" end |
#seo_title ⇒ String
Returns meta_title if set otherwise a string containing the root name and taxon name.
49 50 51 52 53 54 55 |
# File 'app/models/spree/taxon.rb', line 49 def seo_title unless .blank? else root? ? name : "#{root.name} - #{name}" end end |
#set_permalink ⇒ Object
Sets this taxons permalink to a valid url encoded string based on its name and its parents permalink (if present.)
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 |
#to_param ⇒ String
Returns this taxon’s permalink.
68 69 70 |
# File 'app/models/spree/taxon.rb', line 68 def to_param permalink end |