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链接