Class: Crm::Amazon::DatadiveImportsController

Inherits:
CrmController
  • Object
show all
Defined in:
app/controllers/crm/amazon/datadive_imports_controller.rb

Overview

Controller for importing Amazon listing data from DataDive flat file exports

Instance Method Summary collapse

Instance Method Details

#previewObject

POST /amazon_datadive_imports/:id/preview
Parses the pasted data and shows comparison



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/crm/amazon/datadive_imports_controller.rb', line 17

def preview
  # rubocop:disable Style/OpenStructUse
  @job = OpenStruct.new(params[:job])
  # rubocop:enable Style/OpenStructUse
  parser = Amazon::DatadiveImportParser.new
  result = parser.parse(@job.raw_data)

  if result.success?
    populate_job_from_result(result)
    initialize_save_flags
  else
    flash.now[:error] = result.error
    render :prompt, status: :unprocessable_entity
  end
end

#promptObject

GET /amazon_datadive_imports/:id/prompt
Shows the form to paste DataDive export data



9
10
11
12
13
# File 'app/controllers/crm/amazon/datadive_imports_controller.rb', line 9

def prompt
  # rubocop:disable Style/OpenStructUse
  @job = OpenStruct.new
  # rubocop:enable Style/OpenStructUse
end

#saveObject

POST /amazon_datadive_imports/:id/save
Saves the imported data as specifications



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/crm/amazon/datadive_imports_controller.rb', line 35

def save
  # rubocop:disable Style/OpenStructUse
  @job = OpenStruct.new(params[:job])
  # rubocop:enable Style/OpenStructUse
  @link_to_product_line = @job.link_to_product_line.to_b
  target_locale = @job.target_locale.presence || Mobility.locale

  Mobility.with_locale(target_locale) do
    save_all_specs
  end

  @item.update_rendered_product_specifications(locales: [target_locale])
  flash[:success] = 'Amazon specifications imported successfully from DataDive'
  redirect_to item_path(@item, tab: 'amazon')
end