0

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" Admin grip

asked Feb 15, 2016 at 6:44

2 Answers 2

1

You should override _prepareColumns function inside your custom block

Class abc_Addressmanager_Block_Adminhtml_Stores_Csv extends Mage_Adminhtml_Block_Report_Grid_Abstract {
 protected function _prepareCollection()
 { 
 //please make sure to set collection here and having all columns you want to load in the query
 }
 protected function _prepareColumns()
 {
 //for debuging
 $collection = $this->getCollection();
 //printing the query using this command (if $collection object is set)
 echo $collection->getSelect();
 //making sure the fields you want to show up is in the query output
 //you can add or remove columns here
 } 
}
answered Feb 15, 2016 at 6:57
8
  • Can see my update Commented Feb 15, 2016 at 7:42
  • I am doing as you said Commented Feb 15, 2016 at 7:42
  • could you show up adminhtml grid? Commented Feb 15, 2016 at 7:47
  • you can see it, I can't show full grid, it is too large Commented Feb 15, 2016 at 8:01
  • I added some tips for you above. Hope it helps Commented Feb 15, 2016 at 8:08
0

The block is extending Mage_Adminhtml_Block_Widget_Grid which has this function getCsvFile Now following the calls from there:

  • getCsvFile is calling _exportCsvItem
  • _exportCsvItem calls Mage_Adminhtml_Block_Widget_Grid_Column::getRowFieldExport
  • Now getRowFieldExport calls $this->getRenderer()->renderExport($row);
  • Wich is found in the abstract renderer Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract and calls $this->render($row);

Now in your case it should be the "Select" Renderer which is Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Select you can find the render function there, or it might be another Render, you can insert log code and test which one is it.

answered Feb 15, 2016 at 9:44
1
  • I have debugged my project, it always calls to render() from 'Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Longtext', not from 'Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Select' as you said. Commented Feb 16, 2016 at 4:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.