Magento V1.7网格视图 - 添加制造商属性以进行查看

时间:2012-10-02 23:36:06

标签: magento

this page上我想在项目名称的正下方添加制造商名称,但似乎无法使其生效。已经尝试过一些建议,但似乎没有任何建议。

请具体说明要编辑的文件和行。

2 个答案:

答案 0 :(得分:1)

尝试此操作,假设您使用属性集在管理员中创建“制造商”字段 - >目录 - >管理属性。

编写扩展Catalog Product Block Grid的自定义模块 /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php

创建阻止文件:app / code / local / MageIgniter / ManufacturerGrid / Block / AdminhtmlCatalog / Product / 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(),
    ));

创建助手文件:app / code / local / MageIgniter / ManufacturerGrid / Helper / 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;
   }  

 }

创建:app / code / local / 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>

创建:app / etc / modules / MageIgniter_ManufacturerGrid.xml

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

答案 1 :(得分:1)

$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中 - &GT; addAttributeToSelect(&#39;制造商&#39)