Sha256: 9593913ae9d43f1ce17d60baf6b595a8a31f44ced81ff1b7a6e8b6b8e33e264e

Contents?: true

Size: 1.59 KB

Versions: 37

Compression:

Stored size: 1.59 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 :orders, :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_order_total, # The minimum order 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'

    def valid_for_order?(order)
      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_order_total && order.total < self.min_order_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

37 entries across 37 versions & 1 rubygems

Version Path
caboose-cms-0.5.106 app/models/caboose/gift_card.rb
caboose-cms-0.5.105 app/models/caboose/gift_card.rb
caboose-cms-0.5.104 app/models/caboose/gift_card.rb
caboose-cms-0.5.103 app/models/caboose/gift_card.rb
caboose-cms-0.5.102 app/models/caboose/gift_card.rb
caboose-cms-0.5.101 app/models/caboose/gift_card.rb
caboose-cms-0.5.100 app/models/caboose/gift_card.rb
caboose-cms-0.5.99 app/models/caboose/gift_card.rb
caboose-cms-0.5.98 app/models/caboose/gift_card.rb
caboose-cms-0.5.97 app/models/caboose/gift_card.rb
caboose-cms-0.5.96 app/models/caboose/gift_card.rb
caboose-cms-0.5.95 app/models/caboose/gift_card.rb
caboose-cms-0.5.94 app/models/caboose/gift_card.rb
caboose-cms-0.5.93 app/models/caboose/gift_card.rb
caboose-cms-0.5.92 app/models/caboose/gift_card.rb
caboose-cms-0.5.91 app/models/caboose/gift_card.rb
caboose-cms-0.5.90 app/models/caboose/gift_card.rb
caboose-cms-0.5.89 app/models/caboose/gift_card.rb
caboose-cms-0.5.88 app/models/caboose/gift_card.rb
caboose-cms-0.5.87 app/models/caboose/gift_card.rb