Class: Spree::SalePrice
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::SalePrice
- Defined in:
- app/models/spree/sale_price.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
- #calculated_price ⇒ Object
-
#calculator_type ⇒ Object
TODO make this work or remove it def self.calculators Rails.application.config.spree.calculators.send(self.to_s.tableize.gsub(‘/’, ‘_’).sub(‘spree_’, ”)) end.
- #disable ⇒ Object
-
#display_price ⇒ Object
Convenience method for displaying the price of a given sale_price in the table.
- #enable ⇒ Object
- #start(end_time = nil) ⇒ Object
- #stop ⇒ Object
Instance Method Details
#active? ⇒ Boolean
37 38 39 |
# File 'app/models/spree/sale_price.rb', line 37 def active? Spree::SalePrice.active.include? self end |
#calculated_price ⇒ Object
25 26 27 |
# File 'app/models/spree/sale_price.rb', line 25 def calculated_price calculator.compute self end |
#calculator_type ⇒ Object
TODO make this work or remove it def self.calculators
Rails.application.config.spree.calculators.send(self.to_s.tableize.gsub('/', '_').sub('spree_', ''))
end
21 22 23 |
# File 'app/models/spree/sale_price.rb', line 21 def calculator_type calculator.class.to_s if calculator end |
#disable ⇒ Object
33 34 35 |
# File 'app/models/spree/sale_price.rb', line 33 def disable update_attribute(:enabled, false) end |
#display_price ⇒ Object
Convenience method for displaying the price of a given sale_price in the table
53 54 55 |
# File 'app/models/spree/sale_price.rb', line 53 def display_price Spree::Money.new(value || 0, { currency: price.currency }) end |
#enable ⇒ Object
29 30 31 |
# File 'app/models/spree/sale_price.rb', line 29 def enable update_attribute(:enabled, true) end |
#start(end_time = nil) ⇒ Object
41 42 43 44 45 46 |
# File 'app/models/spree/sale_price.rb', line 41 def start(end_time = nil) end_time = nil if end_time.present? && end_time <= Time.now # if end_time is not in the future then make it nil (no end) attr = { end_at: end_time, enabled: true } attr[:start_at] = Time.now if self.start_at.present? && self.start_at > Time.now # only set start_at if it's not set in the past update_attributes(attr) end |
#stop ⇒ Object
48 49 50 |
# File 'app/models/spree/sale_price.rb', line 48 def stop update_attributes({ end_at: Time.now, enabled: false }) end |