Description
Preconditions
Happens in all Magento2 Versions.
Steps to reproduce
Try to provide your own Sample file in
/Files/Sample/<yourentity.csv>
Expected result
You can add your own sample-file to your module and it will be taken from the ImportExport Wizard in the Backend
Actual result
The sample file needs to be placed in the Module "ImportExport".
Why it happens?
This happens because of this code:
vendor/magento/module-import-export/Controller/Adminhtml/Import/Download.php
` /**
* Download sample file action
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$fileName = $this->getRequest()->getParam('filename') . '.csv';
$moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, self::SAMPLE_FILES_MODULE);
$fileAbsolutePath = $moduleDir . '/Files/Sample/' . $fileName;
$directoryRead = $this->readFactory->create($moduleDir);
$filePath = $directoryRead->getRelativePath($fileAbsolutePath);
if (!$directoryRead->isFile($filePath)) {
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$this->messageManager->addError(__('There is no sample file for this entity.'));
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath('*/import');
return $resultRedirect;
}
$fileSize = isset($directoryRead->stat($filePath)['size'])
? $directoryRead->stat($filePath)['size'] : null;
$this->fileFactory->create(
$fileName,
null,
DirectoryList::VAR_DIR,
'application/octet-stream',
$fileSize
);
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
$resultRaw->setContents($directoryRead->readFile($filePath));
return $resultRaw;
}`
This Code is taking sample Files only from the ImportExport-Module. There is no way to provide your own sample File.
Greetings
Elias