Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

ImportExport - Sample Files in own Modules #53

Open
piotrekkaminski opened this issue Nov 6, 2017 · 4 comments
Open

ImportExport - Sample Files in own Modules #53

piotrekkaminski opened this issue Nov 6, 2017 · 4 comments

Comments

@piotrekkaminski
Copy link
Contributor

piotrekkaminski commented Nov 6, 2017

From @EliasKotlyar on September 9, 2016 8:29

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

Copied from original issue: magento/magento2#6553

@piotrekkaminski
Copy link
Contributor Author

From @BaDos on September 15, 2016 9:9

Hi @EliasKotlyar

Thank you for reporting.
We've created internal ticket MAGETWO-58483 to resolve this issue.

@piotrekkaminski
Copy link
Contributor Author

From @MathieuJJ on July 25, 2017 5:27

Hi BaDos,
Any news from this issue? I am working on Magento 2 EE 2.14 and my custom sample csv file cannot be downloaded.
Thank you!
Mathieu

@piotrekkaminski
Copy link
Contributor Author

From @drdrak3 on August 30, 2017 1:55

I'm also after this functionality, any news?

@TomashKhamlai
Copy link
Contributor

@dmanners, it's too difficult for me or maybe I misunderstood something.

magento-engcom-team pushed a commit that referenced this issue Aug 27, 2018
MAGETWO-66666: Adding a product to cart from category page with an ex…
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants