3

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

3
  • I do not have enough reputation to add the comment...but the above code displays the product name but it does not produce any filter search giving error that 'name' column does not exists.... somehow I end up finding result in adding filter_index but that too didnot helped...can you tell me how to configure it so that I can filter search the product name on grid..?
    – Jijo Nair
    Mar 28, 2016 at 12:21
  • got it...... just add... 'filter_index' => 'value'
    – Jijo Nair
    Mar 28, 2016 at 12:41
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. You can also add a bounty to draw more attention to this question once you have enough reputation. - From Review
    – 7ochem
    Mar 28, 2016 at 13:18

1 Answer 1

8

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.