Class: Spree::Catalogs::Create

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

Overview

Creates a catalog, and the price list it prices through when one rides along in the payload. Standing up an agreement is one request: a merchant naming an audience and a discount never has to visit the price-lists page to finish (docs/plans/6.0-catalog-agreement-rework.md).

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

#catalog ⇒ Object (readonly)

Returns the value of attribute catalog.



10
11
12
# File 'app/workflows/spree/catalogs/create.rb', line 10

def catalog
  @catalog
end

Instance Method Details

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

Returns value is the catalog.

Parameters:

  • store (Spree::Store)
  • attributes (Hash) (defaults to: {}) —

    may carry price_list

Returns:



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

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

  step :build_catalog
  run_hooks :validate

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

  success(catalog)
end