Reputation: 1
I have product id
. database field name productid
in custom module
I want to show product name on custom module list view.
Here is my code:
protected function _prepareColumns() {
$this->addColumn('productid', array(
'header' => Mage::helper('productpdf')->__('productid'),
'align' => 'center',
'index' => 'productid',
));
}
Upvotes: 0
Views: 2378
Reputation: 420
Instead of using too much bunch of code, add below code in your model/productpdf.php file.
/**
* @param int $productId.
* @return product name.
*/
public function getProductNameById($productId)
{
$query_select = "SELECT value FROM `".Mage::getConfig()->getTablePrefix()."catalog_product_entity_varchar` WHERE
entity_id = '".$productId."' AND `attribute_id` = 71";
return $data = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($query_select);
}
Now just call this function in your file.
$productNameArray = Mage::getModel('productpdf/productpdf')->getProductNameById($productId);
Add new column for display product name
$this->addColumn('name', array(
'header' => Mage::helper('productpdf')->__('Name'),
'width' => '150',
'index' => $productNameArray[0]['value']
));
Cheers!!
Upvotes: 1
Reputation: 525
For this You have to separately create the collection(or in your existing collection include the below query) for get product name from product id..
You can do like this
protected function _prepareCollection()
{
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name');
$collection->addAttributeToFilter('productid');
}
protected function _prepareColumns()
{
$this->addColumn('productid', array(
'header' => Mage::helper('productpdf')->__('productid'),
'align' =>'center',
'index' =>'productid',
));
$this->addColumn('name', array(
'header' => Mage::helper('productpdf')->__('Name'),
'width' => '150',
'index' => 'name'
));
}
In addAttributeToFilter('productid') you have to pass your product id. Hope this work:-)
Upvotes: 3