I followed steps in this topic Magento 2 run native product csv import programtically, but it didn't work. When I try to import product through a CSV file in back-office, the check data is correct and the import too. But, when I try to use the same file in my custom module, the check data function (validateSource) gives me an error.

I think I didn't upload the CSV file correctly.

I put it in a personal folder, then I copy it in /var/importexport/ renamed as catalog_product.csv. The function importSource seems to work but no product is imported, and the file isn't copied in /var/import_history/.

In my function, I got an argument that is the file path of my CSV file. My code :

$dataImport = 

$newFilvecsv = "/root/var/importexport/catalog_product.csv";
copy($filecsv->getFilepath(), $newFilvecsv);

$importModel = $this->importModelFactory->create();

$source = $this->importAdapter->findAdapterFor(
$isValid = $importModel->validateSource($source);

if ($importModel->getProcessedRowsCount() === 0 || $importModel->getErrorAggregator()->getErrorsCount() || !$isValid){ // Fichier non valide

try {
} catch (\Exception $e) {
    $this->logger->info("Import impossible");

return "Import fini";

I'm lost. Can you help me ?

  • Did you find a solution for this? – SebastianT Jan 10 '20 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.