Extensive Namespacing of model code, renamed abstract class.
[merb_mart.git] / app / models / promotion.rb
blob97ec99925fea13c8861dff1ee08dfda2cd9c49fb
1 require 'validate'
3 module Mart
4   module Store
5     class Promotion
6   
7       include DataMapper::Resource
8       include DataMapper::Validate
10       TYPES = {
11         'Dollars' => 0,
12         'Percent of total order' => 1,
13         'Buy [n] get 1 free' => 2
14       }
15   
16       property :id,               Fixnum,   :serial => true
17       property :code,             String,   :length => 15,                  :nullable => false
18       property :discount_type,    Fixnum,                  :default => 0,   :nullable => false
19       property :discount_amount,  Float,                   :default => 0.0, :nullable => false
20       property :start,            DateTime,                                 :nullable => false
21       property :end,              DateTime,                                 :nullable => false
22       property :minimum_cart_value, Float
23       property :description,      String,                                   :nullable => false
24       property :store_item_id,    Fixnum  # foreign-key
26       one_to_many :orders
27       many_to_one :store_item_id
28   
29       validates_presence_of :code, :discount_amount, :discount_type, :description
30       validates_numericalnes_of :discount_amount  
32     end
33   end
34 end