Module: Stall::Models::ProductList
- Extended by:
- ActiveSupport::Concern
- Included in:
- ProductList
- Defined in:
- app/models/stall/models/product_list.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #active? ⇒ Boolean
- #checkoutable? ⇒ Boolean
- #currency ⇒ Object
- #eot_subtotal ⇒ Object
- #reset_state! ⇒ Object
- #state ⇒ Object
- #subtotal ⇒ Object
- #to_param ⇒ Object
- #total_eot_price ⇒ Object
- #total_price ⇒ Object
- #total_quantity ⇒ Object
- #total_vat ⇒ Object
- #wizard ⇒ Object
Instance Method Details
#active? ⇒ Boolean
90 91 92 |
# File 'app/models/stall/models/product_list.rb', line 90 def active? true end |
#checkoutable? ⇒ Boolean
86 87 88 |
# File 'app/models/stall/models/product_list.rb', line 86 def checkoutable? line_items.length > 0 end |
#currency ⇒ Object
94 95 96 97 98 99 100 |
# File 'app/models/stall/models/product_list.rb', line 94 def currency @currency ||= if (currency = read_attribute(:currency).presence) Money::Currency.new(currency) else self.currency = Money.default_currency end end |
#eot_subtotal ⇒ Object
60 61 62 |
# File 'app/models/stall/models/product_list.rb', line 60 def eot_subtotal line_items.map(&:eot_price).sum end |
#reset_state! ⇒ Object
45 46 47 48 |
# File 'app/models/stall/models/product_list.rb', line 45 def reset_state! self.state = wizard.steps.first save(validate: false) if persisted? end |
#state ⇒ Object
41 42 43 |
# File 'app/models/stall/models/product_list.rb', line 41 def state read_attribute(:state).try(:to_sym) end |
#subtotal ⇒ Object
54 55 56 57 58 |
# File 'app/models/stall/models/product_list.rb', line 54 def subtotal price = line_items.map(&:price).sum price = Money.new(price, currency) unless Money === price price end |
#to_param ⇒ Object
50 51 52 |
# File 'app/models/stall/models/product_list.rb', line 50 def to_param persisted? ? token : 'empty-cart' end |
#total_eot_price ⇒ Object
70 71 72 |
# File 'app/models/stall/models/product_list.rb', line 70 def total_eot_price items.map(&:eot_price).sum end |
#total_price ⇒ Object
64 65 66 67 68 |
# File 'app/models/stall/models/product_list.rb', line 64 def total_price price = items.map(&:price).sum price = Money.new(price, currency) unless Money === price price end |
#total_quantity ⇒ Object
78 79 80 |
# File 'app/models/stall/models/product_list.rb', line 78 def total_quantity line_items.map(&:quantity).sum end |
#total_vat ⇒ Object
74 75 76 |
# File 'app/models/stall/models/product_list.rb', line 74 def total_vat items.map(&:vat).sum end |
#wizard ⇒ Object
82 83 84 |
# File 'app/models/stall/models/product_list.rb', line 82 def wizard @wizard ||= self.class.wizard end |