2

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

2
$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;
    }

}
| improve this answer | |
  • I am a little bit confused, in ** function render**, which code should I place,I am exporting it to csv, not to grid view – Abdul Ghaffar Feb 19 '16 at 11:30
  • i know but first it is creating the gird am i right? – Qaisar Satti Feb 19 '16 at 11:40
  • Yes, my class looks like this class Namespace_Modulename_Block_Adminhtml_Stores_Csv extends Mage_Adminhtml_Block_Widget_Grid {...} – Abdul Ghaffar Feb 19 '16 at 11:49
  • for renderer use this for extend Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract – Qaisar Satti Feb 19 '16 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_id – Abdul Ghaffar Feb 19 '16 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.