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?

up vote 6 down vote accepted
$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('*'); – philwinkle Feb 12 '13 at 15:49
  • 1
    no it is not. It get all the attributes which are marked as used_in_product_listing – Fabian Blechschmidt Feb 13 '13 at 0:27
  • Mark it as answer please. – Fabian Blechschmidt Mar 14 '13 at 21:15

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();
  • Which attributes were not included in your case? – Alex Jan 3 '17 at 13:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.