Class: Spree::Amazon::Taxon

Inherits:
Base
  • Object
show all
Extended by:
ActiveModel::Callbacks
Includes:
ActiveModel::AttributeMethods
Defined in:
app/models/spree/amazon/taxon.rb

Constant Summary

ROOT_TAXONS =
YAML.load( File.open(File.join( Rails.root, 'db', 'amazon_categories.yml' )  ) )

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#attributes=, #initialize, #to_param

Constructor Details

This class inherits a constructor from Spree::Amazon::Base

Class Attribute Details

.root_categoryObject

Returns the value of attribute root_category



15
16
17
# File 'app/models/spree/amazon/taxon.rb', line 15

def root_category
  @root_category
end

Instance Attribute Details

#ancestorsObject

Returns the value of attribute ancestors



7
8
9
# File 'app/models/spree/amazon/taxon.rb', line 7

def ancestors
  @ancestors
end

#childrenObject

Returns the value of attribute children



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def children
  @children
end

#idObject

Returns the value of attribute id



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def id
  @id
end

#is_parentObject Also known as: is_parent?

Returns the value of attribute is_parent



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def is_parent
  @is_parent
end

#is_rootObject

Returns the value of attribute is_root



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def is_root
  @is_root
end

#nameObject

Returns the value of attribute name



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def name
  @name
end

#parent_idObject

Returns the value of attribute parent_id



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def parent_id
  @parent_id
end

#search_indexObject

Returns the value of attribute search_index



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def search_index
  @search_index
end

#statusObject

Returns the value of attribute status



6
7
8
# File 'app/models/spree/amazon/taxon.rb', line 6

def status
  @status
end

Class Method Details

.find(cid) ⇒ Object



29
30
31
# File 'app/models/spree/amazon/taxon.rb', line 29

def find(cid)
  roots.find{ |x| x.id.to_s == cid.to_s} ||  new(SpreeEcs::Taxon.find(cid))
end

.rootsObject

Таксоны верхнего уровня



24
25
26
27
# File 'app/models/spree/amazon/taxon.rb', line 24

def roots
  @@roots ||= ROOT_TAXONS.map{ |x| new(:id => x[:id], :name => x[:name], :children => [])  }
  @@roots
end

Instance Method Details

#applicable_filtersObject



72
73
74
# File 'app/models/spree/amazon/taxon.rb', line 72

def applicable_filters
  [ ]
end

#parentObject



60
61
62
# File 'app/models/spree/amazon/taxon.rb', line 60

def parent
  ancestors.first
end


47
48
49
# File 'app/models/spree/amazon/taxon.rb', line 47

def permalink
  @id.to_s
end

#productsObject

Products



38
39
40
41
# File 'app/models/spree/amazon/taxon.rb', line 38

def products
  @taxon_products ||= Spree::Amazon::Product.multi_find(SpreeEcs::Taxon.top_sellers(self.id).join(', '))
  @taxon_products
end

#rootObject



43
44
45
# File 'app/models/spree/amazon/taxon.rb', line 43

def root
  is_root ? self.class.root_category : self
end

#self_and_descendantsObject



69
70
71
# File 'app/models/spree/amazon/taxon.rb', line 69

def self_and_descendants
  [ self, ancestors ].flatten.compact
end