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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spree::Export

available_models, available_types, #build_csv_line, #current_ability, #decode_prefixed_id_filters, #decode_search_value, #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

Class Method Details

.required_scopeObject



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

def self.required_scope
  :products
end

Instance Method Details

#csv_headersObject



24
25
26
# File 'app/models/spree/exports/product_translations.rb', line 24

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

#generate_csvObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/spree/exports/product_translations.rb', line 28

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 << Spree::CSV::FormulaSanitizer.row(line)
        end
      end
    end
  end
end

#model_classObject



44
45
46
# File 'app/models/spree/exports/product_translations.rb', line 44

def model_class
  Spree::Product
end

#multi_line_csv?Boolean

Returns:

  • (Boolean)


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

def multi_line_csv?
  true
end

#scopeObject



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

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

#scope_includesObject



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

def scope_includes
  []
end