2

Reports->Products Ordered グリッドに新しい製品属性を追加しようとしています。/app/code/core/Mage/Adminhtml/Block/Report/Product/Sold/Grid.phpto をコピーして、次の/app/code/local/Mage/Adminhtml/Block/Report/Product/Sold/Grid.phpような属性を追加しました。

protected function _prepareColumns()
    {
        $this->addColumn('created_at', array(
            'header'    =>Mage::helper('reports')->__('Create At'),
            'index'     =>'created_at'
        ));
        $this->addColumn('sku', array(
            'header'    =>Mage::helper('reports')->__('sku'),
            'index'     =>'sku'
        ));
        $this->addColumn('name', array(
            'header'    =>Mage::helper('reports')->__('Product Name'),
            'index'     =>'name'
        ));
        $this->addColumn('color', array(
            'header'    =>Mage::helper('reports')->__('Color'),
            'index'     =>'color',
            'type'      => 'options'
        ));
        $this->addColumn('size', array(
            'header'    =>Mage::helper('reports')->__('Size'),
            'index'     =>'size'
        ));
        $this->addColumn('price', array(
            'header'    =>Mage::helper('reports')->__('Price'),
            'width'     =>'120px',
            'type'      =>'currency',
            'currency_code' => $this->getCurrentCurrencyCode(),
            'index'     =>'price'
        ));

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

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

        return parent::_prepareColumns();
    }

問題は、「色」と「サイズ」がドロップダウン属性であるため、オプション テキストではなくオプション値が表示されることです。グリッドにドロップダウン属性のテキスト値を表示する方法は?

編集1

BOOMER に感謝します...あなたが提案したように Grid.php を変更し、空白の色の列が表示されるようになりました。私がしたことは次のとおりです。

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('color');

        parent::_prepareCollection();
        $this->getCollection()
            ->initReport('reports/product_sold_collection');
        return $this;
    }

    /**
     * Prepare Grid columns
     *
     * @return Mage_Adminhtml_Block_Report_Product_Sold_Grid
     */
    protected function _prepareColumns()
    {
        $colors = Mage::getResourceModel('eav/entity_attribute_option_collection')
            ->setAttributeFilter(80) // set your attribute ID here
            ->setStoreFilter()
            ->load()
            ->toOptionHash('option_id', 'value');

        $this->addColumn('created_at', array(
            'header'    =>Mage::helper('reports')->__('Create At'),
            'index'     =>'created_at'
        ));
        $this->addColumn('sku', array(
            'header'    =>Mage::helper('reports')->__('sku'),
            'index'     =>'sku'
        ));
        $this->addColumn('name', array(
            'header'    =>Mage::helper('reports')->__('Product Name'),
            'index'     =>'name'
        ));
        $this->addColumn('color', array(
            'header'    =>Mage::helper('reports')->__('Color'),
            'index'     =>'color',
            'type'      => 'options',
            'options' => $colors
        ));
}
4

2 に答える 2

3

_prepareCollection()まず、メソッドで選択する属性を追加していることを確認します。次に例を示します。

$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('color');

そして_prepareColumns()、使用するオプションのコレクションを定義する必要があります。

$colors = Mage::getResourceModel('eav/entity_attribute_option_collection')
            ->setAttributeFilter(15) // set your attribute ID here
            ->setStoreFilter()
            ->load()
            ->toOptionHash('option_id', 'value');

属性 ID を適切に設定してください。次に、次のように addColumns でこのコレクション リストを使用します。

$this->addColumn('color', array(
            'header'    =>Mage::helper('reports')->__('Color'),
            'index'     =>'color',
            'type'      => 'options',
            'options' => $colors
        ));

お役に立てれば!

于 2012-04-30T16:00:36.747 に答える