Updated models for DM 0.9.0:
[merb_mart.git] / app / models / store_item.rb
blob789318c8d59e8001901fc44fa59d85d982867d2a
1 # This is the base model for Product and ProductVariation.
3 require "date"
5 class StoreItem
7   include DataMapper::Resource
9   #has_many :order_line_items
10   #has_many :wishlist_items, :dependent => :destroy
12   property :id,             Fixnum, :serial => true
13   property :code,           String, :length => 20,  :default => "",    :nullable => false
14   property :name,           String, :length => 100, :default => "",    :nullable => false
15   property :description,    DataMapper::Types::Text
16   property :price,          Float,                   :default => 0.0,   :nullable => false
17   property :date_available, DateTime,                                   :nullable => false
18   property :quantity,       Fixnum,                 :default => 0,     :nullable => false
19   property :size_width,     Float,                   :default => 0.0,   :nullable => false
20   property :size_height,    Float,                   :default => 0.0,   :nullable => false
21   property :size_depth,     Float,                   :default => 0.0,   :nullable => false
22   property :weight,         Float,                   :default => 0.0,   :nullable => false
23   property :is_discontinued, TrueClass,                 :default => false, :nullable => false
24                             # Boolean?
25   
26   property :type,           Class    # enable single-table inheritence
27   
28   #t.integer  "product_id",                        :default => 0,     :null => false
30   # FIXME
31   #add_index ["quantity", "is_discontinued", "variation_quantity"], :name => "published"
32   #add_index ["product_id", "type"], :name => "variation"
33   #add_index ["date_available", "is_discontinued", "quantity", "variation_quantity", "type"], :name => "tag_view"
34   #add_index ["name", "code", "is_discontinued", "date_available", "quantity", "variation_quantity", "type"], :name => "search"
36   # FIXME
37   #validates_presence_of :name, :code
38   #validates_uniqueness_of :code
39   
40   #############################################################################
41   # CALLBACKS
42   #############################################################################
43   
44   
45   #############################################################################
46   # CLASS METHODS
47   #############################################################################
48   
49   def find_by_code(code)
50     first(:code => code)
51   end
52   
53   # Name output for product suggestion JS
54   # 
55   def suggestion_name
56     "#{self.code}: #{self.name}"
57   end
59 end