Class: Spree::Exchanges::Create

Inherits:
Workflow
  • Object
show all
Includes:
Refunds::TaxCredit, Returns::ReturnableQuantity
Defined in:
app/workflows/spree/exchanges/create.rb

Overview

Opens an exchange request: items coming back, and what should go out in their place.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Workflow

#call, define_argument_readers, #errors, #halt!, hooks, inherited, model_name, #read_attribute_for_validation, #reject!, workflow_key

Methods included from ServiceModule::Base

#call, prepended

Methods included from Workflow::ControlFlow

#failure

Instance Attribute Details

#exchange ⇒ Object (readonly)

Returns the value of attribute exchange.



11
12
13
# File 'app/workflows/spree/exchanges/create.rb', line 11

def exchange
  @exchange
end

Instance Method Details

#perform(order:, items:, stock_location: nil, reason: nil, memo: nil, created_by: nil) ⇒ Object

Parameters:

  • order (Spree::Order)
  • items (Array<Hash>) —

    [{ fulfillment_item:, new_variant:, quantity: }]

  • stock_location (Spree::StockLocation, nil) (defaults to: nil)
  • reason (Spree::ReturnReason, nil) (defaults to: nil)
  • memo (String, nil) (defaults to: nil)
  • created_by (Object, nil) (defaults to: nil) —

    nil for customer self-service



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/workflows/spree/exchanges/create.rb', line 19

def perform(order:, items:, stock_location: nil, reason: nil, memo: nil, created_by: nil)
  super

  step :ensure_exchangeable
  step :normalize_items
  run_hooks :validate

  ApplicationRecord.transaction do
    step :build_exchange
    step :calculate_tax
  end

  run_hooks :after_create
  exchange.publish_event('exchange.requested')
  success(exchange.reload)
end