Class: Spree::ProductImport
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::ProductImport
- Defined in:
- app/models/spree/product_import.rb
Constant Summary collapse
- ENCODINGS =
%w[UTF-8 iso-8859-1].freeze
Instance Method Summary collapse
- #add_product(product) ⇒ Object
- #destroy_products ⇒ Object
- #parse ⇒ Object
- #product?(product) ⇒ Boolean
- #products ⇒ Object
- #products_count ⇒ Object
- #state_datetime ⇒ Object
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_products ⇒ Object
68 69 70 |
# File 'app/models/spree/product_import.rb', line 68 def destroy_products products.destroy_all end |
#parse ⇒ Object
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
60 61 62 |
# File 'app/models/spree/product_import.rb', line 60 def product?(product) product.id && product_ids.include?(product.id) end |
#products ⇒ Object
52 53 54 |
# File 'app/models/spree/product_import.rb', line 52 def products Product.where(id: product_ids) end |
#products_count ⇒ Object
64 65 66 |
# File 'app/models/spree/product_import.rb', line 64 def products_count parse.product_count end |
#state_datetime ⇒ Object
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 |