Class: Spree::ProductImport

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/product_import.rb

Constant Summary collapse

ENCODINGS =
%w[UTF-8 iso-8859-1].freeze

Instance Method Summary collapse

Instance Method Details

#add_product(product) ⇒ Object



56
57
58
# File 'app/models/spree/product_import.rb', line 56

def add_product(product)
  product_ids << product.id unless product?(product)
end

#destroy_productsObject



68
69
70
# File 'app/models/spree/product_import.rb', line 68

def destroy_products
  products.destroy_all
end

#parseObject



48
49
50
# File 'app/models/spree/product_import.rb', line 48

def parse
  @_parse ||= SolidusImportProducts::Parser.parse(:csv, data_file.url(:default, timestamp: false), { encoding_csv: encoding_csv, separator_char: separatorChar })
end

#product?(product) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/spree/product_import.rb', line 60

def product?(product)
  product.id && product_ids.include?(product.id)
end

#productsObject



52
53
54
# File 'app/models/spree/product_import.rb', line 52

def products
  Product.where(id: product_ids)
end

#products_countObject



64
65
66
# File 'app/models/spree/product_import.rb', line 64

def products_count
  parse.product_count
end

#state_datetimeObject



72
73
74
75
76
77
78
79
80
# File 'app/models/spree/product_import.rb', line 72

def state_datetime
  if failed?
    failed_at
  elsif completed?
    completed_at
  else
    updated_at
  end
end