Class: Spree::Orders::Cancel
- Inherits:
-
Object
- Object
- Spree::Orders::Cancel
- Includes:
- ServiceModule::Base
- Defined in:
- app/services/spree/orders/cancel.rb
Constant Summary collapse
- DEFAULT_REASON =
'other'.freeze
Instance Method Summary collapse
-
#call(order:, canceler: nil, canceled_at: nil, reason: DEFAULT_REASON, note: nil, restock_items: false, refund_payments: false, refund_amount: nil, notify_customer: false) ⇒ Spree::ServiceModule::Result
Cancels an order and records a Spree::OrderCancellation history record.
Methods included from ServiceModule::Base
Instance Method Details
#call(order:, canceler: nil, canceled_at: nil, reason: DEFAULT_REASON, note: nil, restock_items: false, refund_payments: false, refund_amount: nil, notify_customer: false) ⇒ Spree::ServiceModule::Result
Cancels an order and records a Spree::OrderCancellation history record. Legacy ‘canceler:` and `canceled_at:` remain valid; new keywords are additive.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/spree/orders/cancel.rb', line 22 def call(order:, canceler: nil, canceled_at: nil, reason: DEFAULT_REASON, note: nil, restock_items: false, refund_payments: false, refund_amount: nil, notify_customer: false) canceled_at ||= Time.current refund_amount ||= order.payment_total if refund_payments order.transaction do order.cancellations.create!( reason: reason, note: note, restock_items: restock_items, refund_payments: refund_payments, refund_amount: refund_amount, notify_customer: notify_customer, canceled_by: canceler, created_at: canceled_at ) changes = { canceled_at: canceled_at } changes[:canceler_id] = canceler.id if canceler.present? order.update_columns(changes) order.cancel! end order.publish_event('order.canceled', order.event_payload.merge(notify_customer: notify_customer)) success(order.reload) rescue ActiveRecord::RecordInvalid, StateMachines::InvalidTransition failure(order) end |