Created
October 19, 2012 16:33
-
-
Save ecogswell/3919204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getCsv() | |
{ | |
$csv = ''; | |
$this->_isExport = true; | |
$this->_prepareGrid(); | |
$sql = (string)$this->getCollection()->getSelect()->__toString(); | |
$db = Mage::getResourceSingleton('core/resource')->getReadConnection(); | |
$result = $db->query($sql); | |
$per_page = 100; | |
$pages = ceil($result->rowCount()/$per_page); | |
$data = array(); | |
foreach ($this->_columns as $column) { | |
if (!$column->getIsSystem()) { | |
$data[] = '"'.$column->getExportHeader().'"'; | |
} | |
} | |
$csv.= implode(',', $data)."\n"; | |
for ($page=1; $page<=$pages; $page++) { | |
$this->getCollection()->setPage($page,$per_page); | |
$this->getCollection()->load(); | |
$this->_afterLoadCollection(); | |
foreach($this->getCollection() as $item) { | |
$data = array(); | |
foreach ($this->_columns as $column) { | |
if (!$column->getIsSystem()) { | |
$data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), | |
$column->getRowFieldExport($item)) . '"'; | |
} | |
} | |
$csv.= implode(',', $data)."\n"; | |
} | |
} | |
if ($this->getCountTotals()) | |
{ | |
$data = array(); | |
foreach ($this->_columns as $column) { | |
if (!$column->getIsSystem()) { | |
$data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), | |
$column->getRowFieldExport($this->getTotals())) . '"'; | |
} | |
} | |
$csv.= implode(',', $data)."\n"; | |
} | |
return $csv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment