Search code examples
magentocollectionsmagento-1.7magento-1.6meta-key

how to get product attribute(all) in "catalog_product" collection?


i want to get all attribute of the product in the product collection.

i've try this

$samp_pro = Mage::getModel('catalog/product')->load(1223)->getData();

it'll load attribute meta keyword.

But when i load it in collection ,doesn't get the meta keyword attribute, the code is

$products1 = Mage::getModel('catalog/product')->getCollection()
                 ->addAttributeToSelect('*')
                 ->addFieldToFilter('meta_keyword', array('like' => '%'.$metaData.'%'))
                 ->addAttributeToSort('name', 'ASC')
                 ->getData();

I need to load meta keyword attribute in collection,help me to fix this issue

Thanks.


Solution

  • Better you will try this below code:

    $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
    
        $sql        = "SELECT * FROM <table-prefix>_catalog_product_entity_text WHERE attribute_id=(SELECT attribute_id FROM <table-prefix>_eav_attribute WHERE attribute_code='meta_keyword') AND value LIKE '%$metaData%'";
    
        $products1       =$connection->fetchAll($sql);