Skip to content

Allow custom SolidusImporter::Import strategy to read CSV files #61

@cesartalves

Description

@cesartalves

Right now SolidusImporter::ProcessImport is reading the CSV file by doing a File.read on the import file path.

def scan
      data = CSV.parse(
        File.read(@import.file.path),
        headers: true,
        encoding: 'UTF-8',
        header_converters: ->(h) { h.strip }
      )
      prepare_rows(data)
end

However, on some projects that path may not be available depending on which customizations have been applied to Paperclip or ActiveStorage.
On a project I'm working on the files are sent directly to AWS, even on development, and their bucket path is interpolated in such a way that the @import.file local path can't be determined.

Therefore it would be useful to allow user-customizable strategies for reading the content from the file. E.g.:

SolidusImporter.config do |c|
  c.import_file_reader = -> (import) {
     open(@import.file.public_url)
  }
end

def scan
      raw_content = SolidusImporter::Config.import_file_reader.call(@import)
      data = CSV.parse(
        raw_content,
        headers: true,
        encoding: 'UTF-8',
        header_converters: ->(h) { h.strip }
      )
      prepare_rows(data)
end

Or any other approach may also be viable as long as we allow this to me easily customizable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions