How can I get a catalog/product
collection with all attributes which are selected to be "used in product listing", i.e. are in the flat table?
2 Answers
$collection
->addAttributeToSelect(
Mage::getSingleton('catalog/config')->getProductAttributes()
);
This is for example used in Mage_Catalog_Model_Layer::prepareProductCollection
.
-
Is this not equivalent with
$collection->addAttributeToSelect('*');
Commented Feb 12, 2013 at 15:49 -
1no it is not. It get all the attributes which are marked as
used_in_product_listing
Commented Feb 13, 2013 at 0:27 -
Looks like
Mage::getSingleton('catalog/config')->getProductAttributes()
doesn't include all flat attributes. Still missing some attributes. Use the flat reindexer Model instead to get exactly attributes that are in Flat table:
Mage::getModel('catalog/resource_product_flat_indexer')->getAttributeCodes();