Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 在产品网格中显示类别名称_Magento_Magento 1.8 - Fatal编程技术网

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

Magento 在产品网格中显示类别名称,magento,magento-1.8,Magento,Magento 1.8,我试图在管理网格中显示每个产品的类别名称。我是这样做的,而且很有效,但我不确定这样做是否正确: protected function _prepareCollection() { /** * Tell Magento which collection to use to display in the grid. */ $collection = Mage::getResourceModel(

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

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();
    }

如果有人能告诉我这是正确的,我将不胜感激,还有更好的方法吗?

将您的代码与以下内容中的答案进行比较:。那一个有用,谢谢你,马吕斯。这有帮助!检查stackoverflow.com/questions/3472702/add-categories-column-to-the-product-grid-in-magento-admin链接