I have a custom module in admin panel,when I click at "Export" button following function is called. CSV is being exported and downloaded correctly, in CSV one column is having id's instead of value of field.So I just want to changes to the value for that column, But I can't find where data is being dumped into csv file.
class Abc_AddressManager_Adminhtml_StoresController extends
Mage_Adminhtml_Controller_Action {
public function exportCsvAction() {
$fileName = 'stores.csv';
$content = $this->getLayout()->createBlock('abc_addressmanager/adminhtml_stores_csv')
->getCsvFile();
$this->_prepareDownloadResponse($fileName, $content);
}
}
And
class Abc_AddressManager_Block_Adminhtml_Stores_Csv extends Mage_Adminhtml_Block_Widget_Grid
{
protected function _prepareCollection() {
$customer_id = $this->getRequest()->getParam('id');
$collection = Mage::getResourceModel('customer/address_collection');
$collection->addAttributeToSelect('*');
$select = $collection->getSelect();
$select->joinLeft(
array('customer' => $collection->getTable('customer/entity')), 'customer.entity_id=e.parent_id', array('email' => 'email')
);
$d = $collection->getSelect()->__toString();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$addressModel = Mage::getModel('customer/address');
$addressForm = Mage::getModel('customer/form');
$addressForm->setFormCode('adminhtml_customer_address')
->setEntity($addressModel)
->initDefaultValues();
$attributes = $addressForm->getAttributes();
$this->addColumn('email', array(
'header' => 'email',
'type' => 'text',
'index' => 'email',
'filter' => false,
'sortable' => false,
));
$this->addColumn('entity_id', array(
'header' => 'address_id',
'type' => 'text',
'index' => 'entity_id',
'filter' => false,
'sortable' => false,
));
foreach ($attributes as $attribute) {
$code = $attribute->getData('attribute_code');
$this->addColumn($code, array(
'header' => $code,
'type' => 'text',
'index' => $code,
'filter' => false,
'sortable' => false,
));
} // end
return $this;
}
My field Column is "Ownership", that is a customer attribute, type drop down,its attribute_id =554 in eav_attribute table, and option id's are =438 to 443 in eav_attribute_option, and values for option is stored in eav_attribute_option_value,in csv file, column name is Ownership, but its has option id's(438 to 443) in it, instead of their value. My grid look like this.As you can see, Ownership has value(CO), in csv it here I am getting '439' option_id for "CO"
Best Answer
You should override
_prepareColumns
function inside your custom block