magento Grid 显示下拉菜单属性

在使用grid时自己新建了几个属性,然后其中有一个是下拉单,即deal_status

 protected function _prepareCollection()
    {
        $collection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToSelect('price')
            ->addAttributeToSelect('special_price')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('is_deal')
            ->addAttributeToSelect('deal_status')
            ->addAttributeToFilter('is_deal', true, 'left');

        $this->setCollection($collection);

        parent::_prepareCollection();
        return $this;
    }

解决方案:

 $this->addColumn('deal_status',
            array(
                'header'=> Mage::helper('catalog')->__('Deal Status'),
                'width' => '70px',
                'index' => 'deal_status',
                'type'  => 'options',
                'options' => $this->_getProductAttributeOptions('deal_status')
            ));
  protected function _getProductAttributeOptions($attributeName) {
        $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$attributeName);
        /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
        $attributeOptions = $attribute->getSource()->getAllOptions();
        $options = array();
        // options in key => value Format bringen
        foreach ($attributeOptions as $option) {
            $options[$option['value']] = $option['label'];
        }
        return $options;
    }
原文地址:https://www.cnblogs.com/cangzhou/p/3756549.html