Class: Caboose::GiftCard

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/caboose/gift_card.rb

Constant Summary collapse

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'

Instance Method Summary collapse

Instance Method Details

#check_nil_fieldsObject



32
33
34
35
36
# File 'app/models/caboose/gift_card.rb', line 32

def check_nil_fields
  self.total           = 0.00 if self.total.nil?
  self.balance         = 0.00 if self.balance.nil?          
  self.min_order_total = 0.00 if self.min_order_total.nil?  
end

#valid_for_order?(order) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'app/models/caboose/gift_card.rb', line 38

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