magento2-module-catalog-import-command icon indicating copy to clipboard operation
magento2-module-catalog-import-command copied to clipboard

How to pass seperators

Open clicktrend opened this issue 8 years ago • 2 comments

How can I pass parameters like "field separator" and "multiple value separator"?

clicktrend avatar Jun 21 '16 10:06 clicktrend

Hello, you found a solution?

psapoznik avatar Sep 13 '16 12:09 psapoznik

It's currently not supported by this module.

To specify a different field separator, you may want to take a look at Model/Import.php file : https://github.com/cedricblondeau/magento2-module-catalog-import-command/blob/master/Model/Import.php#L73.

\Magento\ImportExport\Model\Import\Source\CsvFactory builds a Magento\ImportExport\Model\Import\Source\Csv object. Source\Csv constructor takes delimiter and enclosure parameters (see: https://github.com/magento/magento2/blob/develop/app/code/Magento/ImportExport/Model/Import/Source/Csv.php#L41).

So, I guess you could do something like this:

$csvSource = $this->csvSourceFactory->create(
  [
    'file' => $pathInfo['basename'],
    'directory' => $this->readFactory->create($pathInfo['dirname']),
    'delimiter' => ';',
    'enclosure' => '|'
  ]
);
$validate = $this->importModel->validateSource($csvSource);

cedricblondeau avatar Sep 13 '16 16:09 cedricblondeau