Class: Spree::Exports::Products

Inherits:
Spree::Export show all
Defined in:
app/models/spree/exports/products.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?, #export_file_name, #export_tmp_file_path, #generate, #generate_async, #generate_csv, #handle_attachment, #model_class, model_class, #records_to_export, #send_export_done_email, type_for_model

Instance Method Details

#csv_headersObject



26
27
28
# File 'app/models/spree/exports/products.rb', line 26

def csv_headers
  @csv_headers ||= Spree::CSV::ProductVariantPresenter::CSV_HEADERS + properties_headers
end

#multi_line_csv?Boolean



13
14
15
# File 'app/models/spree/exports/products.rb', line 13

def multi_line_csv?
  true
end

#properties_headersObject



30
31
32
# File 'app/models/spree/exports/products.rb', line 30

def properties_headers
  @properties_headers ||= Spree::Property.order(:position).count.times.flat_map { |n| ["property#{n + 1}_name", "property#{n + 1}_value"] }
end

#scopeObject

when doing full product export, we want to exclude archived products



18
19
20
21
22
23
24
# File 'app/models/spree/exports/products.rb', line 18

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

#scope_includesObject

to avoid N+1 queries



5
6
7
# File 'app/models/spree/exports/products.rb', line 5

def scope_includes
  [:tax_category, :master, { taxons: :taxonomy }, { product_properties: [:property] }, { variants_including_master: variant_includes }]
end

#variant_includesObject



9
10
11
# File 'app/models/spree/exports/products.rb', line 9

def variant_includes
  [:images, :prices, :stock_items, { option_values: [:option_type] }]
end