Class: Spree::Seeds::ApiKeys

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree/seeds/api_keys.rb

Instance Method Summary collapse

Methods included from Spree::ServiceModule::Base

prepended

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/services/spree/seeds/api_keys.rb', line 6

def call
  Spree::Store.find_each do |store|
    unless store.api_keys.active.publishable.where(channel_id: nil).exists?
      store.api_keys.create!(name: 'Default', key_type: 'publishable')
    end

    wholesale = store.channels.find_by(code: Channels::WHOLESALE_CODE)
    if wholesale && !store.api_keys.active.publishable.where(channel: wholesale).exists?
      store.api_keys.create!(name: 'Storefront (Wholesale)', key_type: 'publishable', channel: wholesale)
    end
  end
end