Class: SnfCore::Order
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SnfCore::Order
- Defined in:
- app/models/snf_core/order.rb
Instance Method Summary collapse
- #cancel! ⇒ Object
- #confirm! ⇒ Object
- #deliver! ⇒ Object
- #process! ⇒ Object
- #ship! ⇒ Object
- #total_amount ⇒ Object
Instance Method Details
#cancel! ⇒ Object
40 41 42 |
# File 'app/models/snf_core/order.rb', line 40 def cancel! update!(status: :cancelled) unless delivered? end |
#confirm! ⇒ Object
24 25 26 |
# File 'app/models/snf_core/order.rb', line 24 def confirm! update!(status: :confirmed) if pending? end |
#deliver! ⇒ Object
36 37 38 |
# File 'app/models/snf_core/order.rb', line 36 def deliver! update!(status: :delivered) if shipped? end |
#process! ⇒ Object
28 29 30 |
# File 'app/models/snf_core/order.rb', line 28 def process! update!(status: :processing) if confirmed? end |
#ship! ⇒ Object
32 33 34 |
# File 'app/models/snf_core/order.rb', line 32 def ship! update!(status: :shipped) if processing? end |
#total_amount ⇒ Object
44 45 46 |
# File 'app/models/snf_core/order.rb', line 44 def total_amount order_items.reload.sum { |item| item.quantity * item.unit_price } end |