Skip to content

Commit

Permalink
payment and delivery flags
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiokung committed Sep 7, 2011
1 parent ac7c10e commit 9a50ed8
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions app/models/product.rb
Expand Up @@ -7,17 +7,22 @@ class Product

search_in :name, :description

field :id, :type => Integer
field :name, :type => String
field :price, :type => Integer
field :description, :type => String
field :sold, :type => Boolean
field :id, type: Integer
field :name, type: String
field :price, type: Integer
field :description, type: String
field :buyer, type: String
field :sold, type: Boolean, default: false
field :paid, type: Boolean, default: false
field :delivered, type: Boolean, default: false

validates_presence_of :id, :name, :price

scope :sorted, order_by(:_id => :asc)
scope :sorted, order_by(_id: :asc)
scope :available, where(:sold.ne => true)
scope :sold, where(sold: true)
scope :pending_payment, where(sold: true, paid: false)
scope :pending_delivery, where(sold: true, delivered: false)

def sell_to(name)
self[:buyer] = name
Expand All @@ -26,5 +31,15 @@ def sell_to(name)
self[:delivered] = false
self.save!
end

def pay
self.paid = true
self.save!
end

def deliver
self.delivered = true
self.save!
end
end

0 comments on commit 9a50ed8

Please sign in to comment.