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.

有帮助吗?

解决方案

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

其他提示

Try adding it in manually:

Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToSelect('meta_keyword')
;

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top