Question

In custom module i m saving product id in my table using that i want to display product name in admin grid

I m trying this code to join table

$collection->getSelect()
    ->joinLeft(
        array('prod' => 'catalog_product_entity'), 
        'prod.entity_id = main_table.mageproduct_id',
        array('sku')
    )
    ->joinLeft(
        array('cpev' => 'catalog_product_entity_varchar'), 
        'cpev.entity_id=main_table.mageproduct_id , 
        array('name' => 'value')
    ); 

I am getting sku but name is not display how to get name

Was it helpful?

Solution

Using join u have to get product name like this

$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.mageproduct_id',
        array('sku')
    )
    ->joinLeft(
        array('cpev' => 'catalog_product_entity_varchar'), 
        'cpev.entity_id=prod.entity_id AND cpev.attribute_id='.$prodNameAttrId.'', 
        array('name' => 'value')
    ); 

This is worked for me hope this will help you

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top