Sha256: 11adcbc002d08dc627fd3c0028158facfbe0eb229b059d1835c21a552f526205

Contents?: true

Size: 1.87 KB

Versions: 312

Compression:

Stored size: 1.87 KB

Contents

module Caboose
  class GiftCard < ActiveRecord::Base
    self.table_name  = 'store_gift_cards'
    self.primary_key = 'id'
        
    belongs_to :site    
    has_many :discounts
    has_many :invoices, :through => :discounts    
    attr_accessible :id,
      :site_id,      
      :name,  # The name of this discount            
      :code,  # The code the customer has to input to apply for this discount
      :card_type,
      :total,
      :balance,
      :min_invoice_total, # The minimum invoice total required to be able to use the card
      :date_available,
      :date_expires,
      :status            
            
    STATUS_INACTIVE = 'Inactive'
    STATUS_ACTIVE   = 'Active'
    STATUS_EXPIRED  = 'Expired'
    
    CARD_TYPE_AMOUNT      = 'Amount'
    CARD_TYPE_PERCENTAGE  = 'Percentage'
    CARD_TYPE_NO_SHIPPING = 'No Shipping'
    CARD_TYPE_NO_TAX      = 'No Tax'
    
    after_initialize :check_nil_fields
    
    def check_nil_fields
      self.total             = 0.00 if self.total.nil?
      self.balance           = 0.00 if self.balance.nil?          
      self.min_invoice_total = 0.00 if self.min_invoice_total.nil?  
    end

    def valid_for_invoice?(invoice)
      return false if self.status != GiftCard::STATUS_ACTIVE
      return false if self.date_available && DateTime.now.utc < self.date_available
      return false if self.date_expires && DateTime.now.utc > self.date_expires
      return false if self.card_type == GiftCard::CARD_TYPE_AMOUNT && self.balance <= 0      
      return false if self.min_invoice_total && invoice.total < self.min_invoice_total
      return true
    end

  end
end

# Flat amount - $10 off
# Flat amount off if you spend over a certain amount
# Percentage off
# Percentage amount off if you spend over a certain amount
# Free shipping
# Free shipping if you spend over a certain amount
# No Tax
# No tax if you spend over a certain amount

Version data entries

312 entries across 312 versions & 1 rubygems

Version Path
caboose-cms-0.9.229 app/models/caboose/gift_card.rb
caboose-cms-1.0.2 app/models/caboose/gift_card.rb
caboose-cms-1.0.1 app/models/caboose/gift_card.rb
caboose-cms-0.9.228 app/models/caboose/gift_card.rb
caboose-cms-0.9.227 app/models/caboose/gift_card.rb
caboose-cms-0.9.226 app/models/caboose/gift_card.rb
caboose-cms-0.9.225 app/models/caboose/gift_card.rb
caboose-cms-0.9.224 app/models/caboose/gift_card.rb
caboose-cms-0.9.223 app/models/caboose/gift_card.rb
caboose-cms-0.9.222 app/models/caboose/gift_card.rb
caboose-cms-0.9.221 app/models/caboose/gift_card.rb
caboose-cms-0.9.220 app/models/caboose/gift_card.rb
caboose-cms-0.9.219 app/models/caboose/gift_card.rb
caboose-cms-0.9.218 app/models/caboose/gift_card.rb
caboose-cms-0.9.217 app/models/caboose/gift_card.rb
caboose-cms-0.9.216 app/models/caboose/gift_card.rb
caboose-cms-0.9.215 app/models/caboose/gift_card.rb
caboose-cms-0.9.214 app/models/caboose/gift_card.rb
caboose-cms-0.9.213 app/models/caboose/gift_card.rb
caboose-cms-0.9.212 app/models/caboose/gift_card.rb