【问题标题】:how to add new column and its data for attribute on product list grid on admin panel in magento如何在magento的管理面板上的产品列表网格上添加新列及其属性数据
【发布时间】:2015-09-08 07:30:57
【问题描述】:

我添加了一个新属性“productcategory”,其中包含三个选项用于添加产品模块以选择产品类别并存储在 magento db 中,但如何在产品列表网格中相应地显示 productcategory 列和数据。添加列及其数据我的代码上

    app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php


    $this->addColumn('Product Category',
    array(

'header'=> Mage::helper('catalog')->__('Product Category'),
'index' => 'productcategory',

));

【问题讨论】:

    标签: database magento attributes grid product


    【解决方案1】:

    查找:$collection = Mage::getModel('catalog/product')->getCollection() within the _prepareCollection() 函数。

    并添加:

    ->addAttributeToSelect('productcategory')
    

    【讨论】:

    • 已经完成。但只显示选项 id 而不是选项名称
    • ->getAttributeText('attribute_code')与渲染器一起使用 参考链接inchoo.net/magento/…
    • 我在下面添加了代码以显示属性标签,但过滤器无法处理它受保护的功能 _getAttributeOptions($attribute_code) { $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product ', $attribute_code); $options = 数组(); foreach( $attribute->getSource()->getAllOptions(true, true) as $option ) { $options[$option['value']] = $option['label']; } 返回 $options; }
    • 和下面的代码添加列
      //代码为产品类别添加列 $this->addColumn('Product Category', array('header' =>Mage::helper( 'catalog')->__('Product Category'), 'index' =>'productcategory', 'type' => 'options', 'options' => $this->_getAttributeOptions('productcategory'), )) ; //产品类别的代码结束,但现在过滤器不起作用
    • 使用我的代码和渲染器,我在我的项目中做了很多次。它将始终有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多