I've got a big product collection about 68.000 items, when I loop through
the collection I'm trying to get all attributes by using $collection->getAttributes()
but it returns nothing.
When I load the products attributes like
$catId=604;
$collection = Mage::getModel('catalog/category')->load($catId)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', $catId)
->addAttributeToFilter('type_id', 'simple')
->addAttributeToFilter('status', 1)->load();
foreach($collection as $col) {
$prod = Mage::getModel('catalog/product')->load($col->getId());
$prod->getAttributes();
}
the performance is horrible so I want to get the attributes by using the collection but it doesn't work at all.
Any suggestions ?
Best Answer
You cannot call
getAttributes()
on$collection
as this is the collection model/object. In your code example you are callinggetAttributes()
on$prod
which is a product model/object.You should remove the line
$prod = Mage::getModel('catalog/product')->load($col->getId());
which is causing a huge load because you are loading every individual product again while they were already loaded.Just call
$col->getAttributes();
right away.By the way, as far as I can see,
getAttributes()
just returns all editable attributes of the product EAV model. So this array is the same for all of your 68.000 products (per attribute set that is). If you need all values in an array, just do$col->getData()