Friday, September 22, 2017

Magento 1: How to display customer custom attribute value for selected option in report grid

in Grid.php in method  _prepareColumns()

// get all available options for custom attribute

$options = array();

$attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'attribute_name');
if(!empty($attribute)){
$opts = $attribute->getFrontend()->getSelectOptions();

foreach($opts as $opt){
if(empty($opt['value'])) // skip empty option
continue;
$options[$opt['value']] = $opt['label'];
}
}

// now add column in grid
  
  $this->addColumn('attribute_name', array(
  'header'    => Mage::helper('customer')->__('Some Attribute Name'),
  'index'     => 'attribute_name',
  'type' => 'options',
  'options' => $options  // gere is array with all available options
  ));



P.S. to select attribute value from database, need to open collection.php model for your report and use
->addAttributeToSelect('attribute_name');

I can't provide excat example, because each report may use other classes and method. this was just an example of what function exists, you can find examples in magento to see how it works and where you can use it

No comments:

Post a Comment

Restore xampp database from backup

steps: stop mysql xampp 1 - create some backup folder "data_1"  2 - from your current xampp/mysql/data folder move core folders an...