Grid.php of your custom module
protected function _prepareCollection() { $collection = Mage::getModel('warranty/stickerid')->getCollection(); // join product table $entityTypeId = Mage::getModel('eav/entity') ->setType('catalog_product') ->getTypeId(); $prodNameAttrId = Mage::getModel('eav/entity_attribute') ->loadByCode($entityTypeId, 'name') ->getAttributeId(); $collection->getSelect() ->joinLeft( array('prod' => 'catalog_product_entity'), 'prod.entity_id = main_table.product_id', array('sku') ) ->joinLeft( array('cpev' => 'catalog_product_entity_varchar'), 'cpev.entity_id=prod.entity_id AND cpev.attribute_id='.$prodNameAttrId.'', array('product_name' => 'value') ); $this->setCollection($collection); return parent::_prepareCollection(); }
Show product name in grid:
protected function _prepareColumns() { $this->addColumn('product_name', array( 'header' => Mage::helper('warranty')->__('Product Name'), 'align' => 'left', 'width' => '120px', 'index' => 'product_name', )); return parent::_prepareColumns(); }
0 Comments