Skip to content

ImportExport - Sample Files in own Modules #6553

Closed
@EliasKotlyar

Description

@EliasKotlyar

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

Metadata

Metadata

Assignees

Labels

Component: ImportExportIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentbug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions