Class: Spree::Catalogs::Update

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

Overview

Updates a catalog, and the price list it prices through when one rides along in the payload (docs/plans/6.0-catalog-agreement-rework.md).

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(catalog:, attributes: {}) ⇒ Spree::ServiceModule::Result

Returns value is the catalog.

Parameters:

  • catalog (Spree::Catalog)
  • attributes (Hash) (defaults to: {}) —

    may carry price_list, assignments and order_minimums — small bounded sets the agreement editor saves with the catalog, so the whole agreement lands in one transaction rather than a sequence a failure can leave half applied

Returns:



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

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

  step :assign_attributes
  run_hooks :validate

  ApplicationRecord.transaction do
    step :save_catalog
    step :apply_price_list
    step :apply_assignments
    step :apply_order_minimums
    run_hooks :after_update
  end

  success(catalog)
end