2

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.

MeenakshiSundaram R
  • 2,837
  • 3
  • 29
  • 41

3 Answers3

1

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);
0

Try adding it in manually:

Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToSelect('meta_keyword')
;
Andrew
  • 12,617
  • 1
  • 34
  • 48
0

I ran this on my own system and the meta_keyword field did come through.

One difference, however, is that in the first example you are loading the model whereas in the second example you are loading a collection. As such there is a huge difference in the SQL that is being executed.

Kevin Schroeder
  • 1,296
  • 11
  • 23