0

I have overridden Mage_Adminhtml_Block_Catalog_Product_Grid and added the export functionality like below :

protected function _prepareColumns()
{
    $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
    $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('XML'));
    parent::_prepareColumns();
}

and also overridden Mage_Adminhtml_Catalog_ProductController and added the exportCsv and exportXml actions :

/**
     * Export product grid to CSV format.
     */
    public function exportCsvAction()
    {
        $fileName   = 'products.csv';
        $content    = $this->getLayout()->createBlock('enhancedgrid/catalog_product_grid')
            ->getCsv();

        $this->_sendUploadResponse($fileName, $content);
    }

    /**
     * Export product grid to XML format.
     */
    public function exportXmlAction()
    {
        $fileName   = 'products.xml';
        $content    = $this->getLayout()->createBlock('enhancedgrid/catalog_product_grid')
            ->getXml();

        $this->_sendUploadResponse($fileName, $content);
    }

    protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream')
    {
        $response = $this->getResponse();
        $response->setHeader('HTTP/1.1 200 OK', '');

        $response->setHeader('Pragma', 'public', true);
        $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);

        $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
        $response->setHeader('Last-Modified', date('r'));
        $response->setHeader('Accept-Ranges', 'bytes');
        $response->setHeader('Content-Length', strlen($content));
        $response->setHeader('Content-type', $contentType);
        $response->setBody($content);
        $response->sendResponse();
    }

The csv is generated fine. But the issue is there are only 20 records in the csv that is exported. I want all the products to be exported. Can anyone suggest what is the issue ? Thanks in Advance.

  • My guess would be that a problem with the 21st record, maybe special characters? I've had my imports fail over the micron symbol. Anything like that? – LM_Fielding Apr 5 '17 at 14:14
  • No, i think it is due to the no of records displayed in the grid. when i select 50 records per page, the export csv contains 50 records – Manashvi Birla Apr 5 '17 at 14:17
0

Number of products loaded in grid will be always equal to number of products exported in csv.

Default view of grid is 20 products. Now change the view of grid to 200.

You can export 200 products in csv. Try this, you issue will be resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.