在产品网格中显示类别名称

时间:2014-05-07 08:47:20

标签: magento magento-1.8

我正在尝试在管理网格中显示每个产品的类别名称。我是这样做的,但它确实有效,但我不确定它是否正确:

protected function _prepareCollection()
    {
        /**
         * Tell Magento which collection to use to display in the grid.
         */

        $collection = Mage::getResourceModel(
                'catalog/product_collection'
        );
        $collection ->addAttributeToSelect('sku')
        ->addAttributeToSelect('name')
        ->addAttributeToSelect('type_id');

        $collection->joinTable(
            'catalog/category_product',
            'product_id=entity_id',
            array('my_cat'=>'category_id'),
                null,
                'left'
        );

        $collection->joinTable(
            'catalog_category_entity_varchar',
                'entity_id=my_cat',
                array('mv'=>'value'),
                null,
                'left'
        );
        $collection->groupByAttribute('entity_id');

        $this->setCollection($collection);


        return parent::_prepareCollection();
    }

如果有人能告诉我这是否正确,我会很感激,并且有更好的方法吗?

0 个答案:

没有答案
相关问题