Class: SpreeCmCommissioner::VotePackage::Create

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/vote_package/create.rb

Instance Method Summary collapse

Instance Method Details

#call(params:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/spree_cm_commissioner/vote_package/create.rb', line 6

def call(params:)
  @params = params

  # First build the vote package object
  build_vote_package

  # Prepare data outside transaction to reduce lock time
  assign_store
  assign_season
  
  set_option_value

  # Only include actual database writes in the transaction
  ActiveRecord::Base.transaction do
    save_vote_package
    create_variant
    create_stock_item
  end

  success(vote_package: @vote_package)
rescue StandardError => e
  failure(nil, e.message)
end