Class: Spree::Exports::ProductTranslations

Inherits:
Spree::Export show all
Defined in:
app/models/spree/exports/product_translations.rb

Constant Summary

Constants inherited from Spree::Export

Spree::Export::SUPPORTED_FILE_FORMATS

Instance Method Summary collapse

Methods inherited from Spree::Export

available_models, available_types, #build_csv_line, #current_ability, #done?, #event_serializer_class, #export_file_name, #export_tmp_file_path, #generate, #generate_async, #handle_attachment, #metafields_headers, model_class, #normalize_search_params, #records_to_export, #send_export_done_email, type_for_model

Instance Method Details

#csv_headersObject



20
21
22
# File 'app/models/spree/exports/product_translations.rb', line 20

def csv_headers
  Spree::CSV::ProductTranslationPresenter::CSV_HEADERS
end

#generate_csvObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/spree/exports/product_translations.rb', line 24

def generate_csv
  locales = store.supported_locales_list - [store.default_locale]
  return super if locales.empty?

  ::CSV.open(export_tmp_file_path, 'wb', encoding: 'UTF-8', col_sep: ',', row_sep: "\r\n") do |csv|
    csv << csv_headers
    records_to_export.includes(scope_includes).find_in_batches do |batch|
      batch.each do |product|
        product.to_translation_csv(store, locales).each do |line|
          csv << line
        end
      end
    end
  end
end

#model_classObject



40
41
42
# File 'app/models/spree/exports/product_translations.rb', line 40

def model_class
  Spree::Product
end

#multi_line_csv?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/models/spree/exports/product_translations.rb', line 8

def multi_line_csv?
  true
end

#scopeObject



12
13
14
15
16
17
18
# File 'app/models/spree/exports/product_translations.rb', line 12

def scope
  if search_params.nil?
    super.where.not(status: 'archived')
  else
    super
  end
end

#scope_includesObject



4
5
6
# File 'app/models/spree/exports/product_translations.rb', line 4

def scope_includes
  []
end