Sha256: 72735c32ddd0336281ba6084a03395b76dffb33858f82bba80a6728aa52f6b04

Contents?: true

Size: 788 Bytes

Versions: 16

Compression:

Stored size: 788 Bytes

Contents

class Piggybak::Sellable < ActiveRecord::Base
  belongs_to :item, :polymorphic => true, :inverse_of => :piggybak_sellable
  attr_accessible :sku, :description, :price, :quantity, :active, :unlimited_inventory, :item_id, :item_type 
  attr_accessible :item # to allow direct assignment from code or console

  validates_presence_of :sku
  validates_uniqueness_of :sku
  validates_presence_of :description
  validates_presence_of :price
  validates_presence_of :item_type
  validates_numericality_of :quantity, :only_integer => true, :greater_than_or_equal_to => 0

  has_many :line_items, :as => :reference, :inverse_of => :reference

  def admin_label
    self.description
  end

  def update_inventory(purchased)
    self.update_attribute(:quantity, self.quantity + purchased)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
piggybak-0.6.34 app/models/piggybak/sellable.rb
piggybak-0.6.33 app/models/piggybak/sellable.rb
piggybak-0.6.32 app/models/piggybak/sellable.rb
piggybak-0.6.31 app/models/piggybak/sellable.rb
piggybak-0.6.30 app/models/piggybak/sellable.rb
piggybak-0.6.29 app/models/piggybak/sellable.rb
piggybak-0.6.28 app/models/piggybak/sellable.rb
piggybak-0.6.27 app/models/piggybak/sellable.rb
piggybak-0.6.26 app/models/piggybak/sellable.rb
piggybak-0.6.25 app/models/piggybak/sellable.rb
piggybak-0.6.24 app/models/piggybak/sellable.rb
piggybak-0.6.23 app/models/piggybak/sellable.rb
piggybak-0.6.22 app/models/piggybak/sellable.rb
piggybak-0.6.21 app/models/piggybak/sellable.rb
piggybak-0.6.20 app/models/piggybak/sellable.rb
piggybak-0.6.19 app/models/piggybak/sellable.rb