Class: Spree::Taxon
- Defined in:
- app/models/spree/taxon.rb
Defined Under Namespace
Modules: PaperclipAttachment
Instance Method Summary collapse
-
#active_products ⇒ ActiveRecord::Relation<Spree::Product>
The active products the belong to this taxon.
-
#all_products ⇒ ActiveRecord::Relation<Spree::Product>
All self and descendant products.
-
#all_variants ⇒ ActiveRecord::Relation<Spree::Variant>
All self and descendant variants, including master variants.
-
#applicable_filters ⇒ Array
Filters that should be used for a taxon.
- #child_index=(idx) ⇒ Object
- #permalink_part ⇒ Object
- #permalink_part=(value) ⇒ 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.
-
#update_child_permalinks ⇒ Object
Update the permalinks for all children.
-
#update_permalinks ⇒ Object
Update the permalink for this taxon and all children (if necessary).
Methods inherited from Base
display_includes, #initialize_preference_defaults, page, preference
Methods included from Preferences::Preferable
#admin_form_preference_names, #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.
80 81 82 |
# File 'app/models/spree/taxon.rb', line 80 def active_products products.not_deleted.available end |
#all_products ⇒ ActiveRecord::Relation<Spree::Product>
Returns all self and descendant products.
85 86 87 88 89 90 |
# File 'app/models/spree/taxon.rb', line 85 def all_products scope = Product.joins(:taxons) scope.where( spree_taxons: { id: self_and_descendants.select(:id) } ) end |
#all_variants ⇒ ActiveRecord::Relation<Spree::Variant>
Returns all self and descendant variants, including master variants.
93 94 95 |
# File 'app/models/spree/taxon.rb', line 93 def all_variants Variant.where(product_id: all_products.select(:id)) 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.
34 35 36 37 38 39 40 41 |
# File 'app/models/spree/taxon.rb', line 34 def applicable_filters Spree::Deprecation.warn "Spree::Taxon#applicable_filters is deprecated, if you are using this functionality please move it into your own application." fs = [] 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
111 112 113 114 115 116 117 118 119 |
# File 'app/models/spree/taxon.rb', line 111 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 new_record? end |
#permalink_part ⇒ Object
121 122 123 |
# File 'app/models/spree/taxon.rb', line 121 def permalink_part permalink.split('/').last end |
#permalink_part=(value) ⇒ Object
125 126 127 128 129 130 131 |
# File 'app/models/spree/taxon.rb', line 125 def permalink_part=(value) if parent.present? self.permalink = "#{parent.permalink}/#{value}" else self.permalink = value end end |
#pretty_name ⇒ String
Returns this taxon’s ancestors names followed by its own name, separated by arrows.
99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/spree/taxon.rb', line 99 def pretty_name if parent.present? [ parent.pretty_name, name ].compact.join(" -> ") else name end end |
#seo_title ⇒ String
Returns meta_title if set otherwise a string containing the root name and taxon name.
45 46 47 48 49 50 51 |
# File 'app/models/spree/taxon.rb', line 45 def seo_title if .present? 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.)
55 56 57 58 |
# File 'app/models/spree/taxon.rb', line 55 def set_permalink permalink_tail = permalink.present? ? permalink.split('/').last : name self.permalink_part = Spree::Config.taxon_url_parametizer_class.parameterize(permalink_tail) end |
#to_param ⇒ String
Returns this taxon’s permalink.
74 75 76 |
# File 'app/models/spree/taxon.rb', line 74 def to_param permalink end |
#update_child_permalinks ⇒ Object
Update the permalinks for all children
69 70 71 |
# File 'app/models/spree/taxon.rb', line 69 def update_child_permalinks children.each(&:update_permalinks) end |
#update_permalinks ⇒ Object
Update the permalink for this taxon and all children (if necessary)
61 62 63 64 65 66 |
# File 'app/models/spree/taxon.rb', line 61 def update_permalinks set_permalink # This will trigger update_child_permalinks if permalink has changed save! end |