Question

We recently upgraded our website to Magento 2.4, but we have run into an issue with trying to import products using the import tool. When we upload a csv that has errors in it, we want to download the error report to see what those issues are. However, when we try to click on the download button the following error appears in the exception log.

[2020-10-01 14:44:43] main.CRITICAL: Path "/var/www/production/var/importexport//0ioMiFS6xCv06A0XOyQQSxGMKhKTAMcr.csv" cannot be used with directory "/var/www/production/pub/media/" {"exception":"[object] (Magento\\Framework\\Exception\\ValidatorException(code: 0): Path \"/var/www/production/var/importexport//0ioMiFS6xCv06A0XOyQQSxGMKhKTAMcr.csv\" cannot be used with directory \"/var/www/production/pub/media/\" at /var/www/production/vendor/magento/framework/Filesystem/Directory/PathValidator.php:63)"} []
Was it helpful?

Solution

I found that the error reports were not being generated while investigating the download process. I resolved the by copying the working code from the repository and updating the file "vendor\magento\module-import-export\Model\Report\Csv.php"

Inside the csv.php file is the method createReport. I replaced the contents of this method with the following code obtained from the current magento repository

$outputCsv = $this->outputCsvFactory->create();

$sourceCsv = $this->createSourceCsvModel($originalFileName);
$columnsName = $sourceCsv->getColNames();
$columnsName[] = self::REPORT_ERROR_COLUMN_NAME;
$outputCsv->setHeaderCols($columnsName);

foreach ($sourceCsv as $rowNum => $rowData) {
    $errorMessages = $this->retrieveErrorMessagesByRowNumber($rowNum, $errorAggregator);
    if (!$writeOnlyErrorItems || ($writeOnlyErrorItems && $errorMessages)) {
        $rowData[self::REPORT_ERROR_COLUMN_NAME] = $errorMessages;
        $outputCsv->writeRow($rowData);
    }
}

$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$outputFileName = $this->generateOutputFileName($originalFileName);
$directory->writeFile(Import::IMPORT_HISTORY_DIR . $outputFileName, $outputCsv->getContents());

return $outputFileName;
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top