I have a multi select attribute in eav_attribute with attribute_code my_managers, its entity_type_code is customer_address, I want to get selected value,,I am trying to export it to csv,in my protected function _prepareColumns() {.....} I am doing this. If single value is selected, it is working fine, but if multiple value are selected, then it shows an empty column.Multi select case is not working properly, other two cases are fine.I am doing this.
class Abc_AddressManager_Block_Adminhtml_Stores_Csv extends Mage_Adminhtml_Block_Widget_Grid {
public function __construct() {
parent::__construct();
$this->setIsExport(true);
$this->setId('customer_address_grid');
$this->setUseAjax(false);
$this->setDefaultSort('store_id');
$this->setSaveParametersInSession(true);
}
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')
);
$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');
if ($code == "additional_managers") {
$x = 0;
}
switch ($attribute->getFrontendInput()) {
case 'select' :
$selectValues = array();
$options = $attribute->getSource()->getAllOptions(false);
foreach ($options as $option) {
$selectValues[$option['value']] = $option['label'];
}
$this->addColumn($code, array(
'header' => $code,
'type' => 'options',
'index' => $code,
'filter' => false,
'sortable' => false,
'options' => $selectValues
));
break;
case 'multiselect' :
$selectValues = array();
$options = $attribute->getSource()->getAllOptions(false);
foreach ($options as $option) {
$selectValues[$option['value']] = $option['label'];
}
$this->addColumn($attribute->getAttributeCode(), array(
'header' => $attribute->getFrontendLabel(),
'type' => 'options',
'index' => $code,
'options' => $selectValues,
'renderer' => 'Abc_AddressManager_Block_Adminhtml_Stores_Render_Store',
));
break;
default :
$this->addColumn($code, array(
'header' => $code,
'type' => 'text',
'index' => $code,
'filter' => false,
'sortable' => false
));
break;
}
} // end
return parent::_prepareColumns();
}
}
And my render is
class Abc_sgAddressManager_Block_Adminhtml_Stores_Render_Store extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{
public function render(Varien_Object $row){
$id = $row->getEntityId();//Here row is csutomer address entity objetct,
//Code will go here
}
}
and one thing more, in db,comma separated values (values of selected options) is saved as shown in pic. enter image description here There one more catch, if I remove case of "multiselect",just values of are shown for multi selected in csv.If selection is multiple, multiple values are show, With current code, it skips multiple selected options
1 Answer 1
$this->addColumn($code, array(
'header' => $attribute->getFrontendLabel(),
'type' => 'options',
'index' => $code,
'options' => $selectValues,
'renderer' => 'Namespace_Modulename_Block_Adminhtml_Code',
));
render block
class Namespace_Modulename_Block_Adminhtml_Code extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$status=$row->getCode();
//you code here
return $value;
}
}
-
I am a little bit confused, in ** function render**, which code should I place,I am exporting it to csv, not to grid viewAbdul Ghaffar– Abdul Ghaffar2016年02月19日 11:30:31 +00:00Commented Feb 19, 2016 at 11:30
-
i know but first it is creating the gird am i right?Qaisar Satti– Qaisar Satti2016年02月19日 11:40:27 +00:00Commented Feb 19, 2016 at 11:40
-
Yes, my class looks like this class Namespace_Modulename_Block_Adminhtml_Stores_Csv extends Mage_Adminhtml_Block_Widget_Grid {...}Abdul Ghaffar– Abdul Ghaffar2016年02月19日 11:49:08 +00:00Commented Feb 19, 2016 at 11:49
-
for renderer use this for
extend Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_AbstractQaisar Satti– Qaisar Satti2016年02月19日 11:53:33 +00:00Commented Feb 19, 2016 at 11:53 -
In render, if I do $row->getEntityId(), I am getting entity id of customer_address_entity, how should I relate it to get values from customer_address_entity_varchar, because I don't have attribute_idAbdul Ghaffar– Abdul Ghaffar2016年02月19日 12:32:51 +00:00Commented Feb 19, 2016 at 12:32
Explore related questions
See similar questions with these tags.