setId('shippingPostdkExportGrid'); $this->_exportPageSize = 10000; } public function setWebsiteId($websiteId) { $this->_websiteId = Mage::app()->getWebsite($websiteId)->getId(); return $this; } public function getWebsiteId() { if (is_null($this->_websiteId)) { $this->_websiteId = Mage::app()->getWebsite()->getId(); } return $this->_websiteId; } public function setConditionName($name) { $this->_conditionName = $name; return $this; } public function getConditionName() { return $this->_conditionName; } protected function _getHelper() { return Mage::helper('pacsoft/rates'); } protected function _getStore() { $storeId = (int) $this->getRequest()->getParam('store', 0); return Mage::app()->getStore($storeId); } protected function _prepareColumns() { parent::_prepareColumns(); $helper = $this->_getHelper(); $this->addColumn('dest_country_id', array( 'header' => $helper->__('Country'), 'index' => 'dest_country_id', 'default' => '*' )); $this->addColumn('dest_region', array( 'header' => $helper->__('Region/State'), 'index' => 'dest_region', 'default' => '*' )); $this->addColumn('dest_city', array( 'header' => $helper->__('City'), 'index' => 'dest_city', 'default' => '*' )); $this->addColumn('dest_zip', array( 'header' => $helper->__('Zip/Postal Code From'), 'index' => 'dest_zip', 'default' => '*' )); $this->addColumn('dest_zip_to', array( 'header' => $helper->__('Zip/Postal Code To'), 'index' => 'dest_zip_to', 'default' => '*' )); $this->addColumn('condition_name', array( 'header' => $helper->__('Condition Name'), 'index' => 'condition_name', 'default' => 'package_value' )); $this->addColumn('condition_from_value', array( 'header' => $helper->__('Condition Value From'), 'index' => 'condition_from_value' )); $this->addColumn('condition_value_to', array( 'header' => $helper->__('Condition Value To'), 'index' => 'condition_to_value' )); $this->addColumn('price', array( 'header' => $helper->__('Price'), 'index' => 'price' )); $this->addColumn('cost', array( 'header' => $helper->__('Cost'), 'index' => 'cost' )); $this->addColumn('service', array( 'header' => $helper->__('Service'), 'index' => 'service' )); $this->addColumn('addons', array( 'header' => $helper->__('Add-ons'), 'index' => 'addons' )); $this->addColumn('title', array( 'header' => $helper->__('Title'), 'index' => 'title' )); $this->addColumn('sort_order', array( 'header' => $helper->__('Sort Order'), 'index' => 'sort_order' )); $this->addColumn('external_id', array( 'header' => $helper->__('External ID'), 'index' => 'external_id' )); return $this; } protected function _prepareCollection() { $websiteId = $this->getWebsiteId(); $collection = Mage::getModel('pacsoft/rate')->getCollection(); $select = $collection->getSelect(); $select->where('active = 1'); if ($websiteId) $select->where('website_id = ?', $websiteId); else $select->where('website_id = -1'); $this->setCollection($collection); return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection(); } public function getCsvFile() { $this->_isExport = true; $this->_prepareGrid(); $io = new Varien_Io_File(); $path = Mage::getBaseDir('var') . DS . 'export' . DS; $name = md5(microtime()); $file = $path . DS . $name . '.csv'; $io->setAllowCreateFolders(true); $io->open(array('path' => $path)); $io->streamOpen($file, 'w+'); $io->streamLock(true); $io->streamWriteCsv($this->_getExportHeaders(),';'); $this->_exportIterateCollection('_exportCsvItem', array($io)); if ($this->getCountTotals()) { $io->streamWriteCsv($this->_getExportTotals(),';'); } $io->streamUnlock(); $io->streamClose(); return array( 'type' => 'filename', 'value' => $file, 'rm' => true // can delete file after use ); } protected function _exportCsvItem(Varien_Object $item, Varien_Io_File $adapter) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowFieldExport($item); } } $adapter->streamWriteCsv($row,';'); } }