Create CSV Magento admin

This tutorial explains how to Create CSV Magento admin. Here I am explaining how to export CSV from Magento admin.


File Structure


Also refer the other tutorials import magento 2 products.

Create CSV Magento admin

Please refer the following code.


Add the following code in the system.xml file.


Block File

class Addpeople_Migrations_Block_Exportproducts extends Mage_Adminhtml_Block_System_Config_Form_Field

    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
        $url = Mage::getModel('adminhtml/url')->getUrl("*/*/exportproducts");
        $html = $this->getLayout()->createBlock('adminhtml/widget_button')
            ->setLabel('Export CSV')

        return $html;


Controller File

class Addpeople_Migrations_System_ConfigController   extends Mage_Adminhtml_Controller_Action
     * Export products in csv format
    public function exportproductsAction()
        $data = array();
        $fileInfo = Mage::getModel('migrations/export_csv')->createCSV($data);


Model Class - Create CSV Code

class Addpeople_Migrations_Model_Export_Csv extends Mage_Core_Model_Abstract
    public function createCSV( $data ) {

        $fileName = 'import_log'.date("Y-m-d").'.csv';

        $headers = ['Weight','Code','Product','SRP (GROSS)','SRP (NET)','30% Discount','Comment'];

        header('Content-Type: application/excel');
        header('Content-Disposition: attachment; filename="' . $fileName . '"');
        $file = fopen('php://output', 'w');
        fputcsv($file, $headers);

        foreach ($data as $row) {

            fputcsv($file, $row);




Config File


Share this Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *