Class: Spree::Taxon
- Extended by:
- FriendlyId
- Includes:
- Metadata, TranslatableResource, TranslatableResourceSlug, Webhooks::HasWebhooks
- Defined in:
- app/models/spree/taxon.rb
Constant Summary collapse
- TRANSLATABLE_FIELDS =
%i[name description permalink].freeze
Instance Method Summary collapse
- #active_products ⇒ Object
-
#applicable_filters ⇒ Object
indicate which filters should be used for a taxon this method should be customized to your own site.
- #cached_self_and_descendants_ids ⇒ Object
-
#child_index=(idx) ⇒ Object
awesome_nested_set sorts by :lft and :rgt.
- #pretty_name ⇒ Object
-
#seo_title ⇒ Object
Return meta_title if set otherwise generates from taxon name.
-
#set_permalink ⇒ Object
Creates permalink base for friendly_id.
Methods inherited from Base
belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope
Methods included from Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference
Instance Method Details
#active_products ⇒ Object
123 124 125 |
# File 'app/models/spree/taxon.rb', line 123 def active_products products.active end |
#applicable_filters ⇒ Object
indicate which filters should be used for a taxon this method should be customized to your own site
103 104 105 106 107 108 109 110 111 |
# File 'app/models/spree/taxon.rb', line 103 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 |
#cached_self_and_descendants_ids ⇒ Object
134 135 136 137 138 |
# File 'app/models/spree/taxon.rb', line 134 def cached_self_and_descendants_ids Rails.cache.fetch("#{cache_key_with_version}/descendant-ids") do self_and_descendants.ids end 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.
146 147 148 |
# File 'app/models/spree/taxon.rb', line 146 def child_index=(idx) move_to_child_with_index(parent, idx.to_i) unless new_record? end |
#pretty_name ⇒ Object
127 128 129 130 131 132 |
# File 'app/models/spree/taxon.rb', line 127 def pretty_name ancestor_chain = ancestors.inject('') do |name, ancestor| name += "#{ancestor.name} -> " end ancestor_chain + name.to_s end |
#seo_title ⇒ Object
Return meta_title if set otherwise generates from taxon name
114 115 116 |
# File 'app/models/spree/taxon.rb', line 114 def seo_title .blank? ? name : end |
#set_permalink ⇒ Object
Creates permalink base for friendly_id
119 120 121 |
# File 'app/models/spree/taxon.rb', line 119 def set_permalink translations.each(&:set_permalink) end |