Module: Shoppy::Concerns::Models::Promotional

Extended by:
ActiveSupport::Concern
Included in:
Variant
Defined in:
app/models/shoppy/concerns/models/promotional.rb

Instance Method Summary collapse

Instance Method Details

#priceObject



26
27
28
# File 'app/models/shoppy/concerns/models/promotional.rb', line 26

def price
  self.promotional_price? || self.reg_price
end

#price_infoObject



21
22
23
24
# File 'app/models/shoppy/concerns/models/promotional.rb', line 21

def price_info
    p = {reg_price: self.reg_price, promo_price: self.promotional_price?}
    return p
end

#promotional_price?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
# File 'app/models/shoppy/concerns/models/promotional.rb', line 13

def promotional_price?
  if self.promo_price && (self.promo_price > 0) && (self.promo_price_starts_on..self.promo_price_ends_on).cover?(Time.now) && (self.reg_price > self.promo_price)
    return self.promo_price
  else
    return false
  end
end

#set_promotion!(price, begin_date, end_date) ⇒ Object



30
31
32
33
34
35
# File 'app/models/shoppy/concerns/models/promotional.rb', line 30

def set_promotion!(price, begin_date, end_date)
  self.promo_price = price
  self.promo_price_starts_on = begin_date
  self.promo_price_ends_on = end_date
  self.save
end