Class: SpreeCmCommissioner::ImportCsvTemplateDownloader

Inherits:
BaseInteractor
  • Object
show all
Defined in:
app/interactors/spree_cm_commissioner/import_csv_template_downloader.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/interactors/spree_cm_commissioner/import_csv_template_downloader.rb', line 5

def call
  headers = case import_type
            when 'new_order'
              initial_headers = %w[order_channel variant_sku quantity email]
              initial_headers + SpreeCmCommissioner::Guest.csv_importable_columns.map(&:to_s)
            when 'existing_order'
              initial_headers = %w[order_number guest_id]
              initial_headers + SpreeCmCommissioner::Guest.csv_importable_columns.map(&:to_s)
            else
              raise ArgumentError, 'Invalid import type'
            end

  filename = 'import_order_csv_template.csv'
  filepath = Rails.root.join('tmp', filename)

  CSV.open(filepath, 'w') do |csv|
    csv << headers
  end

  context.filename = filename
  context.filepath = filepath
end