1

I used following code

$manufacturer_items = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()
    ->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code');

    foreach ($manufacturer_items as $manufacturer_item) :
        if ($manufacturer_item->getAttributeCode() == 'manufacturer')
        $manufacturer_options[$manufacturer_item->getOptionId()] = $manufacturer_item->getValue();
    endforeach;

    $this->addColumn('manufacturer',
        array(
        'header'=> Mage::helper('catalog')->__('Manufacturer'),
        'width' => '100px',
        'type'  => 'options',
        'index' => 'manufacturer',
        'options' => $manufacturer_options,
        ));

But no option value showing in my grid. with help Magento V1.7 Grid View - Add manufacturer attribute to view

Community
  • 1
  • 1
Anwar
  • 43
  • 9

2 Answers2

0

It seems like your options array does not contain valid attribute options. Try following:

$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'manufacturer');
$options = array();
if ($attribute->usesSource()) {
    foreach ($attribute->getSource()->getAllOptions(false) as $option) {
        if ($option['value'] != '') {
            $options[$option['value']] = $option['label'];
        }
    }
}

$this->addColumn('manufacturer', array(
    ...
    'options' => $options,
));

Also, make sure your collection contains manufacturer attribute values.

...
->addAttributeToSelect('manufacturer')
...

Best of luck!

Mladen Ilić
  • 1,667
  • 1
  • 17
  • 21
0

Follow the example from the actual class that renders the grid. That class is Mage_Adminhtml_Block_Catalog_Product_Grid.

Try this for joining the attribute to the collection:

$collection->joinAttribute(
    'manufacturer',
    'catalog_product/manufacturer',
    'entity_id',
    null,
    'left',
    Mage_Core_Model_App::ADMIN_STORE_ID
);

For adding your column to the grid:

$attribute  = Mage::getResourceModel('catalog/product')->getAttribute('manufacturer');
$preOptions = $attribute->getSource()->getAllOptions(false);

$options = array();
foreach($preOptions as $option) {
    if($option['value']) {
        $options[$option['value']] = $option['label'];
    }
}

$this->addColumn('manufacturer', array(
     'header'  => $this->__($attribute->getFrontendLabel()),
     'width'   => '100px',
     'type'    => 'options',
     'index'   => $attribute->getAttributeCode(),
     'options' => $options,
));
Shawn Abramson
  • 701
  • 1
  • 5
  • 18