0

此页面上,我想直接在项目名称下方添加制造商名称,但似乎无法使其正常工作。尝试了许多建议,但似乎没有一个有效。

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

4

2 回答 2

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 文件中,并将此代码放在同一文件中的最高行号 58 到 63 中 ->addAttributeToSelect('manufacturer')

于 2014-06-07T10:57:11.483 回答
1

试试这个,假设您使用属性集在 Admin -> Catalog -> Manage Attributes 中创建一个“制造商”字段。

编写扩展目录产品块网格 /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>
于 2012-10-03T01:49:14.737 回答