Arnaud de Vslt
Arnaud de Vslt

Reputation: 77

Magento 1.7 - How to add an attribute (choice list that ever exist in manage attributes) in a new admin grid

I have an admin grid Ultimate_Ressources_Model_Ressource which so far have two fields. I would like to add a new one... But the particularity is that it already exist in Manage Attributes and it's a choice field.
So for exemple i have an attribute which code is color and choices are Red/Green/Blue... I would like to propose this field in my grid.

Upvotes: 0

Views: 281

Answers (2)

Arnaud de Vslt
Arnaud de Vslt

Reputation: 77

Thank you !

I have done like this :

$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'color');
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
}
$fieldset->addField('color', 'select', array(
'name'       => 'color',
'label'      => Mage::helper('ressources')->__('My color'),
'title'      => 'title_here',
'values'     => $options,
));

Upvotes: 0

Jakub Korupczyński
Jakub Korupczyński

Reputation: 480

To get attribute options you can try something like this:

$attribute = Mage::getModel('eav/config')->getAttribute('product','color');
$options = $attribute->getSource()->getAllOptions();

Than on your grid you add field and add options from above code. I didn't test it, so you need to try it yourself.

Grid column would look something like this:

$this->addColumn('color', array(
    'index'     => 'color',
    'type'      => 'options',
    'options'   => $options,
));

Upvotes: 1

Related Questions