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
102 103 104 |
# File 'app/models/spree/taxon.rb', line 102 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
82 83 84 85 86 87 88 89 90 |
# File 'app/models/spree/taxon.rb', line 82 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
113 114 115 116 117 |
# File 'app/models/spree/taxon.rb', line 113 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.
125 126 127 |
# File 'app/models/spree/taxon.rb', line 125 def child_index=(idx) move_to_child_with_index(parent, idx.to_i) unless new_record? end |
#pretty_name ⇒ Object
106 107 108 109 110 111 |
# File 'app/models/spree/taxon.rb', line 106 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
93 94 95 |
# File 'app/models/spree/taxon.rb', line 93 def seo_title .blank? ? name : end |
#set_permalink ⇒ Object
Creates permalink base for friendly_id
98 99 100 |
# File 'app/models/spree/taxon.rb', line 98 def set_permalink translations.each(&:set_permalink) end |