Class: Spree::Variants::Update

Inherits:
Workflow
  • Object
show all
Includes:
NestedAttributes
Defined in:
app/workflows/spree/variants/update.rb

Overview

Updates a variant, reconciling the option values, prices and stock levels the payload carries (see Spree::Variants::NestedAttributes — prices replace, stock levels and options upsert).

Handlers reading variant.changes in :validate see the pending edit before it is written.

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 Method Details

#perform(variant:, attributes: {}) ⇒ Spree::ServiceModule::Result

Returns value is the variant.

Parameters:

  • variant (Spree::Variant)
  • attributes (Hash) (defaults to: {}) —

    may carry options, prices, stock_levels

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/workflows/spree/variants/update.rb', line 17

def perform(variant:, attributes: {})
  super

  step :assign_attributes
  run_hooks :validate

  ApplicationRecord.transaction do
    step :save_variant
    step :apply_nested_attributes
    run_hooks :after_update
  end

  success(variant)
end