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
79 80 81 |
# File 'app/models/shop_category.rb', line 79 def attrs [ :id, :product_layout_id, :page_id, :created_at, :updated_at ] end |
.methds ⇒ Object
Returns methods with usefuly information
84 85 86 |
# File 'app/models/shop_category.rb', line 84 def methds [ :name, :description, :handle, :url, :created_at, :updated_at ] end |
.params ⇒ Object
Returns a custom hash of attributes on the category
89 90 91 |
# File 'app/models/shop_category.rb', line 89 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
70 71 72 73 74 75 76 |
# File 'app/models/shop_category.rb', line 70 def sort(category_ids) category_ids.each_with_index do |id, index| ShopCategory.find(id).page.update_attributes!( :position => index+1 ) end end |
Instance Method Details
#available_images ⇒ Object
Returns images not attached to category
59 |
# File 'app/models/shop_category.rb', line 59 def available_images; Image.all - images; end |
#categories ⇒ Object
Returns the categories nested directly beneath this
42 43 44 45 46 47 |
# File 'app/models/shop_category.rb', line 42 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
29 30 31 |
# File 'app/models/shop_category.rb', line 29 def description page.render_part('description') end |
#handle ⇒ Object
Returns the url of the page formatted as an sku
26 |
# File 'app/models/shop_category.rb', line 26 def handle; ShopProduct.to_sku(slug); end |
#image_ids ⇒ Object
Returns an array of image ids
56 |
# File 'app/models/shop_category.rb', line 56 def image_ids; images.map(&:id); end |
#images ⇒ Object
Return an array of the pages images
53 |
# File 'app/models/shop_category.rb', line 53 def images; page.images; end |
#name ⇒ Object
Returns the title of the categories’ page
20 |
# File 'app/models/shop_category.rb', line 20 def name; page.title; end |
#products ⇒ Object
Returns products through the pages children
34 35 36 37 38 39 |
# File 'app/models/shop_category.rb', line 34 def products pages = page.children.all( :conditions => { :class_name => 'ShopProductPage' }, :order => 'pages.position ASC' ).map(&:shop_product) end |
#slug ⇒ Object
Returns the page slug
62 |
# File 'app/models/shop_category.rb', line 62 def slug; page.slug; end |
#to_json(*attrs) ⇒ Object
Overloads the base to_json to return what we want
65 |
# File 'app/models/shop_category.rb', line 65 def to_json(*attrs); super self.class.params; end |
#url ⇒ Object
Returns the url of the page
23 |
# File 'app/models/shop_category.rb', line 23 def url; page.url; end |