Magento的V1.7网格视图 - 添加制造商属性,查看(Magento V1.7 Grid Vi

2019-08-01 02:31发布

在这个页面我想直接添加以下项目的名称厂家名称,但似乎无法得到这个工作。 已经尝试了一些建议,但没有一个似乎工作。

请具体说明对文件和线条进行编辑。

Answer 1:

试试这个,假设你正在使用属性设置中的管理员可以创建一个“制造商”字段 - >目录 - >管理属性。

编写扩展目录产品块网格/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php自定义模块

创建块文件:应用程序/代码/本地/ MageIgniter / ManufacturerGrid /座/ AdminhtmlCatalog /产品/ Grid.php

class MageIgniter_ManufacturerGrid_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
 {

复制方法_prepareCollection()给你定制模块和更新(58行)

 $collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('sku')
        ->addAttributeToSelect('name')
        ->addAttributeToSelect('manufacturer')   // added this line
        ->addAttributeToSelect('attribute_set_id')
        ->addAttributeToSelect('type_id');

复制方法_prepareColumns()到你的自定义模块,并添加

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

创建辅助文件:应用程序/代码/本地/ MageIgniter / ManufacturerGrid /助手/ Data.php

 class MageIgniter_ManufacturerGrid_Helper_Data extends Mage_Core_Helper_Abstract
 {

    public function getManufacturerOption(){
       $_opt = array();
       foreach (Mage::getModel('eav/config')->getAttribute('catalog_product','manufacturer')->getSource()->getAllOptions(false,true) as $option){
           $_opt[$option['value']] = $option['label'];
       }

    return $_opt;
   }  

 }

创建:应用程序/代码/本地/ MageIgniter / ManufacturerGrid的/ etc / config.xml中

<config>
  <modules>
    <MageIgniter_ManufacturerGrid>
        <version>1.0.0</version>
    </MageIgniter_ManufacturerGrid>    
  </modules>

  <global>
      <blocks>
        <adminhtml>
            <rewrite>
            <catalog_product_grid>MageIgniter_ManufacturerGrid_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
            </rewrite>
        </adminhtml>
      </blocks>
    <helpers>
        <localship>
            <class>MageIgniter_ManufacturerGrid_Helper</class>
        </localship>
    </helpers>
  </global>
 </config>

创建:应用程序的/ etc /模块/ MageIgniter_ManufacturerGrid.xml

  <?xml version="1.0"?>
    <config>
           <modules>
                  <MageIgniter_ManufacturerGrid>
                          <active>true</active>
                          <codePool>local</codePool>
                  </MageIgniter_ManufacturerGrid>
           </modules>
    </config>


Answer 2:

$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,
        ));

放在Gird.php文件此代码,该代码在apoximate行号58到63中相同的文件 - > addAttributeToSelect('制造商)



文章来源: Magento V1.7 Grid View - Add manufacturer attribute to view
标签: magento