Magento – Store product export csv file in var/importexport folder

exportimportexportmagento-1.8

I want to store the product export csv file on a folder while generating from the admin panel.

Right now its only directly downloadable from the admin panel, but I want to store that file in a particular folder like "var/importexport".

Please advise.

Best Answer

You have to modify Mage_ImportExport_Adminhtml_ExportController::exportAction (of course don't change the file directly, but overwrite the controller update safe).

Change this part:

            return $this->_prepareDownloadResponse(
                $model->getFileName(),
                $model->export(),
                $model->getContentType()
            );

to:

            $filename = $model->getFileName();
            $content = $model->export();
            file_put_contents(Mage::getBaseDir('var') . DS . 'importexport' . DS . $filename, $content);
            return $this->_prepareDownloadResponse(
                $filename,
                $content,
                $model->getContentType()
            );

This should save the file in the given directory. Of course you can modify the filename $filename at that point.

Related Topic