Add attribute set column to magento products order

2019-08-09 07:42发布

问题:

I want to add a column to the magento products ordered report that will display the attribute set name for each product.

I have added the SKU and coverage attribute but struggling with the attribute set name.

This is what i currently have:

protected function _prepareColumns()
{
    $this->addColumn('sku', array(
        'header'    =>Mage::helper('reports')->__('sku'),
        'index'     =>'sku'
    ));

    $this->addColumn('name', array(
        'header'    =>Mage::helper('reports')->__('Product Name'),
        'index'     =>'order_items_name'
    ));

    $this->addColumn('ordered_qty', array(
        'header'    =>Mage::helper('reports')->__('Quantity Ordered'),
        'width'     =>'120px',
        'align'     =>'right',
        'index'     =>'ordered_qty',
        'total'     =>'sum',
        'type'      =>'number'
    ));

    $this->addColumn('coverage', array(
        'header'    =>Mage::helper('reports')->__('coverage'),
        'index'     =>'coverage'
    ));


    $this->addExportType('*/*/exportSoldCsv', Mage::helper('reports')->__('CSV'));
    $this->addExportType('*/*/exportSoldExcel', Mage::helper('reports')->__('Excel XML'));

    return parent::_prepareColumns();

回答1:

$attrSet = Mage::getResourceModel('eav/entity_attribute_set_collection')->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())->toOptionHash();

$this->addColumnAfter('set_name',
    array(
        'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
        'width' => '100px',
        'index' => 'attribute_set_id',
        'type'  => 'options',
        'options' => $attrSet,
), 'name');