magento-engcom / import-export-improvements

Open Software License 3.0
31 stars 29 forks source link

ImportExport - Sample Files in own Modules #53

Open piotrekkaminski opened 6 years ago

piotrekkaminski commented 6 years ago

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/ ### 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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

From @drdrak3 on August 30, 2017 1:55

I'm also after this functionality, any news?

TomashKhamlai commented 6 years ago

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