Class: ShopCategory
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ShopCategory
- Defined in:
- app/models/shop_category.rb
Class Method Summary collapse
-
.attrs ⇒ Object
Returns attributes attached to the category.
-
.methds ⇒ Object
Returns methods with usefuly information.
-
.params ⇒ Object
Returns a custom hash of attributes on the category.
-
.sort(category_ids) ⇒ Object
Sorts a group of categories based on their ID and position in an array.
Instance Method Summary collapse
-
#available_images ⇒ Object
Returns images not attached to category.
-
#categories ⇒ Object
Returns the categories nested directly beneath this.
-
#description ⇒ Object
Returns the content of the product’s page’s description part.
-
#handle ⇒ Object
Returns the url of the page formatted as an sku.
-
#image_ids ⇒ Object
Returns an array of image ids.
-
#images ⇒ Object
Return an array of the pages images.
-
#name ⇒ Object
Returns the title of the categories’ page.
-
#products ⇒ Object
Returns products through the pages children.
-
#slug ⇒ Object
Returns the page slug.
-
#to_json(*attrs) ⇒ Object
Overloads the base to_json to return what we want.
-
#url ⇒ Object
Returns the url of the page.
Class Method Details
.attrs ⇒ Object
Returns attributes attached to the category
78 79 80 |
# File 'app/models/shop_category.rb', line 78 def attrs [ :id, :product_layout_id, :page_id, :created_at, :updated_at ] end |
.methds ⇒ Object
Returns methods with usefuly information
83 84 85 |
# File 'app/models/shop_category.rb', line 83 def methds [ :name, :description, :handle, :url, :created_at, :updated_at ] end |
.params ⇒ Object
Returns a custom hash of attributes on the category
88 89 90 |
# File 'app/models/shop_category.rb', line 88 def params { :only => self.attrs, :methods => self.methds } end |
.sort(category_ids) ⇒ Object
Sorts a group of categories based on their ID and position in an array
69 70 71 72 73 74 75 |
# File 'app/models/shop_category.rb', line 69 def sort(category_ids) category_ids.each_with_index do |id,index| ShopCategory.find(id).update_attributes!( :position => index ) end end |
Instance Method Details
#available_images ⇒ Object
Returns images not attached to category
58 |
# File 'app/models/shop_category.rb', line 58 def available_images; Image.all - images; end |
#categories ⇒ Object
Returns the categories nested directly beneath this
41 42 43 44 45 46 |
# File 'app/models/shop_category.rb', line 41 def categories pages = page.children.all( :conditions => { :class_name => 'ShopCategoryPage' }, :order => 'pages.position ASC' ).map(&:shop_category) end |
#description ⇒ Object
Returns the content of the product’s page’s description part
28 29 30 |
# File 'app/models/shop_category.rb', line 28 def description page.render_part('description') end |
#handle ⇒ Object
Returns the url of the page formatted as an sku
25 |
# File 'app/models/shop_category.rb', line 25 def handle; ShopProduct.to_sku(slug); end |
#image_ids ⇒ Object
Returns an array of image ids
55 |
# File 'app/models/shop_category.rb', line 55 def image_ids; images.map(&:id); end |
#images ⇒ Object
Return an array of the pages images
52 |
# File 'app/models/shop_category.rb', line 52 def images; page.images; end |
#name ⇒ Object
Returns the title of the categories’ page
19 |
# File 'app/models/shop_category.rb', line 19 def name; page.title; end |
#products ⇒ Object
Returns products through the pages children
33 34 35 36 37 38 |
# File 'app/models/shop_category.rb', line 33 def products pages = page.children.all( :conditions => { :class_name => 'ShopProductPage' }, :order => 'pages.position ASC' ).map(&:shop_product) end |
#slug ⇒ Object
Returns the page slug
61 |
# File 'app/models/shop_category.rb', line 61 def slug; page.slug; end |
#to_json(*attrs) ⇒ Object
Overloads the base to_json to return what we want
64 |
# File 'app/models/shop_category.rb', line 64 def to_json(*attrs); super self.class.params; end |
#url ⇒ Object
Returns the url of the page
22 |
# File 'app/models/shop_category.rb', line 22 def url; page.url; end |