zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    mysql触发器
    mysql存储过程
    怎样理解阻塞非阻塞与同步异步的区别?
    常用的排序算法的时间复杂度和空间复杂度
    Struts+Hibernate+Spring面试题合集及答案
    springMVC面试题
    Mybatis面试题合集及答案
    Java基础面试题集(二)
    Java基础面试题集(一)
    Spring----EJB
  • 原文地址:https://www.cnblogs.com/cangzhou/p/3756549.html
Copyright © 2011-2022 走看看