Я пытаюсь добавить столбец категории в таблицу товаров.
Я изменил Mage_Adminhtml_Block_Catalog_Product_Grid
.
В _prepareCollection добавлено следующее:
:
->joinField('category_ids',
'catalog/category_product_index',
'category_id',
'product_id=entity_id',
null,
'left')
, что выдает ошибку:
a: 5: {i: 0; s: 72: «Элемент (Mage_Catalog_Model_Product) с таким же идентификатором« 16243 »уже существует»
.
В prepareColumns я добавляю:
$this->addColumn('category_ids',
array(
'header'=> Mage::helper('catalog')->__('Categories'),
'index' => 'category_ids',
'width' => '150px'
));
Как можно Я исправлю свой запрос, чтобы не получить ошибку? Можно ли показывать и фильтровать по именам категорий вместо идентификаторов?
В сообщении на форуме показан похожий код, но я не могу заставить его работать с категориями http://www.magentocommerce.com/boards/viewthread/44534/
static protected $COLUMN_ID_TRADE_REFERENCES = 'ref_text';
protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id')
->addAttributeToSelect('ref_text')
->joinTable('productreferences/reference',
'product_id=entity_id',
array('ref_text'),
null,
'left')
->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left')
->addStaticField('ref_text')
->addExpressionAttributeToSelect(self::$COLUMN_ID_TRADE_REFERENCES,
'GROUP_CONCAT(ref_text SEPARATOR " ; ")',
'ref_text')
->groupByAttribute('entity_id');